1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153 |
- /*
- * Copyright (c) 2010-2013, 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 <asm/ioctls.h>
- #include <mach/memory.h>
- #include <mach/debug_mm.h>
- #include <mach/qdsp6v2/audio_acdb.h>
- #include <mach/qdsp6v2/rtac.h>
- #include <sound/apr_audio.h>
- #include <sound/q6asm.h>
- #define TRUE 0x01
- #define FALSE 0x00
- #define READDONE_IDX_STATUS 0
- #define READDONE_IDX_BUFFER 1
- #define READDONE_IDX_SIZE 2
- #define READDONE_IDX_OFFSET 3
- #define READDONE_IDX_MSW_TS 4
- #define READDONE_IDX_LSW_TS 5
- #define READDONE_IDX_FLAGS 6
- #define READDONE_IDX_NUMFRAMES 7
- #define READDONE_IDX_ID 8
- #ifdef CONFIG_DEBUG_FS
- #define OUT_BUFFER_SIZE 56
- #define IN_BUFFER_SIZE 24
- #endif
- #define FRAME_NUM (8)
- static DEFINE_MUTEX(session_lock);
- /* session id: 0 reserved */
- static struct audio_client *session[SESSION_MAX+1];
- static int32_t q6asm_mmapcallback(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_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);
- static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
- uint32_t bufsz, uint32_t bufcnt);
- static void q6asm_reset_buf_state(struct audio_client *ac);
- #ifdef CONFIG_DEBUG_FS
- 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;
- 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)
- {
- 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 (!strict_strtol(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)
- {
- 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 (!strict_strtol(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
- };
- #endif
- struct asm_mmap {
- atomic_t ref_cnt;
- atomic_t cmd_state;
- wait_queue_head_t cmd_wait;
- void *apr;
- };
- static struct asm_mmap this_mmap;
- static int q6asm_session_alloc(struct audio_client *ac)
- {
- int n;
- mutex_lock(&session_lock);
- for (n = 1; n <= SESSION_MAX; n++) {
- if (!session[n]) {
- session[n] = ac;
- mutex_unlock(&session_lock);
- return n;
- }
- }
- mutex_unlock(&session_lock);
- return -ENOMEM;
- }
- 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);
- mutex_lock(&session_lock);
- session[ac->session] = 0;
- mutex_unlock(&session_lock);
- ac->session = 0;
- ac->perf_mode = false;
- return;
- }
- 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,
- port->buf[0].size,
- port->max_buf_cnt);
- if (rc < 0)
- pr_err("%s CMD Memory_unmap_regions failed\n",
- __func__);
- }
- while (cnt >= 0) {
- if (port->buf[cnt].data) {
- #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
- ion_unmap_kernel(port->buf[cnt].client,
- port->buf[cnt].handle);
- ion_free(port->buf[cnt].client,
- port->buf[cnt].handle);
- ion_client_destroy(port->buf[cnt].client);
- #else
- pr_debug("%s:data[%p]phys[%p][%p] cnt[%d] mem_buffer[%p]\n",
- __func__, (void *)port->buf[cnt].data,
- (void *)port->buf[cnt].phys,
- (void *)&port->buf[cnt].phys, cnt,
- (void *)port->buf[cnt].mem_buffer);
- if (IS_ERR((void *)port->buf[cnt].mem_buffer))
- pr_err("%s:mem buffer invalid, error = %ld\n",
- __func__,
- PTR_ERR((void *)port->buf[cnt].mem_buffer));
- else {
- if (iounmap(
- port->buf[cnt].mem_buffer) < 0)
- pr_err("%s: unmap buffer failed\n",
- __func__);
- }
- free_contiguous_memory_by_paddr(
- port->buf[cnt].phys);
- #endif
- 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) {
- #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
- ion_unmap_kernel(port->buf[0].client, port->buf[0].handle);
- ion_free(port->buf[0].client, port->buf[0].handle);
- ion_client_destroy(port->buf[0].client);
- 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);
- #else
- pr_debug("%s:data[%p]phys[%p][%p] mem_buffer[%p]\n",
- __func__,
- (void *)port->buf[0].data,
- (void *)port->buf[0].phys,
- (void *)&port->buf[0].phys,
- (void *)port->buf[0].mem_buffer);
- if (IS_ERR((void *)port->buf[0].mem_buffer))
- pr_err("%s:mem buffer invalid, error = %ld\n",
- __func__,
- PTR_ERR((void *)port->buf[0].mem_buffer));
- else {
- if (iounmap(
- port->buf[0].mem_buffer) < 0)
- pr_err("%s: unmap buffer failed\n", __func__);
- }
- free_contiguous_memory_by_paddr(port->buf[0].phys);
- #endif
- }
- 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;
- 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->apr);
- q6asm_session_free(ac);
- pr_debug("%s: APR De-Register\n", __func__);
- if (atomic_read(&this_mmap.ref_cnt) <= 0) {
- pr_err("%s: APR Common Port Already Closed\n", __func__);
- goto done;
- }
- atomic_dec(&this_mmap.ref_cnt);
- if (atomic_read(&this_mmap.ref_cnt) == 0) {
- apr_deregister(this_mmap.apr);
- pr_debug("%s:APR De-Register common port\n", __func__);
- }
- done:
- kfree(ac);
- return;
- }
- int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode)
- {
- if (ac == NULL) {
- pr_err("%s APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (mode == ASYNC_IO_MODE) {
- ac->io_mode &= ~SYNC_IO_MODE;
- ac->io_mode |= ASYNC_IO_MODE;
- } else if (mode == SYNC_IO_MODE) {
- ac->io_mode &= ~ASYNC_IO_MODE;
- ac->io_mode |= SYNC_IO_MODE;
- } else {
- pr_err("%s:Not an valid IO Mode:%d\n", __func__, ac->io_mode);
- return -EINVAL;
- }
- pr_debug("%s:Set Mode to %d\n", __func__, ac->io_mode);
- return 0;
- }
- 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;
- n = q6asm_session_alloc(ac);
- if (n <= 0)
- goto fail_session;
- ac->session = n;
- ac->cb = cb;
- ac->priv = priv;
- ac->io_mode = SYNC_IO_MODE;
- ac->perf_mode = false;
- 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__);
- goto fail;
- }
- rtac_set_asm_handle(n, ac->apr);
- pr_debug("%s Registering the common port with APR\n", __func__);
- if (atomic_read(&this_mmap.ref_cnt) == 0) {
- this_mmap.apr = apr_register("ADSP", "ASM", \
- (apr_fn)q6asm_mmapcallback,\
- 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);
- init_waitqueue_head(&ac->cmd_wait);
- init_waitqueue_head(&ac->time_wait);
- atomic_set(&ac->time_flag, 1);
- 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->cmd_response, 0);
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- return ac;
- fail:
- q6asm_audio_client_free(ac);
- return NULL;
- fail_session:
- kfree(ac);
- return NULL;
- }
- struct audio_client *q6asm_get_audio_client(int session_id)
- {
- 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;
- #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
- int len;
- unsigned int bufsz_4k_aligned;
- #endif
- 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);
- 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) {
- #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
- buf[cnt].client = msm_ion_client_create
- (UINT_MAX, "audio_client");
- if (IS_ERR_OR_NULL((void *)
- buf[cnt].client)) {
- pr_err("%s: ION create client for AUDIO failed\n",
- __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- bufsz_4k_aligned = (bufsz + 4095) &
- (~4095);
- pr_debug("%s: bufsz_4k_aligned %d"\
- "bufsz = %d\n",
- __func__, bufsz_4k_aligned,
- bufsz);
- buf[cnt].handle = ion_alloc
- (buf[cnt].client,
- bufsz_4k_aligned, SZ_4K,
- (0x1 << ION_AUDIO_HEAP_ID), 0);
- if (IS_ERR_OR_NULL((void *)
- buf[cnt].handle)) {
- pr_err("%s: ION memory allocation for AUDIO failed\n",
- __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- rc = ion_phys(buf[cnt].client,
- buf[cnt].handle,
- (ion_phys_addr_t *)
- &buf[cnt].phys,
- (size_t *)&len);
- 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].data = ion_map_kernel
- (buf[cnt].client, buf[cnt].handle);
- if (IS_ERR_OR_NULL((void *)
- buf[cnt].data)) {
- pr_err("%s: ION memory mapping for AUDIO failed\n",
- __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- memset((void *)buf[cnt].data, 0, bufsz);
- #else
- unsigned int flags = 0;
- buf[cnt].phys =
- allocate_contiguous_ebi_nomap(bufsz,
- SZ_4K);
- if (!buf[cnt].phys) {
- pr_err("%s:Buf alloc failed size=%d\n",
- __func__,
- bufsz);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[cnt].mem_buffer =
- ioremap(buf[cnt].phys, bufsz);
- if (IS_ERR(
- (void *)buf[cnt].mem_buffer)) {
- pr_err("%s:map_buffer failed, error = %ld\n",
- __func__,
- PTR_ERR((void *)buf[cnt].mem_buffer));
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[cnt].data =
- buf[cnt].mem_buffer;
- if (!buf[cnt].data) {
- pr_err("%s:invalid vaddr, iomap failed\n",
- __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- #endif
- 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);
- 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;
- #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
- int len;
- #else
- int flags = 0;
- #endif
- 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->port[dir].buf) {
- pr_debug("%s: buffer already allocated\n", __func__);
- return 0;
- }
- 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;
- #ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
- buf[0].client = msm_ion_client_create(UINT_MAX, "audio_client");
- if (IS_ERR_OR_NULL((void *)buf[0].client)) {
- pr_err("%s: ION create client for AUDIO failed\n", __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[0].handle = ion_alloc(buf[0].client, bufsz * bufcnt, SZ_4K,
- (0x1 << ION_AUDIO_HEAP_ID), 0);
- if (IS_ERR_OR_NULL((void *) buf[0].handle)) {
- pr_err("%s: ION memory allocation for AUDIO failed\n",
- __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- rc = ion_phys(buf[0].client, buf[0].handle,
- (ion_phys_addr_t *)&buf[0].phys, (size_t *)&len);
- if (rc) {
- pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
- __func__, rc);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[0].data = ion_map_kernel(buf[0].client, buf[0].handle);
- if (IS_ERR_OR_NULL((void *) buf[0].data)) {
- pr_err("%s: ION memory mapping for AUDIO failed\n", __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- memset((void *)buf[0].data, 0, (bufsz * bufcnt));
- #else
- buf[0].phys = allocate_contiguous_ebi_nomap(bufsz * bufcnt,
- SZ_4K);
- if (!buf[0].phys) {
- pr_err("%s:Buf alloc failed size=%d, bufcnt=%d\n",
- __func__, bufsz, bufcnt);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[0].mem_buffer = ioremap(buf[0].phys, bufsz * bufcnt);
- if (IS_ERR((void *)buf[cnt].mem_buffer)) {
- pr_err("%s:map_buffer failed, error = %ld\n",
- __func__, PTR_ERR((void *)buf[0].mem_buffer));
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[0].data = buf[0].mem_buffer;
- #endif
- if (!buf[0].data) {
- pr_err("%s:invalid vaddr, iomap failed\n", __func__);
- 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;
- pr_debug("%s ac->port[%d].max_buf_cnt[%d]\n", __func__, dir,
- ac->port[dir].max_buf_cnt);
- mutex_unlock(&ac->cmd_lock);
- rc = q6asm_memory_map(ac, buf[0].phys, dir, bufsz, cnt);
- 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_mmapcallback(struct apr_client_data *data, void *priv)
- {
- uint32_t token;
- uint32_t *payload = data->payload;
- struct audio_client *ac;
- 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);
- apr_reset(this_mmap.apr);
- this_mmap.apr = NULL;
- atomic_set(&this_mmap.cmd_state, 0);
- return 0;
- }
- pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]\n",
- __func__, payload[0], payload[1], data->opcode, data->token,
- data->payload_size, data->src_port, data->dest_port);
- if (data->opcode == APR_BASIC_RSP_RESULT) {
- token = data->token;
- ac = (struct audio_client *)data->token;
- pr_debug("%s: audio_client addr %x\n", __func__, (uint32_t)ac);
- switch (payload[0]) {
- case ASM_SESSION_CMD_MEMORY_MAP:
- case ASM_SESSION_CMD_MEMORY_UNMAP:
- case ASM_SESSION_CMD_MEMORY_MAP_REGIONS:
- case ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS:
- pr_debug("%s:command[0x%x]success [0x%x]\n",
- __func__, payload[0], payload[1]);
- if (atomic_read(&ac->cmd_state)) {
- atomic_set(&ac->cmd_state, 0);
- if (payload[1] != ADSP_EOK) {
- pr_err("payload[1]:%d error case\n",
- payload[1]);
- atomic_set(&ac->cmd_response, 1);
- } else
- atomic_set(&ac->cmd_response, 0);
- wake_up(&ac->cmd_wait);
- }
- break;
- default:
- pr_debug("%s:command[0x%x] not expecting rsp\n",
- __func__, payload[0]);
- break;
- }
- }
- 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:
- 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_CMDRSP_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;
- if ((ac == NULL) || (data == NULL)) {
- pr_err("ac or priv NULL\n");
- 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) {
- 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);
- 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 == APR_BASIC_RSP_RESULT) {
- token = data->token;
- pr_debug("%s payload[0]:%x", __func__, payload[0]);
- switch (payload[0]) {
- case ASM_STREAM_CMD_SET_PP_PARAMS:
- if (rtac_make_asm_callback(ac->session, payload,
- data->payload_size))
- break;
- case ASM_SESSION_CMD_PAUSE:
- case ASM_DATA_CMD_EOS:
- case ASM_STREAM_CMD_CLOSE:
- case ASM_STREAM_CMD_FLUSH:
- case ASM_SESSION_CMD_RUN:
- case ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS:
- case ASM_STREAM_CMD_FLUSH_READBUFS:
- pr_debug("%s:Payload = [0x%x]\n", __func__, payload[0]);
- if (token != ac->session) {
- pr_err("%s:Invalid session[%d] rxed expected[%d]",
- __func__, token, ac->session);
- return -EINVAL;
- }
- case ASM_STREAM_CMD_OPEN_READ:
- case ASM_STREAM_CMD_OPEN_READ_V2_1:
- case ASM_STREAM_CMD_OPEN_WRITE:
- case ASM_STREAM_CMD_OPEN_WRITE_V2_1:
- case ASM_STREAM_CMD_OPEN_READWRITE:
- case ASM_STREAM_CMD_OPEN_LOOPBACK:
- case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE:
- case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
- case ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED:
- case ASM_STREAM_CMD_OPEN_READ_COMPRESSED:
- case ASM_STREAM_CMD_OPEN_TRANSCODE_LOOPBACK:
- if (payload[0] == ASM_STREAM_CMD_CLOSE) {
- atomic_set(&ac->cmd_close_state, 0);
- wake_up(&ac->cmd_wait);
- } else if (atomic_read(&ac->cmd_state) &&
- wakeup_flag) {
- atomic_set(&ac->cmd_state, 0);
- pr_debug("response payload[1]:%d",
- payload[1]);
- if (payload[1] == ADSP_EUNSUPPORTED ||
- payload[1] == ADSP_EBADPARAM ||
- payload[1] == ADSP_EFAILED) {
- atomic_set(&ac->cmd_response, 1);
- }
- else
- atomic_set(&ac->cmd_response, 0);
- wake_up(&ac->cmd_wait);
- }
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- (uint32_t *)data->payload, ac->priv);
- 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:{
- 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);
- #ifdef CONFIG_DEBUG_FS
- 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);
- }
- #endif
- for (i = 0; i < port->max_buf_cnt; i++)
- pr_debug("%d ", port->buf[i].used);
- }
- break;
- }
- case ASM_STREAM_CMDRSP_GET_PP_PARAMS:
- rtac_make_asm_callback(ac->session, payload,
- data->payload_size);
- break;
- case ASM_DATA_EVENT_READ_DONE:{
- struct audio_port_data *port = &ac->port[OUT];
- #ifdef CONFIG_DEBUG_FS
- 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);
- }
- }
- #endif
- pr_debug("%s:R-D: status=%d buff_add=%x act_size=%d offset=%d\n",
- __func__, payload[READDONE_IDX_STATUS],
- payload[READDONE_IDX_BUFFER],
- payload[READDONE_IDX_SIZE],
- payload[READDONE_IDX_OFFSET]);
- pr_debug("%s:R-D:msw_ts=%d lsw_ts=%d flags=%d id=%d num=%d\n",
- __func__, payload[READDONE_IDX_MSW_TS],
- payload[READDONE_IDX_LSW_TS],
- payload[READDONE_IDX_FLAGS],
- payload[READDONE_IDX_ID],
- payload[READDONE_IDX_NUMFRAMES]);
- #ifdef CONFIG_DEBUG_FS
- if (in_enable_flag)
- in_cont_index++;
- #endif
- 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_BUFFER]) {
- pr_err("Buf expected[%p]rxed[%p]\n",\
- (void *)port->buf[token].phys,\
- (void *)payload[READDONE_IDX_BUFFER]);
- 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_CMDRSP_EOS:
- pr_debug("%s:EOS ACK received: rxed opcode[0x%x]\n",
- __func__, data->opcode);
- break;
- case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM:
- break;
- case ASM_SESSION_EVENT_TX_OVERFLOW:
- pr_err("ASM_SESSION_EVENT_TX_OVERFLOW\n");
- break;
- case ASM_SESSION_CMDRSP_GET_SESSION_TIME:
- pr_debug("%s: ASM_SESSION_CMDRSP_GET_SESSION_TIME, 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[1] << 32) |
- payload[2]);
- if (atomic_read(&ac->time_flag)) {
- atomic_set(&ac->time_flag, 0);
- wake_up(&ac->time_wait);
- }
- break;
- case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
- case ASM_DATA_EVENT_ENC_SR_CM_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;
- }
- int q6asm_open_transcode_loopback(struct audio_client *ac, uint32_t channels)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_transcode_loopback open;
- if ((ac == NULL) || (ac->apr == NULL)) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d] channels = %d", __func__, ac->session,
- channels);
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_TRANSCODE_LOOPBACK;
- open.mode_flags = 0;
- if (channels > 2)
- open.src_format_id = MULTI_CHANNEL_PCM;
- else
- open.src_format_id = LINEAR_PCM;
- open.sink_format_id = DTS;
- open.audproc_topo_id = DEFAULT_POPP_TOPOLOGY;
- open.src_endpoint_type = 0;
- open.sink_endpoint_type = 0;
- open.bits_per_sample = 16;
- 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_WRITE rc[%d]\n", __func__,
- rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_enc_cfg_blk_dts(struct audio_client *ac,
- uint32_t sample_rate,
- uint32_t channels)
- {
- struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
- int rc = 0;
- pr_debug("%s: sample_rate=%d,channels=%d\n", __func__,
- sample_rate, channels);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
- enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
- enc_cfg.enc_blk.frames_per_buf = 0;
- enc_cfg.enc_blk.format_id = DTS;
- enc_cfg.enc_blk.cfg_size = sizeof(struct asm_dts_enc_cfg);
- enc_cfg.enc_blk.cfg.dts.sample_rate = sample_rate;
- enc_cfg.enc_blk.cfg.dts.num_channels = channels;
- if (channels == 1) {
- enc_cfg.enc_blk.cfg.dts.channel_mapping[0] = PCM_CHANNEL_FC;
- } else if (channels == 2) {
- enc_cfg.enc_blk.cfg.dts.channel_mapping[0] = PCM_CHANNEL_FL;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[1] = PCM_CHANNEL_FR;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[2] = 0;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[3] = 0;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[4] = 0;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[5] = 0;
- } else if (channels == 4) {
- enc_cfg.enc_blk.cfg.dts.channel_mapping[0] = PCM_CHANNEL_FL;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[1] = PCM_CHANNEL_FR;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[2] = PCM_CHANNEL_LS;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[3] = PCM_CHANNEL_RS;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[4] = 0;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[5] = 0;
- } else if (channels == 6) {
- enc_cfg.enc_blk.cfg.dts.channel_mapping[0] = PCM_CHANNEL_FC;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[1] = PCM_CHANNEL_FL;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[2] = PCM_CHANNEL_FR;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[3] = PCM_CHANNEL_LS;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[4] = PCM_CHANNEL_RS;
- enc_cfg.enc_blk.cfg.dts.channel_mapping[5] = PCM_CHANNEL_LFE;
- }
- 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;
- }
- 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)
- {
- pr_debug("%s:session=%d pkt size=%d cmd_flg=%d\n", __func__, pkt_size,
- cmd_flg, ac->session);
- 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 = ((ac->session << 8) & 0xFF00) | 0x01;
- if (cmd_flg) {
- hdr->token = ac->session;
- atomic_set(&ac->cmd_state, 1);
- }
- hdr->pkt_size = pkt_size;
- mutex_unlock(&ac->cmd_lock);
- return;
- }
- static void q6asm_add_mmaphdr(struct apr_hdr *hdr, uint32_t pkt_size,
- uint32_t cmd_flg)
- {
- struct audio_client *ac;
- pr_debug("%s:pkt size=%d cmd_flg=%d\n", __func__, pkt_size, cmd_flg);
- ac = (struct audio_client *)hdr->token;
- pr_debug("%s: audio_client = %x\n", __func__, (uint32_t)ac);
- 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) {
- atomic_set(&ac->cmd_state, 1);
- }
- hdr->pkt_size = pkt_size;
- return;
- }
- int q6asm_open_read(struct audio_client *ac,
- uint32_t format)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_read open;
- #ifdef CONFIG_DEBUG_FS
- in_cont_index = 0;
- #endif
- 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);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ;
- /* Stream prio : High, provide meta info with encoded frames */
- open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
- open.pre_proc_top = get_asm_topology();
- if (open.pre_proc_top == 0)
- open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
- switch (format) {
- case FORMAT_LINEAR_PCM:
- open.uMode = STREAM_PRIORITY_HIGH;
- open.format = LINEAR_PCM;
- break;
- case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
- open.uMode = STREAM_PRIORITY_HIGH;
- open.format = MULTI_CHANNEL_PCM;
- break;
- case FORMAT_MPEG4_AAC:
- open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
- open.format = MPEG4_AAC;
- break;
- case FORMAT_V13K:
- open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
- open.format = V13K_FS;
- break;
- case FORMAT_EVRC:
- open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
- open.format = EVRC_FS;
- break;
- case FORMAT_AMRNB:
- open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
- open.format = AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
- open.format = 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_WRITE 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_v2_1(struct audio_client *ac,
- uint32_t format)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_read_v2_1 open;
- #ifdef CONFIG_DEBUG_FS
- in_cont_index = 0;
- #endif
- 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);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V2_1;
- open.src_endpoint = ASM_END_POINT_DEVICE_MATRIX;
- open.pre_proc_top = get_asm_topology();
- if (open.pre_proc_top == 0)
- open.pre_proc_top = DEFAULT_POPP_TOPOLOGY;
- switch (format) {
- case FORMAT_LINEAR_PCM:
- open.uMode = STREAM_PRIORITY_HIGH;
- open.format = LINEAR_PCM;
- break;
- case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
- open.uMode = STREAM_PRIORITY_HIGH;
- open.format = MULTI_CHANNEL_PCM;
- break;
- case FORMAT_MPEG4_AAC:
- open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
- open.format = MPEG4_AAC;
- break;
- case FORMAT_V13K:
- open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
- open.format = V13K_FS;
- break;
- case FORMAT_EVRC:
- open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
- open.format = EVRC_FS;
- break;
- case FORMAT_AMRNB:
- open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
- open.format = AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_HIGH;
- open.format = AMRWB_FS;
- break;
- default:
- pr_err("Invalid format[%d]\n", format);
- goto fail_cmd;
- }
- open.uMode = ASM_OPEN_READ_PERF_MODE_BIT;
- open.bits_per_sample = PCM_BITS_PER_SAMPLE;
- open.reserved = 0;
- 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_WRITE rc[%d]\n", __func__,
- rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_open_read_compressed(struct audio_client *ac,
- uint32_t frames_per_buffer, uint32_t meta_data_mode)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_read_compressed open;
- #ifdef CONFIG_DEBUG_FS
- in_cont_index = 0;
- #endif
- 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);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_COMPRESSED;
- /* hardcoded as following*/
- open.frame_per_buf = frames_per_buffer;
- open.uMode = meta_data_mode;
- 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_COMPRESSED rc[%d]\n",
- __func__, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_write_compressed open;
- if ((ac == NULL) || (ac->apr == NULL)) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
- format);
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED;
- switch (format) {
- case FORMAT_AC3:
- open.format = AC3_DECODER;
- break;
- case FORMAT_EAC3:
- open.format = EAC3_DECODER;
- break;
- case FORMAT_MP3:
- open.format = MP3;
- break;
- case FORMAT_DTS:
- open.format = DTS;
- break;
- case FORMAT_DTS_LBR:
- open.format = DTS_LBR;
- break;
- case FORMAT_AAC:
- open.format = MPEG4_AAC;
- break;
- case FORMAT_ATRAC:
- open.format = ATRAC;
- break;
- case FORMAT_WMA_V10PRO:
- open.format = WMA_V10PRO;
- break;
- case FORMAT_MAT:
- open.format = MAT;
- break;
- case FORMAT_MP2:
- open.format = MP2;
- break;
- default:
- pr_err("%s: Invalid format[%d]\n", __func__, format);
- goto fail_cmd;
- }
- /*Below flag indicates the DSP that Compressed audio input
- stream is not IEC 61937 or IEC 60958 packetizied*/
- open.flags = 0x00000000;
- 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;
- }
- if (atomic_read(&ac->cmd_response)) {
- pr_err("%s: format = %x not supported\n", __func__, format);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_open_write(struct audio_client *ac, uint32_t format)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_write open;
- if ((ac == NULL) || (ac->apr == NULL)) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d] wr_format[0x%x]", __func__, ac->session,
- format);
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- if (ac->perf_mode) {
- pr_debug("%s In Performance/lowlatency mode", __func__);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V2_1;
- open.uMode = ASM_OPEN_WRITE_PERF_MODE_BIT;
- /* source endpoint : matrix */
- open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
- open.stream_handle = PCM_BITS_PER_SAMPLE;
- } else {
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE;
- open.uMode = STREAM_PRIORITY_HIGH;
- /* source endpoint : matrix */
- open.sink_endpoint = ASM_END_POINT_DEVICE_MATRIX;
- open.stream_handle = 0x00;
- }
- open.post_proc_top = get_asm_topology();
- if (open.post_proc_top == 0)
- open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
- switch (format) {
- case FORMAT_LINEAR_PCM:
- open.format = LINEAR_PCM;
- break;
- case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
- open.format = MULTI_CHANNEL_PCM;
- break;
- case FORMAT_MPEG4_AAC:
- open.format = MPEG4_AAC;
- break;
- case FORMAT_MPEG4_MULTI_AAC:
- open.format = MPEG4_MULTI_AAC;
- break;
- case FORMAT_WMA_V9:
- open.format = WMA_V9;
- break;
- case FORMAT_WMA_V10PRO:
- open.format = WMA_V10PRO;
- break;
- case FORMAT_MP3:
- open.format = MP3;
- break;
- case FORMAT_DTS:
- open.format = DTS;
- break;
- case FORMAT_DTS_LBR:
- open.format = DTS_LBR;
- break;
- case FORMAT_AMRWB:
- open.format = AMRWB_FS;
- pr_debug("q6asm_open_write FORMAT_AMRWB");
- break;
- case FORMAT_AMR_WB_PLUS:
- open.format = AMR_WB_PLUS;
- pr_debug("q6asm_open_write FORMAT_AMR_WB_PLUS");
- break;
- case FORMAT_MP2:
- open.format = MP2;
- 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;
- }
- if (atomic_read(&ac->cmd_response)) {
- pr_err("%s: format = %x not supported\n", __func__, format);
- goto fail_cmd;
- }
- ac->io_mode |= TUN_WRITE_IO_MODE;
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- 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_read_write open;
- if ((ac == NULL) || (ac->apr == NULL)) {
- pr_err("APR handle NULL\n");
- return -EINVAL;
- }
- pr_debug("%s: session[%d]", __func__, ac->session);
- pr_debug("wr_format[0x%x]rd_format[0x%x]",
- wr_format, rd_format);
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE;
- open.uMode = BUFFER_META_ENABLE | STREAM_PRIORITY_NORMAL;
- /* source endpoint : matrix */
- open.post_proc_top = get_asm_topology();
- if (open.post_proc_top == 0)
- open.post_proc_top = DEFAULT_POPP_TOPOLOGY;
- switch (wr_format) {
- case FORMAT_LINEAR_PCM:
- open.write_format = LINEAR_PCM;
- break;
- case FORMAT_MPEG4_AAC:
- open.write_format = MPEG4_AAC;
- break;
- case FORMAT_MPEG4_MULTI_AAC:
- open.write_format = MPEG4_MULTI_AAC;
- break;
- case FORMAT_WMA_V9:
- open.write_format = WMA_V9;
- break;
- case FORMAT_WMA_V10PRO:
- open.write_format = WMA_V10PRO;
- break;
- case FORMAT_AMRNB:
- open.write_format = AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.write_format = AMRWB_FS;
- break;
- case FORMAT_AMR_WB_PLUS:
- open.write_format = AMR_WB_PLUS;
- break;
- case FORMAT_V13K:
- open.write_format = V13K_FS;
- break;
- case FORMAT_EVRC:
- open.write_format = EVRC_FS;
- break;
- case FORMAT_EVRCB:
- open.write_format = EVRCB_FS;
- break;
- case FORMAT_EVRCWB:
- open.write_format = EVRCWB_FS;
- break;
- case FORMAT_MP3:
- open.write_format = MP3;
- break;
- case FORMAT_MP2:
- open.write_format = MP2;
- break;
- default:
- pr_err("Invalid format[%d]\n", wr_format);
- goto fail_cmd;
- }
- switch (rd_format) {
- case FORMAT_LINEAR_PCM:
- open.read_format = LINEAR_PCM;
- break;
- case FORMAT_MPEG4_AAC:
- open.read_format = MPEG4_AAC;
- break;
- case FORMAT_V13K:
- open.read_format = V13K_FS;
- break;
- case FORMAT_EVRC:
- open.read_format = EVRC_FS;
- break;
- case FORMAT_AMRNB:
- open.read_format = AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.read_format = 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.read_format, open.write_format);
- 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_WRITE rc[%d]\n", rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_open_loopack(struct audio_client *ac)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_loopback open;
- if ((ac == NULL) || (ac->apr == NULL)) {
- pr_err("APR handle NULL\n");
- return -EINVAL;
- }
- pr_debug("%s: session[%d]", __func__, ac->session);
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_LOOPBACK;
- 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;
- 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_WRITE rc[%d]\n", 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_stream_cmd_run run;
- int rc;
- if (!ac || ac->apr == NULL) {
- pr_err("APR handle NULL\n");
- return -EINVAL;
- }
- pr_debug("%s session[%d]", __func__, ac->session);
- q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
- run.hdr.opcode = ASM_SESSION_CMD_RUN;
- run.flags = flags;
- run.msw_ts = msw_ts;
- run.lsw_ts = lsw_ts;
- #ifdef CONFIG_DEBUG_FS
- 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);
- }
- #endif
- 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;
- }
- int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
- uint32_t msw_ts, uint32_t lsw_ts)
- {
- struct asm_stream_cmd_run 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_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE);
- run.hdr.opcode = ASM_SESSION_CMD_RUN;
- run.flags = flags;
- run.msw_ts = msw_ts;
- run.lsw_ts = lsw_ts;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
- if (rc < 0) {
- pr_err("%s:Commmand run failed[%d]", __func__, rc);
- return -EINVAL;
- }
- atomic_inc(&ac->nowait_cmd_cnt);
- return 0;
- }
- 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_stream_cmd_encdec_cfg_blk 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);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
- enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
- enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
- enc_cfg.enc_blk.format_id = MPEG4_AAC;
- enc_cfg.enc_blk.cfg_size = sizeof(struct asm_aac_read_cfg);
- enc_cfg.enc_blk.cfg.aac.bitrate = bit_rate;
- enc_cfg.enc_blk.cfg.aac.enc_mode = mode;
- enc_cfg.enc_blk.cfg.aac.format = format;
- enc_cfg.enc_blk.cfg.aac.ch_cfg = channels;
- enc_cfg.enc_blk.cfg.aac.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_enc_cfg_blk_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
- int rc = 0;
- 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);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
- enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
- enc_cfg.enc_blk.frames_per_buf = 1;
- enc_cfg.enc_blk.format_id = LINEAR_PCM;
- enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
- enc_cfg.enc_blk.cfg.pcm.ch_cfg = channels;
- enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
- enc_cfg.enc_blk.cfg.pcm.sample_rate = rate;
- enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
- enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
- 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_native(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
- int rc = 0;
- pr_debug("%s: Session %d, rate = %d, channels = %d, setting the rate and channels to 0 for native\n",
- __func__, ac->session, rate, channels);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
- enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
- enc_cfg.enc_blk.frames_per_buf = 1;
- enc_cfg.enc_blk.format_id = LINEAR_PCM;
- enc_cfg.enc_blk.cfg_size = sizeof(struct asm_pcm_cfg);
- enc_cfg.enc_blk.cfg.pcm.ch_cfg = 0;/*channels;*/
- enc_cfg.enc_blk.cfg.pcm.bits_per_sample = 16;
- enc_cfg.enc_blk.cfg.pcm.sample_rate = 0;/*rate;*/
- enc_cfg.enc_blk.cfg.pcm.is_signed = 1;
- enc_cfg.enc_blk.cfg.pcm.interleaved = 1;
- 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_multi_ch_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- struct asm_stream_cmd_encdec_cfg_blk enc_cfg;
- int rc = 0;
- 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);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
- enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
- enc_cfg.enc_blk.frames_per_buf = 1;
- enc_cfg.enc_blk.format_id = MULTI_CHANNEL_PCM;
- enc_cfg.enc_blk.cfg_size =
- sizeof(struct asm_multi_channel_pcm_fmt_blk);
- enc_cfg.enc_blk.cfg.mpcm.num_channels = channels;
- enc_cfg.enc_blk.cfg.mpcm.bits_per_sample = 16;
- enc_cfg.enc_blk.cfg.mpcm.sample_rate = rate;
- enc_cfg.enc_blk.cfg.mpcm.is_signed = 1;
- enc_cfg.enc_blk.cfg.mpcm.is_interleaved = 1;
- if (channels == 1) {
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
- } else if (channels == 2) {
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
- } else if (channels == 4) {
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_RB;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_LB;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
- } else if (channels == 6) {
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = 0;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = 0;
- } else if (channels == 8) {
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[0] = PCM_CHANNEL_FL;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[1] = PCM_CHANNEL_FR;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[2] = PCM_CHANNEL_LFE;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[3] = PCM_CHANNEL_FC;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[4] = PCM_CHANNEL_LB;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[5] = PCM_CHANNEL_RB;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[6] = PCM_CHANNEL_FLC;
- enc_cfg.enc_blk.cfg.mpcm.channel_mapping[7] = PCM_CHANNEL_FRC;
- }
- 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_enable_sbrps(struct audio_client *ac,
- uint32_t sbr_ps_enable)
- {
- struct asm_stream_cmd_encdec_sbr sbrps;
- int rc = 0;
- pr_debug("%s: Session %d\n", __func__, ac->session);
- q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
- sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- sbrps.param_id = ASM_ENABLE_SBR_PS;
- sbrps.param_size = sizeof(struct asm_sbr_ps);
- sbrps.sbr_ps.enable = 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_ENABLE_SBR_PS);
- 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_stream_cmd_encdec_dualmono 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);
- dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- dual_mono.param_id = ASM_CONFIGURE_DUAL_MONO;
- dual_mono.param_size = sizeof(struct asm_dual_mono);
- dual_mono.channel_map.sce_left = sce_left;
- dual_mono.channel_map.sce_right = 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_CONFIGURE_DUAL_MONO);
- 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;
- }
- int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff)
- {
- struct asm_aac_stereo_mix_coeff_selection_param aac_mix_coeff;
- int rc = 0;
- q6asm_add_hdr(ac, &aac_mix_coeff.hdr, sizeof(aac_mix_coeff), TRUE);
- 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;
- aac_mix_coeff.param_size =
- sizeof(struct asm_aac_stereo_mix_coeff_selection_param);
- 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);
- 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__,
- aac_mix_coeff.hdr.opcode);
- 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_stream_cmd_encdec_channelmap chan_map;
- u8 *channel_mapping;
- int rc = 0;
- pr_debug("%s: Session %d, num_channels = %d\n",
- __func__, ac->session, num_channels);
- q6asm_add_hdr(ac, &chan_map.hdr, sizeof(chan_map), TRUE);
- chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- chan_map.param_id = ASM_ENCDEC_DEC_CHAN_MAP;
- chan_map.param_size = sizeof(struct asm_dec_chan_map);
- chan_map.chan_map.num_channels = num_channels;
- channel_mapping =
- chan_map.chan_map.channel_mapping;
- memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
- if (num_channels == 1) {
- channel_mapping[0] = PCM_CHANNEL_FL;
- } else if (num_channels == 2) {
- channel_mapping[0] = PCM_CHANNEL_FL;
- channel_mapping[1] = PCM_CHANNEL_FR;
- } else if (num_channels == 4) {
- channel_mapping[0] = PCM_CHANNEL_FL;
- channel_mapping[1] = PCM_CHANNEL_FR;
- channel_mapping[1] = PCM_CHANNEL_LB;
- channel_mapping[1] = PCM_CHANNEL_RB;
- } else if (num_channels == 6) {
- channel_mapping[0] = PCM_CHANNEL_FC;
- channel_mapping[1] = PCM_CHANNEL_FL;
- channel_mapping[2] = PCM_CHANNEL_FR;
- channel_mapping[3] = PCM_CHANNEL_LB;
- channel_mapping[4] = PCM_CHANNEL_RB;
- channel_mapping[5] = PCM_CHANNEL_LFE;
- } else if (num_channels == 8) {
- channel_mapping[0] = PCM_CHANNEL_FC;
- channel_mapping[1] = PCM_CHANNEL_FL;
- channel_mapping[2] = PCM_CHANNEL_FR;
- channel_mapping[3] = PCM_CHANNEL_LB;
- channel_mapping[4] = PCM_CHANNEL_RB;
- channel_mapping[5] = PCM_CHANNEL_LFE;
- channel_mapping[6] = PCM_CHANNEL_FLC;
- channel_mapping[7] = PCM_CHANNEL_FRC;
- } else {
- pr_err("%s: ERROR.unsupported num_ch = %u\n", __func__,
- num_channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- 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_ENCDEC_DEC_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;
- }
- 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_stream_cmd_encdec_cfg_blk 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);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
- enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
- enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
- enc_cfg.enc_blk.format_id = V13K_FS;
- enc_cfg.enc_blk.cfg_size = sizeof(struct asm_qcelp13_read_cfg);
- enc_cfg.enc_blk.cfg.qcelp13.min_rate = min_rate;
- enc_cfg.enc_blk.cfg.qcelp13.max_rate = max_rate;
- enc_cfg.enc_blk.cfg.qcelp13.reduced_rate_level = reduced_rate_level;
- enc_cfg.enc_blk.cfg.qcelp13.rate_modulation_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 FORMAT_UPDATE\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_stream_cmd_encdec_cfg_blk 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);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
- enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
- enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
- enc_cfg.enc_blk.format_id = EVRC_FS;
- enc_cfg.enc_blk.cfg_size = sizeof(struct asm_evrc_read_cfg);
- enc_cfg.enc_blk.cfg.evrc.min_rate = min_rate;
- enc_cfg.enc_blk.cfg.evrc.max_rate = max_rate;
- enc_cfg.enc_blk.cfg.evrc.rate_modulation_cmd = rate_modulation_cmd;
- enc_cfg.enc_blk.cfg.evrc.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 FORMAT_UPDATE\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_stream_cmd_encdec_cfg_blk 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);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
- enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
- enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
- enc_cfg.enc_blk.format_id = AMRNB_FS;
- enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrnb_read_cfg);
- enc_cfg.enc_blk.cfg.amrnb.mode = band_mode;
- enc_cfg.enc_blk.cfg.amrnb.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;
- }
- 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_stream_cmd_encdec_cfg_blk 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);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.param_id = ASM_ENCDEC_CFG_BLK_ID;
- enc_cfg.param_size = sizeof(struct asm_encode_cfg_blk);
- enc_cfg.enc_blk.frames_per_buf = frames_per_buf;
- enc_cfg.enc_blk.format_id = AMRWB_FS;
- enc_cfg.enc_blk.cfg_size = sizeof(struct asm_amrwb_read_cfg);
- enc_cfg.enc_blk.cfg.amrwb.mode = band_mode;
- enc_cfg.enc_blk.cfg.amrwb.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;
- }
- int q6asm_media_format_block_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- struct asm_stream_media_format_update fmt;
- int rc = 0;
- pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
- channels);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
- fmt.format = LINEAR_PCM;
- fmt.cfg_size = sizeof(struct asm_pcm_cfg);
- fmt.write_cfg.pcm_cfg.ch_cfg = channels;
- fmt.write_cfg.pcm_cfg.bits_per_sample = 16;
- fmt.write_cfg.pcm_cfg.sample_rate = rate;
- fmt.write_cfg.pcm_cfg.is_signed = 1;
- fmt.write_cfg.pcm_cfg.interleaved = 1;
- 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, char *channel_map)
- {
- struct asm_stream_media_format_update fmt;
- u8 *channel_mapping;
- int rc = 0;
- pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
- channels);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
- fmt.format = MULTI_CHANNEL_PCM;
- fmt.cfg_size = sizeof(struct asm_multi_channel_pcm_fmt_blk);
- fmt.write_cfg.multi_ch_pcm_cfg.num_channels = channels;
- fmt.write_cfg.multi_ch_pcm_cfg.bits_per_sample = 16;
- fmt.write_cfg.multi_ch_pcm_cfg.sample_rate = rate;
- fmt.write_cfg.multi_ch_pcm_cfg.is_signed = 1;
- fmt.write_cfg.multi_ch_pcm_cfg.is_interleaved = 1;
- channel_mapping =
- fmt.write_cfg.multi_ch_pcm_cfg.channel_mapping;
- 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_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg)
- {
- struct asm_stream_media_format_update fmt;
- int rc = 0;
- pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
- cfg->sample_rate, cfg->ch_cfg);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
- fmt.format = MPEG4_AAC;
- fmt.cfg_size = sizeof(struct asm_aac_cfg);
- fmt.write_cfg.aac_cfg.format = cfg->format;
- fmt.write_cfg.aac_cfg.aot = cfg->aot;
- fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
- fmt.write_cfg.aac_cfg.section_data_resilience =
- cfg->section_data_resilience;
- fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
- cfg->scalefactor_data_resilience;
- fmt.write_cfg.aac_cfg.spectral_data_resilience =
- cfg->spectral_data_resilience;
- fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
- fmt.write_cfg.aac_cfg.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.format, fmt.cfg_size,
- fmt.write_cfg.aac_cfg.format,
- fmt.write_cfg.aac_cfg.aot,
- fmt.write_cfg.aac_cfg.ch_cfg,
- fmt.write_cfg.aac_cfg.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_amrwbplus(struct audio_client *ac,
- struct asm_amrwbplus_cfg *cfg)
- {
- struct asm_stream_media_format_update fmt;
- int rc = 0;
- pr_debug("q6asm_media_format_block_amrwbplus");
- 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);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
- fmt.format = AMR_WB_PLUS;
- fmt.cfg_size = cfg->size_bytes;
- fmt.write_cfg.amrwbplus_cfg.size_bytes = cfg->size_bytes;
- fmt.write_cfg.amrwbplus_cfg.version = cfg->version;
- fmt.write_cfg.amrwbplus_cfg.num_channels = cfg->num_channels;
- fmt.write_cfg.amrwbplus_cfg.amr_band_mode = cfg->amr_band_mode;
- fmt.write_cfg.amrwbplus_cfg.amr_dtx_mode = cfg->amr_dtx_mode;
- fmt.write_cfg.amrwbplus_cfg.amr_frame_fmt = cfg->amr_frame_fmt;
- fmt.write_cfg.amrwbplus_cfg.amr_lsf_idx = cfg->amr_lsf_idx;
- pr_debug("%s: num_channels=%x amr_band_mode=%d amr_frame_fmt=%d\n",
- __func__,
- cfg->num_channels,
- cfg->amr_band_mode,
- 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_media_format_block_multi_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg)
- {
- struct asm_stream_media_format_update fmt;
- int rc = 0;
- pr_debug("%s:session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
- cfg->sample_rate, cfg->ch_cfg);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
- fmt.format = MPEG4_MULTI_AAC;
- fmt.cfg_size = sizeof(struct asm_aac_cfg);
- fmt.write_cfg.aac_cfg.format = cfg->format;
- fmt.write_cfg.aac_cfg.aot = cfg->aot;
- fmt.write_cfg.aac_cfg.ep_config = cfg->ep_config;
- fmt.write_cfg.aac_cfg.section_data_resilience =
- cfg->section_data_resilience;
- fmt.write_cfg.aac_cfg.scalefactor_data_resilience =
- cfg->scalefactor_data_resilience;
- fmt.write_cfg.aac_cfg.spectral_data_resilience =
- cfg->spectral_data_resilience;
- fmt.write_cfg.aac_cfg.ch_cfg = cfg->ch_cfg;
- fmt.write_cfg.aac_cfg.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.format, fmt.cfg_size,
- fmt.write_cfg.aac_cfg.format,
- fmt.write_cfg.aac_cfg.aot,
- fmt.write_cfg.aac_cfg.ch_cfg,
- fmt.write_cfg.aac_cfg.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(struct audio_client *ac, uint32_t format)
- {
- struct asm_stream_media_format_update fmt;
- int rc = 0;
- pr_debug("%s:session[%d] format[0x%x]\n", __func__,
- ac->session, format);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
- switch (format) {
- case FORMAT_V13K:
- fmt.format = V13K_FS;
- break;
- case FORMAT_EVRC:
- fmt.format = EVRC_FS;
- break;
- case FORMAT_AMRWB:
- fmt.format = AMRWB_FS;
- break;
- case FORMAT_AMR_WB_PLUS:
- fmt.format = AMR_WB_PLUS;
- break;
- case FORMAT_AMRNB:
- fmt.format = AMRNB_FS;
- break;
- case FORMAT_MP3:
- fmt.format = MP3;
- break;
- case FORMAT_DTS:
- fmt.format = DTS;
- break;
- case FORMAT_DTS_LBR:
- fmt.format = DTS_LBR;
- break;
- case FORMAT_MP2:
- fmt.format = MP2;
- break;
- default:
- pr_err("Invalid format[%d]\n", format);
- goto fail_cmd;
- }
- fmt.cfg_size = 0;
- 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_wma(struct audio_client *ac,
- void *cfg)
- {
- struct asm_stream_media_format_update 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);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
- fmt.format = WMA_V9;
- fmt.cfg_size = sizeof(struct asm_wma_cfg);
- fmt.write_cfg.wma_cfg.format_tag = wma_cfg->format_tag;
- fmt.write_cfg.wma_cfg.ch_cfg = wma_cfg->ch_cfg;
- fmt.write_cfg.wma_cfg.sample_rate = wma_cfg->sample_rate;
- fmt.write_cfg.wma_cfg.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
- fmt.write_cfg.wma_cfg.block_align = wma_cfg->block_align;
- fmt.write_cfg.wma_cfg.valid_bits_per_sample =
- wma_cfg->valid_bits_per_sample;
- fmt.write_cfg.wma_cfg.ch_mask = wma_cfg->ch_mask;
- fmt.write_cfg.wma_cfg.encode_opt = wma_cfg->encode_opt;
- fmt.write_cfg.wma_cfg.adv_encode_opt = 0;
- fmt.write_cfg.wma_cfg.adv_encode_opt2 = 0;
- fmt.write_cfg.wma_cfg.drc_peak_ref = 0;
- fmt.write_cfg.wma_cfg.drc_peak_target = 0;
- fmt.write_cfg.wma_cfg.drc_ave_ref = 0;
- fmt.write_cfg.wma_cfg.drc_ave_target = 0;
- 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_stream_media_format_update 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);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FORMAT_UPDATE;
- fmt.format = WMA_V10PRO;
- fmt.cfg_size = sizeof(struct asm_wmapro_cfg);
- fmt.write_cfg.wmapro_cfg.format_tag = wmapro_cfg->format_tag;
- fmt.write_cfg.wmapro_cfg.ch_cfg = wmapro_cfg->ch_cfg;
- fmt.write_cfg.wmapro_cfg.sample_rate = wmapro_cfg->sample_rate;
- fmt.write_cfg.wmapro_cfg.avg_bytes_per_sec =
- wmapro_cfg->avg_bytes_per_sec;
- fmt.write_cfg.wmapro_cfg.block_align = wmapro_cfg->block_align;
- fmt.write_cfg.wmapro_cfg.valid_bits_per_sample =
- wmapro_cfg->valid_bits_per_sample;
- fmt.write_cfg.wmapro_cfg.ch_mask = wmapro_cfg->ch_mask;
- fmt.write_cfg.wmapro_cfg.encode_opt = wmapro_cfg->encode_opt;
- fmt.write_cfg.wmapro_cfg.adv_encode_opt = wmapro_cfg->adv_encode_opt;
- fmt.write_cfg.wmapro_cfg.adv_encode_opt2 = wmapro_cfg->adv_encode_opt2;
- fmt.write_cfg.wmapro_cfg.drc_peak_ref = 0;
- fmt.write_cfg.wmapro_cfg.drc_peak_target = 0;
- fmt.write_cfg.wmapro_cfg.drc_ave_ref = 0;
- fmt.write_cfg.wmapro_cfg.drc_ave_target = 0;
- 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_memory_map(struct audio_client *ac, uint32_t buf_add, int dir,
- uint32_t bufsz, uint32_t bufcnt)
- {
- struct asm_stream_cmd_memory_map mem_map;
- int rc = 0;
- if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
- pr_err("APR handle NULL\n");
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- mem_map.hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP;
- mem_map.buf_add = buf_add;
- mem_map.buf_size = bufsz * bufcnt;
- mem_map.mempool_id = 0; /* EBI */
- mem_map.reserved = 0;
- pr_debug("%s: audio_client addr %x\n", __func__, (uint32_t)ac);
- mem_map.hdr.token = (uint32_t)ac;
- q6asm_add_mmaphdr(&mem_map.hdr,
- sizeof(struct asm_stream_cmd_memory_map), TRUE);
- pr_debug("buf add[%x] buf_add_parameter[%x]\n",
- mem_map.buf_add, buf_add);
- rc = apr_send_pkt(this_mmap.apr, (uint32_t *) &mem_map);
- if (rc < 0) {
- pr_err("mem_map op[0x%x]rc[%d]\n",
- mem_map.hdr.opcode, rc);
- 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 memory_map\n");
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_response)) {
- pr_err("%s: ASM_SESSION_CMD_MEMORY_MAP cmd failed\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- int q6asm_memory_unmap(struct audio_client *ac, uint32_t buf_add, int dir)
- {
- struct asm_stream_cmd_memory_unmap mem_unmap;
- int rc = 0;
- if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
- pr_err("APR handle NULL\n");
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- pr_debug("%s: audio_client addr %x\n", __func__, (uint32_t)ac);
- mem_unmap.hdr.token = (uint32_t)ac;
- q6asm_add_mmaphdr(&mem_unmap.hdr,
- sizeof(struct asm_stream_cmd_memory_unmap), TRUE);
- mem_unmap.hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP;
- mem_unmap.buf_add = buf_add;
- rc = apr_send_pkt(this_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->cmd_wait,
- (atomic_read(&ac->cmd_state) == 0), 5*HZ);
- if (!rc) {
- pr_err("timeout. waited for memory_unmap\n");
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_response)) {
- pr_err("%s: ASM_SESSION_CMD_MEMORY_UNMAP cmd failed\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
- {
- void *vol_cmd = NULL;
- void *payload = NULL;
- struct asm_pp_params_command *cmd = NULL;
- struct asm_lrchannel_gain_params *lrgain = NULL;
- int sz = 0;
- int rc = 0;
- sz = sizeof(struct asm_pp_params_command) +
- + sizeof(struct asm_lrchannel_gain_params);
- vol_cmd = kzalloc(sz, GFP_KERNEL);
- if (vol_cmd == NULL) {
- pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
- rc = -EINVAL;
- return rc;
- }
- cmd = (struct asm_pp_params_command *)vol_cmd;
- q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
- cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
- cmd->payload = NULL;
- cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
- sizeof(struct asm_lrchannel_gain_params);
- cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
- cmd->params.param_id = L_R_CHANNEL_GAIN_PARAM_ID;
- cmd->params.param_size = sizeof(struct asm_lrchannel_gain_params);
- cmd->params.reserved = 0;
- payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
- lrgain = (struct asm_lrchannel_gain_params *)payload;
- lrgain->left_gain = left_gain;
- lrgain->right_gain = right_gain;
- rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
- if (rc < 0) {
- pr_err("%s: Volume Command failed\n", __func__);
- 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 in sending volume command to apr\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- kfree(vol_cmd);
- return rc;
- }
- static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
- uint32_t bufsz, uint32_t bufcnt)
- {
- struct asm_stream_cmd_memory_map_regions *mmap_regions = NULL;
- struct asm_memory_map_regions *mregions = NULL;
- struct audio_port_data *port = NULL;
- struct audio_buffer *ab = NULL;
- void *mmap_region_cmd = NULL;
- void *payload = NULL;
- int rc = 0;
- int i = 0;
- int cmd_size = 0;
- if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
- pr_err("APR handle NULL\n");
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- cmd_size = sizeof(struct asm_stream_cmd_memory_map_regions)
- + sizeof(struct asm_memory_map_regions) * bufcnt;
- mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
- if (mmap_region_cmd == NULL) {
- pr_err("%s: Mem alloc failed\n", __func__);
- rc = -EINVAL;
- return rc;
- }
- mmap_regions = (struct asm_stream_cmd_memory_map_regions *)
- mmap_region_cmd;
- mmap_regions->hdr.token = (uint32_t)ac;
- pr_debug("%s: audio_client addr %x\n", __func__, (uint32_t)ac);
- q6asm_add_mmaphdr(&mmap_regions->hdr, cmd_size, TRUE);
- mmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_MAP_REGIONS;
- mmap_regions->mempool_id = 0;
- mmap_regions->nregions = bufcnt & 0x00ff;
- pr_debug("map_regions->nregions = %d\n", mmap_regions->nregions);
- payload = ((u8 *) mmap_region_cmd +
- sizeof(struct asm_stream_cmd_memory_map_regions));
- mregions = (struct asm_memory_map_regions *)payload;
- port = &ac->port[dir];
- for (i = 0; i < bufcnt; i++) {
- ab = &port->buf[i];
- mregions->phys = ab->phys;
- mregions->buf_size = ab->size;
- ++mregions;
- }
- rc = apr_send_pkt(this_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;
- 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 map_regions\n");
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_response)) {
- pr_err("%s: ASM_SESSION_CMD_MEMORY_MAP_REGIONS cmd failed\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- kfree(mmap_region_cmd);
- return rc;
- }
- static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir,
- uint32_t bufsz, uint32_t bufcnt)
- {
- struct asm_stream_cmd_memory_unmap_regions *unmap_regions = NULL;
- struct asm_memory_unmap_regions *mregions = NULL;
- struct audio_port_data *port = NULL;
- struct audio_buffer *ab = NULL;
- void *unmap_region_cmd = NULL;
- void *payload = NULL;
- int rc = 0;
- int i = 0;
- int cmd_size = 0;
- if (!ac || ac->apr == NULL || this_mmap.apr == NULL) {
- pr_err("APR handle NULL\n");
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- cmd_size = sizeof(struct asm_stream_cmd_memory_unmap_regions) +
- sizeof(struct asm_memory_unmap_regions) * bufcnt;
- unmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
- if (unmap_region_cmd == NULL) {
- pr_err("%s: Mem alloc failed\n", __func__);
- rc = -EINVAL;
- return rc;
- }
- unmap_regions = (struct asm_stream_cmd_memory_unmap_regions *)
- unmap_region_cmd;
- unmap_regions->hdr.token = (uint32_t)ac;
- pr_debug("%s: audio_client addr %x\n", __func__, (uint32_t)ac);
- q6asm_add_mmaphdr(&unmap_regions->hdr, cmd_size, TRUE);
- unmap_regions->hdr.opcode = ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS;
- unmap_regions->nregions = bufcnt & 0x00ff;
- pr_debug("unmap_regions->nregions = %d\n", unmap_regions->nregions);
- payload = ((u8 *) unmap_region_cmd +
- sizeof(struct asm_stream_cmd_memory_unmap_regions));
- mregions = (struct asm_memory_unmap_regions *)payload;
- port = &ac->port[dir];
- for (i = 0; i < bufcnt; i++) {
- ab = &port->buf[i];
- mregions->phys = ab->phys;
- ++mregions;
- }
- rc = apr_send_pkt(this_mmap.apr, (uint32_t *) unmap_region_cmd);
- if (rc < 0) {
- pr_err("mmap_regions op[0x%x]rc[%d]\n",
- unmap_regions->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 unmap_regions\n");
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_response)) {
- pr_err("%s: ASM_SESSION_CMD_MEMORY_UNMAP_REGIONS cmd failed\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- kfree(unmap_region_cmd);
- return rc;
- }
- int q6asm_set_mute(struct audio_client *ac, int muteflag)
- {
- void *vol_cmd = NULL;
- void *payload = NULL;
- struct asm_pp_params_command *cmd = NULL;
- struct asm_mute_params *mute = NULL;
- int sz = 0;
- int rc = 0;
- sz = sizeof(struct asm_pp_params_command) +
- + sizeof(struct asm_mute_params);
- vol_cmd = kzalloc(sz, GFP_KERNEL);
- if (vol_cmd == NULL) {
- pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
- rc = -EINVAL;
- return rc;
- }
- cmd = (struct asm_pp_params_command *)vol_cmd;
- q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
- cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
- cmd->payload = NULL;
- cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
- sizeof(struct asm_mute_params);
- cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
- cmd->params.param_id = MUTE_CONFIG_PARAM_ID;
- cmd->params.param_size = sizeof(struct asm_mute_params);
- cmd->params.reserved = 0;
- payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
- mute = (struct asm_mute_params *)payload;
- mute->muteflag = muteflag;
- rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
- if (rc < 0) {
- pr_err("%s: Mute Command failed\n", __func__);
- 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 in sending mute command to apr\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- kfree(vol_cmd);
- return rc;
- }
- int q6asm_set_volume(struct audio_client *ac, int volume)
- {
- void *vol_cmd = NULL;
- void *payload = NULL;
- struct asm_pp_params_command *cmd = NULL;
- struct asm_master_gain_params *mgain = NULL;
- int sz = 0;
- int rc = 0;
- sz = sizeof(struct asm_pp_params_command) +
- + sizeof(struct asm_master_gain_params);
- vol_cmd = kzalloc(sz, GFP_KERNEL);
- if (vol_cmd == NULL) {
- pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
- rc = -EINVAL;
- return rc;
- }
- cmd = (struct asm_pp_params_command *)vol_cmd;
- q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
- cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
- cmd->payload = NULL;
- cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
- sizeof(struct asm_master_gain_params);
- cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
- cmd->params.param_id = MASTER_GAIN_PARAM_ID;
- cmd->params.param_size = sizeof(struct asm_master_gain_params);
- cmd->params.reserved = 0;
- payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
- mgain = (struct asm_master_gain_params *)payload;
- mgain->master_gain = volume;
- mgain->padding = 0x00;
- rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
- if (rc < 0) {
- pr_err("%s: Volume Command failed\n", __func__);
- 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 in sending volume command to apr\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- kfree(vol_cmd);
- return rc;
- }
- int q6asm_set_softpause(struct audio_client *ac,
- struct asm_softpause_params *pause_param)
- {
- void *vol_cmd = NULL;
- void *payload = NULL;
- struct asm_pp_params_command *cmd = NULL;
- struct asm_softpause_params *params = NULL;
- int sz = 0;
- int rc = 0;
- sz = sizeof(struct asm_pp_params_command) +
- + sizeof(struct asm_softpause_params);
- vol_cmd = kzalloc(sz, GFP_KERNEL);
- if (vol_cmd == NULL) {
- pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
- rc = -EINVAL;
- return rc;
- }
- cmd = (struct asm_pp_params_command *)vol_cmd;
- q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
- cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
- cmd->payload = NULL;
- cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
- sizeof(struct asm_softpause_params);
- cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
- cmd->params.param_id = SOFT_PAUSE_PARAM_ID;
- cmd->params.param_size = sizeof(struct asm_softpause_params);
- cmd->params.reserved = 0;
- payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
- params = (struct asm_softpause_params *)payload;
- params->enable = pause_param->enable;
- params->period = pause_param->period;
- params->step = pause_param->step;
- params->rampingcurve = pause_param->rampingcurve;
- pr_debug("%s: soft Pause Command: enable = %d, period = %d, step = %d, curve = %d\n",
- __func__, params->enable,
- params->period, params->step, params->rampingcurve);
- rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
- if (rc < 0) {
- pr_err("%s: Volume Command(soft_pause) failed\n", __func__);
- 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 in sending volume command(soft_pause) to apr\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- kfree(vol_cmd);
- return rc;
- }
- int q6asm_set_softvolume(struct audio_client *ac,
- struct asm_softvolume_params *softvol_param)
- {
- void *vol_cmd = NULL;
- void *payload = NULL;
- struct asm_pp_params_command *cmd = NULL;
- struct asm_softvolume_params *params = NULL;
- int sz = 0;
- int rc = 0;
- sz = sizeof(struct asm_pp_params_command) +
- + sizeof(struct asm_softvolume_params);
- vol_cmd = kzalloc(sz, GFP_KERNEL);
- if (vol_cmd == NULL) {
- pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
- rc = -EINVAL;
- return rc;
- }
- cmd = (struct asm_pp_params_command *)vol_cmd;
- q6asm_add_hdr_async(ac, &cmd->hdr, sz, TRUE);
- cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
- cmd->payload = NULL;
- cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
- sizeof(struct asm_softvolume_params);
- cmd->params.module_id = VOLUME_CONTROL_MODULE_ID;
- cmd->params.param_id = SOFT_VOLUME_PARAM_ID;
- cmd->params.param_size = sizeof(struct asm_softvolume_params);
- cmd->params.reserved = 0;
- payload = (u8 *)(vol_cmd + sizeof(struct asm_pp_params_command));
- params = (struct asm_softvolume_params *)payload;
- params->period = softvol_param->period;
- params->step = softvol_param->step;
- params->rampingcurve = softvol_param->rampingcurve;
- pr_debug("%s: soft Volume:opcode = %d,payload_sz =%d,module_id =%d, param_id = %d, param_sz = %d\n",
- __func__,
- cmd->hdr.opcode, cmd->payload_size,
- cmd->params.module_id, cmd->params.param_id,
- cmd->params.param_size);
- pr_debug("%s: soft Volume Command: period = %d, step = %d, curve = %d\n",
- __func__, params->period,
- params->step, params->rampingcurve);
- rc = apr_send_pkt(ac->apr, (uint32_t *) vol_cmd);
- if (rc < 0) {
- pr_err("%s: Volume Command(soft_volume) failed\n", __func__);
- 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 in sending volume command(soft_volume) to apr\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- kfree(vol_cmd);
- return rc;
- }
- int q6asm_equalizer(struct audio_client *ac, void *eq)
- {
- void *eq_cmd = NULL;
- void *payload = NULL;
- struct asm_pp_params_command *cmd = NULL;
- struct asm_equalizer_params *equalizer = NULL;
- struct msm_audio_eq_stream_config *eq_params = NULL;
- int i = 0;
- int sz = 0;
- int rc = 0;
- sz = sizeof(struct asm_pp_params_command) +
- + sizeof(struct asm_equalizer_params);
- eq_cmd = kzalloc(sz, GFP_KERNEL);
- if (eq_cmd == NULL) {
- pr_err("%s[%d]: Mem alloc failed\n", __func__, ac->session);
- rc = -EINVAL;
- goto fail_cmd;
- }
- eq_params = (struct msm_audio_eq_stream_config *) eq;
- cmd = (struct asm_pp_params_command *)eq_cmd;
- q6asm_add_hdr(ac, &cmd->hdr, sz, TRUE);
- cmd->hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS;
- cmd->payload = NULL;
- cmd->payload_size = sizeof(struct asm_pp_param_data_hdr) +
- sizeof(struct asm_equalizer_params);
- cmd->params.module_id = EQUALIZER_MODULE_ID;
- cmd->params.param_id = EQUALIZER_PARAM_ID;
- cmd->params.param_size = sizeof(struct asm_equalizer_params);
- cmd->params.reserved = 0;
- payload = (u8 *)(eq_cmd + sizeof(struct asm_pp_params_command));
- equalizer = (struct asm_equalizer_params *)payload;
- equalizer->enable = eq_params->enable;
- equalizer->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++) {
- equalizer->eq_bands[i].band_idx =
- eq_params->eq_bands[i].band_idx;
- equalizer->eq_bands[i].filter_type =
- eq_params->eq_bands[i].filter_type;
- equalizer->eq_bands[i].center_freq_hz =
- eq_params->eq_bands[i].center_freq_hz;
- equalizer->eq_bands[i].filter_gain =
- eq_params->eq_bands[i].filter_gain;
- equalizer->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_cmd);
- if (rc < 0) {
- pr_err("%s: Equalizer Command failed\n", __func__);
- 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 in sending equalizer command to apr\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- kfree(eq_cmd);
- return rc;
- }
- int q6asm_read(struct audio_client *ac)
- {
- struct asm_stream_cmd_read read;
- struct audio_buffer *ab;
- int dsp_buf;
- struct audio_port_data *port;
- int rc;
- if (!ac || ac->apr == NULL) {
- pr_err("APR handle NULL\n");
- 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;
- 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;
- read.buf_add = ab->phys;
- read.buf_size = ab->size;
- read.uid = 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_add,
- read.hdr.token,
- read.uid);
- 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_stream_cmd_read read;
- struct audio_buffer *ab;
- int dsp_buf;
- struct audio_port_data *port;
- int rc;
- if (!ac || ac->apr == NULL) {
- pr_err("APR handle NULL\n");
- 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;
- read.buf_add = ab->phys;
- read.buf_size = ab->size;
- read.uid = port->dsp_buf;
- read.hdr.token = port->dsp_buf;
- port->dsp_buf = (port->dsp_buf + 1) & (port->max_buf_cnt - 1);
- pr_info("%s:buf add[0x%x] token[%d] uid[%d]\n", __func__,
- read.buf_add,
- read.hdr.token,
- read.uid);
- 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;
- }
- static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg)
- {
- pr_debug("session=%d pkt size=%d cmd_flg=%d\n", pkt_size, cmd_flg,
- ac->session);
- 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 = ((ac->session << 8) & 0xFF00) | 0x01;
- if (cmd_flg) {
- hdr->token = ac->session;
- atomic_set(&ac->cmd_state, 1);
- }
- hdr->pkt_size = pkt_size;
- return;
- }
- int q6asm_async_write(struct audio_client *ac,
- struct audio_aio_write_param *param)
- {
- int rc = 0;
- struct asm_stream_cmd_write write;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_add_hdr_async(ac, &write.hdr, sizeof(write), FALSE);
- /* Pass physical address as token for AIO scheme */
- write.hdr.token = param->uid;
- write.hdr.opcode = ASM_DATA_CMD_WRITE;
- write.buf_add = param->paddr;
- write.avail_bytes = param->len;
- write.uid = param->uid;
- write.msw_ts = param->msw_ts;
- write.lsw_ts = param->lsw_ts;
- /* Use 0xFF00 for disabling timestamps */
- if (param->flags == 0xFF00)
- write.uflags = (0x00000000 | (param->flags & 0x800000FF));
- else
- write.uflags = (0x80000000 | param->flags);
- pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
- write.buf_add, write.avail_bytes);
- 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_stream_cmd_read read;
- 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;
- read.buf_add = param->paddr;
- read.buf_size = param->len;
- read.uid = param->uid;
- pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
- read.buf_add, read.buf_size);
- 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_async_read_compressed(struct audio_client *ac,
- struct audio_aio_read_param *param)
- {
- int rc = 0;
- struct asm_stream_cmd_read read;
- 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_COMPRESSED;
- read.buf_add = param->paddr;
- read.buf_size = param->len;
- read.uid = param->uid;
- pr_debug("%s: session[%d] bufadd[0x%x]len[0x%x]", __func__, ac->session,
- read.buf_add, read.buf_size);
- 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_stream_cmd_write write;
- struct audio_port_data *port;
- struct audio_buffer *ab;
- int dsp_buf = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("APR handle NULL\n");
- 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;
- write.buf_add = ab->phys;
- write.avail_bytes = len;
- write.uid = port->dsp_buf;
- write.msw_ts = msw_ts;
- write.lsw_ts = lsw_ts;
- /* Use 0xFF00 for disabling timestamps */
- if (flags == 0xFF00)
- write.uflags = (0x00000000 | (flags & 0x800000FF));
- else
- write.uflags = (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]"
- , __func__,
- ab->phys,
- write.buf_add,
- write.hdr.token,
- write.uid);
- mutex_unlock(&port->lock);
- #ifdef CONFIG_DEBUG_FS
- 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");
- }
- }
- #endif
- 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_stream_cmd_write write;
- struct audio_port_data *port;
- struct audio_buffer *ab;
- int dsp_buf = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("APR handle NULL\n");
- 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;
- write.buf_add = ab->phys;
- write.avail_bytes = len;
- write.uid = port->dsp_buf;
- write.msw_ts = msw_ts;
- write.lsw_ts = lsw_ts;
- /* Use 0xFF00 for disabling timestamps */
- if (flags == 0xFF00)
- write.uflags = (0x00000000 | (flags & 0x800000FF));
- else
- write.uflags = (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]"
- , __func__,
- ab->phys,
- write.buf_add,
- write.hdr.token,
- write.uid);
- 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("APR handle or tstamp NULL\n");
- return -EINVAL;
- }
- q6asm_add_hdr(ac, &hdr, sizeof(hdr), FALSE);
- hdr.opcode = ASM_SESSION_CMD_GET_SESSION_TIME;
- 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_cmd(struct audio_client *ac, int cmd)
- {
- struct apr_hdr hdr;
- int rc;
- atomic_t *state;
- int cnt = 0;
- if (!ac || ac->apr == NULL) {
- pr_err("APR handle NULL\n");
- return -EINVAL;
- }
- q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
- 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_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;
- atomic_set(&ac->cmd_close_state, 1);
- state = &ac->cmd_close_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_nowait(struct audio_client *ac, int cmd)
- {
- struct apr_hdr hdr;
- int rc;
- if (!ac || ac->apr == NULL) {
- pr_err("%s:APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE);
- 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;
- 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);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
- if (rc < 0) {
- pr_err("%s:Commmand 0x%x failed\n", __func__, hdr.opcode);
- goto fail_cmd;
- }
- atomic_inc(&ac->nowait_cmd_cnt);
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- 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_stream_cmd_reg_tx_overflow_event tx_overflow;
- 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(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
- tx_overflow.hdr.opcode = \
- ASM_SESSION_CMD_REGISTER_FOR_TX_OVERFLOW_EVENTS;
- /* tx overflow event: enable */
- tx_overflow.enable = 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_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 __init q6asm_init(void)
- {
- pr_debug("%s\n", __func__);
- init_waitqueue_head(&this_mmap.cmd_wait);
- memset(session, 0, sizeof(session));
- #ifdef CONFIG_DEBUG_FS
- out_buffer = kmalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
- out_dentry = debugfs_create_file("audio_out_latency_measurement_node",\
- S_IFREG | S_IRUGO | S_IWUGO,\
- NULL, NULL, &audio_output_latency_debug_fops);
- if (IS_ERR(out_dentry))
- pr_err("debugfs_create_file failed\n");
- in_buffer = kmalloc(IN_BUFFER_SIZE, GFP_KERNEL);
- in_dentry = debugfs_create_file("audio_in_latency_measurement_node",\
- S_IFREG | S_IRUGO | S_IWUGO,\
- NULL, NULL, &audio_input_latency_debug_fops);
- if (IS_ERR(in_dentry))
- pr_err("debugfs_create_file failed\n");
- #endif
- return 0;
- }
- device_initcall(q6asm_init);
|