1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330 |
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
- * Author: Brian Swetland <[email protected]>
- *
- * 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/slab.h>
- #include <linux/debugfs.h>
- #include <linux/time.h>
- #include <linux/atomic.h>
- #include <linux/mm.h>
- #include <asm/ioctls.h>
- #include <linux/memory.h>
- #include <sound/compress_params.h>
- #include <dsp/msm_audio_ion.h>
- #include <dsp/apr_audio-v2.h>
- #include <dsp/audio_cal_utils.h>
- #include <dsp/q6asm-v2.h>
- #include <dsp/q6audio-v2.h>
- #include <dsp/q6common.h>
- #include <dsp/q6core.h>
- #include "adsp_err.h"
- #define TIMEOUT_MS 1000
- #define TRUE 0x01
- #define FALSE 0x00
- #define SESSION_MAX 8
- #define ENC_FRAMES_PER_BUFFER 0x01
- enum {
- ASM_TOPOLOGY_CAL = 0,
- ASM_CUSTOM_TOP_CAL,
- ASM_AUDSTRM_CAL,
- ASM_RTAC_APR_CAL,
- ASM_MAX_CAL_TYPES
- };
- union asm_token_struct {
- struct {
- u8 stream_id;
- u8 session_id;
- u8 buf_index;
- u8 flags;
- } _token;
- u32 token;
- } __packed;
- enum {
- ASM_DIRECTION_OFFSET,
- ASM_CMD_NO_WAIT_OFFSET,
- /*
- * Offset is limited to 7 because flags is stored in u8
- * field in asm_token_structure defined above. The offset
- * starts from 0.
- */
- ASM_MAX_OFFSET = 7,
- };
- enum {
- WAIT_CMD,
- NO_WAIT_CMD
- };
- #define ASM_SET_BIT(n, x) (n |= 1 << x)
- #define ASM_TEST_BIT(n, x) ((n >> x) & 1)
- /* TODO, combine them together */
- static DEFINE_MUTEX(session_lock);
- struct asm_mmap {
- atomic_t ref_cnt;
- void *apr;
- };
- static struct asm_mmap this_mmap;
- struct audio_session {
- struct audio_client *ac;
- spinlock_t session_lock;
- struct mutex mutex_lock_per_session;
- };
- /* session id: 0 reserved */
- static struct audio_session session[ASM_ACTIVE_STREAMS_ALLOWED + 1];
- struct asm_buffer_node {
- struct list_head list;
- phys_addr_t buf_phys_addr;
- uint32_t mmap_hdl;
- };
- static int32_t q6asm_srvc_callback(struct apr_client_data *data, void *priv);
- static int32_t q6asm_callback(struct apr_client_data *data, void *priv);
- static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg);
- static void q6asm_add_hdr_custom_topology(struct audio_client *ac,
- struct apr_hdr *hdr,
- uint32_t pkt_size);
- static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg);
- static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
- uint32_t bufsz, uint32_t bufcnt,
- bool is_contiguous);
- static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir);
- static void q6asm_reset_buf_state(struct audio_client *ac);
- void *q6asm_mmap_apr_reg(void);
- static int q6asm_is_valid_session(struct apr_client_data *data, void *priv);
- static int q6asm_get_asm_topology_apptype(struct q6asm_cal_info *cal_info);
- /* for ASM custom topology */
- static struct cal_type_data *cal_data[ASM_MAX_CAL_TYPES];
- static struct audio_buffer common_buf[2];
- static struct audio_client common_client;
- static int set_custom_topology;
- static int topology_map_handle;
- struct generic_get_data_ {
- int valid;
- int is_inband;
- int size_in_ints;
- int ints[];
- };
- static struct generic_get_data_ *generic_get_data;
- #ifdef CONFIG_DEBUG_FS
- #define OUT_BUFFER_SIZE 56
- #define IN_BUFFER_SIZE 24
- static struct timeval out_cold_tv;
- static struct timeval out_warm_tv;
- static struct timeval out_cont_tv;
- static struct timeval in_cont_tv;
- static long out_enable_flag;
- static long in_enable_flag;
- static struct dentry *out_dentry;
- static struct dentry *in_dentry;
- static int in_cont_index;
- /*This var is used to keep track of first write done for cold output latency */
- static int out_cold_index;
- static char *out_buffer;
- static char *in_buffer;
- static uint32_t adsp_reg_event_opcode[] = {
- ASM_STREAM_CMD_REGISTER_PP_EVENTS,
- ASM_STREAM_CMD_REGISTER_ENCDEC_EVENTS,
- ASM_STREAM_CMD_REGISTER_IEC_61937_FMT_UPDATE };
- static uint32_t adsp_raise_event_opcode[] = {
- ASM_STREAM_PP_EVENT,
- ASM_STREAM_CMD_ENCDEC_EVENTS,
- ASM_IEC_61937_MEDIA_FMT_EVENT };
- static int is_adsp_reg_event(uint32_t cmd)
- {
- int i;
- for (i = 0; i < ARRAY_SIZE(adsp_reg_event_opcode); i++) {
- if (cmd == adsp_reg_event_opcode[i])
- return i;
- }
- return -EINVAL;
- }
- static int is_adsp_raise_event(uint32_t cmd)
- {
- int i;
- for (i = 0; i < ARRAY_SIZE(adsp_raise_event_opcode); i++) {
- if (cmd == adsp_raise_event_opcode[i])
- return i;
- }
- return -EINVAL;
- }
- static inline void q6asm_set_flag_in_token(union asm_token_struct *asm_token,
- int flag, int flag_offset)
- {
- if (flag)
- ASM_SET_BIT(asm_token->_token.flags, flag_offset);
- }
- static inline int q6asm_get_flag_from_token(union asm_token_struct *asm_token,
- int flag_offset)
- {
- return ASM_TEST_BIT(asm_token->_token.flags, flag_offset);
- }
- static inline void q6asm_update_token(u32 *token, u8 session_id, u8 stream_id,
- u8 buf_index, u8 dir, u8 nowait_flag)
- {
- union asm_token_struct asm_token;
- asm_token.token = 0;
- asm_token._token.session_id = session_id;
- asm_token._token.stream_id = stream_id;
- asm_token._token.buf_index = buf_index;
- q6asm_set_flag_in_token(&asm_token, dir, ASM_DIRECTION_OFFSET);
- q6asm_set_flag_in_token(&asm_token, nowait_flag,
- ASM_CMD_NO_WAIT_OFFSET);
- *token = asm_token.token;
- }
- static inline uint32_t q6asm_get_pcm_format_id(uint32_t media_format_block_ver)
- {
- uint32_t pcm_format_id;
- switch (media_format_block_ver) {
- case PCM_MEDIA_FORMAT_V5:
- pcm_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V5;
- break;
- case PCM_MEDIA_FORMAT_V4:
- pcm_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V4;
- break;
- case PCM_MEDIA_FORMAT_V3:
- pcm_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V3;
- break;
- case PCM_MEDIA_FORMAT_V2:
- default:
- pcm_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- break;
- }
- return pcm_format_id;
- }
- /*
- * q6asm_get_buf_index_from_token:
- * Retrieve buffer index from token.
- *
- * @token: token value sent to ASM service on q6.
- * Returns buffer index in the read/write commands.
- */
- uint8_t q6asm_get_buf_index_from_token(uint32_t token)
- {
- union asm_token_struct asm_token;
- asm_token.token = token;
- return asm_token._token.buf_index;
- }
- EXPORT_SYMBOL(q6asm_get_buf_index_from_token);
- /*
- * q6asm_get_stream_id_from_token:
- * Retrieve stream id from token.
- *
- * @token: token value sent to ASM service on q6.
- * Returns stream id.
- */
- uint8_t q6asm_get_stream_id_from_token(uint32_t token)
- {
- union asm_token_struct asm_token;
- asm_token.token = token;
- return asm_token._token.stream_id;
- }
- EXPORT_SYMBOL(q6asm_get_stream_id_from_token);
- static int audio_output_latency_dbgfs_open(struct inode *inode,
- struct file *file)
- {
- file->private_data = inode->i_private;
- return 0;
- }
- static ssize_t audio_output_latency_dbgfs_read(struct file *file,
- char __user *buf, size_t count, loff_t *ppos)
- {
- if (out_buffer == NULL) {
- pr_err("%s: out_buffer is null\n", __func__);
- return 0;
- }
- if (count < OUT_BUFFER_SIZE) {
- pr_err("%s: read size %d exceeds buf size %zd\n", __func__,
- OUT_BUFFER_SIZE, count);
- return 0;
- }
- snprintf(out_buffer, OUT_BUFFER_SIZE, "%ld,%ld,%ld,%ld,%ld,%ld,",
- out_cold_tv.tv_sec, out_cold_tv.tv_usec, out_warm_tv.tv_sec,
- out_warm_tv.tv_usec, out_cont_tv.tv_sec, out_cont_tv.tv_usec);
- return simple_read_from_buffer(buf, OUT_BUFFER_SIZE, ppos,
- out_buffer, OUT_BUFFER_SIZE);
- }
- static ssize_t audio_output_latency_dbgfs_write(struct file *file,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- char *temp;
- if (count > 2*sizeof(char)) {
- pr_err("%s: err count is more %zd\n", __func__, count);
- return -EINVAL;
- }
- temp = kmalloc(2*sizeof(char), GFP_KERNEL);
- out_cold_index = 0;
- if (temp) {
- if (copy_from_user(temp, buf, 2*sizeof(char))) {
- pr_err("%s: copy from user failed for size %zd\n",
- __func__, 2*sizeof(char));
- kfree(temp);
- return -EFAULT;
- }
- if (!kstrtol(temp, 10, &out_enable_flag)) {
- kfree(temp);
- return count;
- }
- kfree(temp);
- }
- return -EINVAL;
- }
- static const struct file_operations audio_output_latency_debug_fops = {
- .open = audio_output_latency_dbgfs_open,
- .read = audio_output_latency_dbgfs_read,
- .write = audio_output_latency_dbgfs_write
- };
- static int audio_input_latency_dbgfs_open(struct inode *inode,
- struct file *file)
- {
- file->private_data = inode->i_private;
- return 0;
- }
- static ssize_t audio_input_latency_dbgfs_read(struct file *file,
- char __user *buf, size_t count, loff_t *ppos)
- {
- if (in_buffer == NULL) {
- pr_err("%s: in_buffer is null\n", __func__);
- return 0;
- }
- if (count < IN_BUFFER_SIZE) {
- pr_err("%s: read size %d exceeds buf size %zd\n", __func__,
- IN_BUFFER_SIZE, count);
- return 0;
- }
- snprintf(in_buffer, IN_BUFFER_SIZE, "%ld,%ld,",
- in_cont_tv.tv_sec, in_cont_tv.tv_usec);
- return simple_read_from_buffer(buf, IN_BUFFER_SIZE, ppos,
- in_buffer, IN_BUFFER_SIZE);
- }
- static ssize_t audio_input_latency_dbgfs_write(struct file *file,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- char *temp;
- if (count > 2*sizeof(char)) {
- pr_err("%s: err count is more %zd\n", __func__, count);
- return -EINVAL;
- }
- temp = kmalloc(2*sizeof(char), GFP_KERNEL);
- if (temp) {
- if (copy_from_user(temp, buf, 2*sizeof(char))) {
- pr_err("%s: copy from user failed for size %zd\n",
- __func__, 2*sizeof(char));
- kfree(temp);
- return -EFAULT;
- }
- if (!kstrtol(temp, 10, &in_enable_flag)) {
- kfree(temp);
- return count;
- }
- kfree(temp);
- }
- return -EINVAL;
- }
- static const struct file_operations audio_input_latency_debug_fops = {
- .open = audio_input_latency_dbgfs_open,
- .read = audio_input_latency_dbgfs_read,
- .write = audio_input_latency_dbgfs_write
- };
- /*
- * get_monotonic_timeval -
- * This method returns a structure in timeval
- * format (sec,microsec) by using ktime kernel
- * API to get time in nano secs and then converts
- * it to timeval format
- *
- * ktime_get [nsec]-> ktime_to_timespec [sec,nsec]-> timeval[sec,usec]
- *
- * Returns struct timeval
- */
- static struct timeval get_monotonic_timeval(void)
- {
- static struct timeval out_tval;
- /* Get time from monotonic clock in nanoseconds */
- ktime_t kTimeNsec = ktime_get();
- /* Convert it to timespec format and later to timeval as expected by audio HAL */
- struct timespec temp_tspec = ktime_to_timespec(kTimeNsec);
- /* Time returned above is in sec,nanosec format, needs to convert to sec,microsec */
- out_tval.tv_usec = temp_tspec.tv_nsec/1000;
- out_tval.tv_sec = temp_tspec.tv_sec;
- return out_tval;
- }
- static void config_debug_fs_write_cb(void)
- {
- if (out_enable_flag) {
- /* For first Write done log the time and reset
- * out_cold_index
- */
- if (out_cold_index != 1) {
- out_cold_tv = get_monotonic_timeval();
- 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("%s: out_enable_flag %ld\n",
- __func__, out_enable_flag);
- }
- }
- static void config_debug_fs_read_cb(void)
- {
- if (in_enable_flag) {
- /* when in_cont_index == 7, DSP would be
- * writing into the 8th 512 byte buffer and this
- * timestamp is tapped here.Once done it then writes
- * to 9th 512 byte buffer.These two buffers(8th, 9th)
- * reach the test application in 5th iteration and that
- * timestamp is tapped at user level. The difference
- * of these two timestamps gives us the time between
- * the time at which dsp started filling the sample
- * required and when it reached the test application.
- * Hence continuous input latency
- */
- if (in_cont_index == 7) {
- in_cont_tv = get_monotonic_timeval();
- pr_info("%s: read buffer at %ld sec %ld microsec\n",
- __func__,
- in_cont_tv.tv_sec, in_cont_tv.tv_usec);
- }
- in_cont_index++;
- }
- }
- static void config_debug_fs_reset_index(void)
- {
- in_cont_index = 0;
- }
- static void config_debug_fs_run(void)
- {
- if (out_enable_flag) {
- out_cold_tv = get_monotonic_timeval();
- pr_debug("%s: COLD apr_send_pkt at %ld sec %ld microsec\n",
- __func__, out_cold_tv.tv_sec, out_cold_tv.tv_usec);
- }
- }
- static void config_debug_fs_write(struct audio_buffer *ab)
- {
- if (out_enable_flag) {
- char zero_pattern[2] = {0x00, 0x00};
- /* If First two byte is non zero and last two byte
- * is zero then it is warm output pattern
- */
- if ((strcmp(((char *)ab->data), zero_pattern)) &&
- (!strcmp(((char *)ab->data + 2), zero_pattern))) {
- out_warm_tv = get_monotonic_timeval();
- pr_debug("%s: WARM:apr_send_pkt at %ld sec %ld microsec\n",
- __func__,
- out_warm_tv.tv_sec,
- out_warm_tv.tv_usec);
- pr_debug("%s: Warm Pattern Matched\n", __func__);
- }
- /* If First two byte is zero and last two byte is
- * non zero then it is cont output pattern
- */
- else if ((!strcmp(((char *)ab->data), zero_pattern))
- && (strcmp(((char *)ab->data + 2), zero_pattern))) {
- out_cont_tv = get_monotonic_timeval();
- pr_debug("%s: CONT:apr_send_pkt at %ld sec %ld microsec\n",
- __func__,
- out_cont_tv.tv_sec,
- out_cont_tv.tv_usec);
- pr_debug("%s: Cont Pattern Matched\n", __func__);
- }
- }
- }
- static void config_debug_fs_init(void)
- {
- out_buffer = kzalloc(OUT_BUFFER_SIZE, GFP_KERNEL);
- if (out_buffer == NULL)
- goto outbuf_fail;
- in_buffer = kzalloc(IN_BUFFER_SIZE, GFP_KERNEL);
- if (in_buffer == NULL)
- goto inbuf_fail;
- out_dentry = debugfs_create_file("audio_out_latency_measurement_node",
- 0664,
- NULL, NULL, &audio_output_latency_debug_fops);
- if (IS_ERR(out_dentry)) {
- pr_err("%s: debugfs_create_file failed\n", __func__);
- goto file_fail;
- }
- in_dentry = debugfs_create_file("audio_in_latency_measurement_node",
- 0664,
- NULL, NULL, &audio_input_latency_debug_fops);
- if (IS_ERR(in_dentry)) {
- pr_err("%s: debugfs_create_file failed\n", __func__);
- goto file_fail;
- }
- return;
- file_fail:
- kfree(in_buffer);
- inbuf_fail:
- kfree(out_buffer);
- outbuf_fail:
- in_buffer = NULL;
- out_buffer = NULL;
- }
- #else
- static void config_debug_fs_write(struct audio_buffer *ab)
- {
- }
- static void config_debug_fs_run(void)
- {
- }
- static void config_debug_fs_reset_index(void)
- {
- }
- static void config_debug_fs_read_cb(void)
- {
- }
- static void config_debug_fs_write_cb(void)
- {
- }
- static void config_debug_fs_init(void)
- {
- }
- #endif
- int q6asm_mmap_apr_dereg(void)
- {
- int c;
- c = atomic_sub_return(1, &this_mmap.ref_cnt);
- if (c == 0) {
- apr_deregister(this_mmap.apr);
- common_client.mmap_apr = NULL;
- pr_debug("%s: APR De-Register common port\n", __func__);
- } else if (c < 0) {
- pr_err("%s: APR Common Port Already Closed %d\n",
- __func__, c);
- atomic_set(&this_mmap.ref_cnt, 0);
- }
- return 0;
- }
- static int q6asm_session_alloc(struct audio_client *ac)
- {
- int n;
- for (n = 1; n <= ASM_ACTIVE_STREAMS_ALLOWED; n++) {
- if (!(session[n].ac)) {
- session[n].ac = ac;
- return n;
- }
- }
- pr_err("%s: session not available\n", __func__);
- return -ENOMEM;
- }
- static int q6asm_get_session_id_from_audio_client(struct audio_client *ac)
- {
- int n;
- for (n = 1; n <= ASM_ACTIVE_STREAMS_ALLOWED; n++) {
- if (session[n].ac == ac)
- return n;
- }
- pr_debug("%s: cannot find matching audio client. ac = %pK\n",
- __func__, ac);
- return 0;
- }
- static bool q6asm_is_valid_audio_client(struct audio_client *ac)
- {
- return q6asm_get_session_id_from_audio_client(ac) ? 1 : 0;
- }
- static void q6asm_session_free(struct audio_client *ac)
- {
- int session_id;
- unsigned long flags = 0;
- pr_debug("%s: sessionid[%d]\n", __func__, ac->session);
- session_id = ac->session;
- mutex_lock(&session[session_id].mutex_lock_per_session);
- rtac_remove_popp_from_adm_devices(ac->session);
- spin_lock_irqsave(&(session[session_id].session_lock), flags);
- session[ac->session].ac = NULL;
- ac->session = 0;
- ac->perf_mode = LEGACY_PCM_MODE;
- ac->fptr_cache_ops = NULL;
- ac->cb = NULL;
- ac->priv = NULL;
- kfree(ac);
- ac = NULL;
- spin_unlock_irqrestore(&(session[session_id].session_lock), flags);
- mutex_unlock(&session[session_id].mutex_lock_per_session);
- }
- static uint32_t q6asm_get_next_buf(struct audio_client *ac,
- uint32_t curr_buf, uint32_t max_buf_cnt)
- {
- dev_vdbg(ac->dev, "%s: curr_buf = %d, max_buf_cnt = %d\n",
- __func__, curr_buf, max_buf_cnt);
- curr_buf += 1;
- return (curr_buf >= max_buf_cnt) ? 0 : curr_buf;
- }
- static int q6asm_map_cal_memory(int32_t cal_type,
- struct cal_block_data *cal_block)
- {
- int result = 0;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- if (cal_block == NULL) {
- pr_err("%s: cal_block is NULL!\n",
- __func__);
- goto done;
- }
- if (cal_block->cal_data.paddr == 0) {
- pr_debug("%s: No address to map!\n",
- __func__);
- goto done;
- }
- common_client.mmap_apr = q6asm_mmap_apr_reg();
- if (common_client.mmap_apr == NULL) {
- pr_err("%s: q6asm_mmap_apr_reg failed\n",
- __func__);
- result = -EPERM;
- goto done;
- }
- common_client.apr = common_client.mmap_apr;
- if (cal_block->map_data.map_size == 0) {
- pr_debug("%s: map size is 0!\n",
- __func__);
- goto done;
- }
- /* Use second asm buf to map memory */
- if (common_client.port[IN].buf == NULL) {
- pr_err("%s: common buf is NULL\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- common_client.port[IN].buf->phys = cal_block->cal_data.paddr;
- result = q6asm_memory_map_regions(&common_client,
- IN, cal_block->map_data.map_size, 1, 1);
- if (result < 0) {
- pr_err("%s: mmap did not work! size = %zd result %d\n",
- __func__,
- cal_block->map_data.map_size, result);
- pr_debug("%s: mmap did not work! addr = 0x%pK, size = %zd\n",
- __func__,
- &cal_block->cal_data.paddr,
- cal_block->map_data.map_size);
- goto done;
- }
- list_for_each_safe(ptr, next,
- &common_client.port[IN].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == cal_block->cal_data.paddr) {
- cal_block->map_data.q6map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- done:
- return result;
- }
- static int remap_cal_data(int32_t cal_type, struct cal_block_data *cal_block)
- {
- int ret = 0;
- if (cal_block->map_data.dma_buf == NULL) {
- pr_err("%s: No ION allocation for cal type %d!\n",
- __func__, cal_type);
- ret = -EINVAL;
- goto done;
- }
- if ((cal_block->map_data.map_size > 0) &&
- (cal_block->map_data.q6map_handle == 0)) {
- ret = q6asm_map_cal_memory(cal_type, cal_block);
- if (ret < 0) {
- pr_err("%s: mmap did not work! size = %zd ret %d\n",
- __func__, cal_block->map_data.map_size, ret);
- goto done;
- }
- }
- done:
- return ret;
- }
- static int q6asm_unmap_cal_memory(int32_t cal_type,
- struct cal_block_data *cal_block)
- {
- int result = 0;
- int result2 = 0;
- if (cal_block == NULL) {
- pr_err("%s: cal_block is NULL!\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- if (cal_block->map_data.q6map_handle == 0) {
- pr_debug("%s: No address to unmap!\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- if (common_client.mmap_apr == NULL) {
- common_client.mmap_apr = q6asm_mmap_apr_reg();
- if (common_client.mmap_apr == NULL) {
- pr_err("%s: q6asm_mmap_apr_reg failed\n",
- __func__);
- result = -EPERM;
- goto done;
- }
- }
- result2 = q6asm_memory_unmap_regions(&common_client, IN);
- if (result2 < 0) {
- pr_err("%s: unmap failed, err %d\n",
- __func__, result2);
- result = result2;
- }
- cal_block->map_data.q6map_handle = 0;
- done:
- return result;
- }
- int q6asm_unmap_cal_data(int cal_type, struct cal_block_data *cal_block)
- {
- int ret = 0;
- if ((cal_block->map_data.map_size > 0) &&
- (cal_block->map_data.q6map_handle != 0)) {
- ret = q6asm_unmap_cal_memory(cal_type, cal_block);
- if (ret < 0) {
- pr_err("%s: unmap did not work! size = %zd ret %d\n",
- __func__, cal_block->map_data.map_size, ret);
- goto done;
- }
- }
- done:
- return ret;
- }
- int send_asm_custom_topology(struct audio_client *ac)
- {
- struct cal_block_data *cal_block = NULL;
- struct cmd_set_topologies asm_top;
- int result = 0;
- int result1 = 0;
- if (cal_data[ASM_CUSTOM_TOP_CAL] == NULL)
- goto done;
- mutex_lock(&cal_data[ASM_CUSTOM_TOP_CAL]->lock);
- if (!set_custom_topology)
- goto unlock;
- set_custom_topology = 0;
- cal_block = cal_utils_get_only_cal_block(cal_data[ASM_CUSTOM_TOP_CAL]);
- if (cal_block == NULL || cal_utils_is_cal_stale(cal_block))
- goto unlock;
- if (cal_block->cal_data.size == 0) {
- pr_debug("%s: No cal to send!\n", __func__);
- goto unlock;
- }
- pr_debug("%s: Sending cal_index %d\n", __func__, ASM_CUSTOM_TOP_CAL);
- result = remap_cal_data(ASM_CUST_TOPOLOGY_CAL_TYPE, cal_block);
- if (result) {
- pr_err("%s: Remap_cal_data failed for cal %d!\n",
- __func__, ASM_CUSTOM_TOP_CAL);
- goto unlock;
- }
- q6asm_add_hdr_custom_topology(ac, &asm_top.hdr, sizeof(asm_top));
- atomic_set(&ac->mem_state, -1);
- asm_top.hdr.opcode = ASM_CMD_ADD_TOPOLOGIES;
- asm_top.payload_addr_lsw = lower_32_bits(cal_block->cal_data.paddr);
- asm_top.payload_addr_msw = msm_audio_populate_upper_32_bits(
- cal_block->cal_data.paddr);
- asm_top.mem_map_handle = cal_block->map_data.q6map_handle;
- asm_top.payload_size = cal_block->cal_data.size;
- pr_debug("%s: Sending ASM_CMD_ADD_TOPOLOGIES payload = %pK, size = %d, map handle = 0x%x\n",
- __func__, &cal_block->cal_data.paddr,
- asm_top.payload_size, asm_top.mem_map_handle);
- result = apr_send_pkt(ac->apr, (uint32_t *) &asm_top);
- if (result < 0) {
- pr_err("%s: Set topologies failed result %d\n",
- __func__, result);
- pr_debug("%s: Set topologies failed payload = 0x%pK\n",
- __func__, &cal_block->cal_data.paddr);
- goto unmap;
- }
- result = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!result) {
- pr_err("%s: Set topologies failed timeout\n", __func__);
- pr_debug("%s: Set topologies failed after timedout payload = 0x%pK\n",
- __func__, &cal_block->cal_data.paddr);
- result = -ETIMEDOUT;
- goto unmap;
- }
- if (atomic_read(&ac->mem_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->mem_state)));
- result = adsp_err_get_lnx_err_code(
- atomic_read(&ac->mem_state));
- goto unmap;
- }
- unmap:
- result1 = q6asm_unmap_cal_memory(ASM_CUST_TOPOLOGY_CAL_TYPE,
- cal_block);
- if (result1 < 0) {
- result = result1;
- pr_debug("%s: unmap cal failed! %d\n", __func__, result);
- }
- unlock:
- mutex_unlock(&cal_data[ASM_CUSTOM_TOP_CAL]->lock);
- done:
- return result;
- }
- int q6asm_map_rtac_block(struct rtac_cal_block_data *cal_block)
- {
- int result = 0;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- pr_debug("%s:\n", __func__);
- if (cal_block == NULL) {
- pr_err("%s: cal_block is NULL!\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- if (cal_block->cal_data.paddr == 0) {
- pr_debug("%s: No address to map!\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- if (common_client.mmap_apr == NULL) {
- common_client.mmap_apr = q6asm_mmap_apr_reg();
- if (common_client.mmap_apr == NULL) {
- pr_err("%s: q6asm_mmap_apr_reg failed\n",
- __func__);
- result = -EPERM;
- goto done;
- }
- }
- if (cal_block->map_data.map_size == 0) {
- pr_debug("%s: map size is 0!\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- /* Use second asm buf to map memory */
- if (common_client.port[OUT].buf == NULL) {
- pr_err("%s: common buf is NULL\n",
- __func__);
- result = -EINVAL;
- goto done;
- }
- common_client.port[OUT].buf->phys = cal_block->cal_data.paddr;
- result = q6asm_memory_map_regions(&common_client,
- OUT, cal_block->map_data.map_size, 1, 1);
- if (result < 0) {
- pr_err("%s: mmap did not work! size = %d result %d\n",
- __func__,
- cal_block->map_data.map_size, result);
- pr_debug("%s: mmap did not work! addr = 0x%pK, size = %d\n",
- __func__,
- &cal_block->cal_data.paddr,
- cal_block->map_data.map_size);
- goto done;
- }
- list_for_each_safe(ptr, next,
- &common_client.port[OUT].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == cal_block->cal_data.paddr) {
- cal_block->map_data.map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- done:
- return result;
- }
- int q6asm_unmap_rtac_block(uint32_t *mem_map_handle)
- {
- int result = 0;
- int result2 = 0;
- pr_debug("%s:\n", __func__);
- if (mem_map_handle == NULL) {
- pr_debug("%s: Map handle is NULL, nothing to unmap\n",
- __func__);
- goto done;
- }
- if (*mem_map_handle == 0) {
- pr_debug("%s: Map handle is 0, nothing to unmap\n",
- __func__);
- goto done;
- }
- if (common_client.mmap_apr == NULL) {
- common_client.mmap_apr = q6asm_mmap_apr_reg();
- if (common_client.mmap_apr == NULL) {
- pr_err("%s: q6asm_mmap_apr_reg failed\n",
- __func__);
- result = -EPERM;
- goto done;
- }
- }
- result2 = q6asm_memory_unmap_regions(&common_client, OUT);
- if (result2 < 0) {
- pr_err("%s: unmap failed, err %d\n",
- __func__, result2);
- result = result2;
- } else {
- *mem_map_handle = 0;
- }
- result2 = q6asm_mmap_apr_dereg();
- if (result2 < 0) {
- pr_err("%s: q6asm_mmap_apr_dereg failed, err %d\n",
- __func__, result2);
- result = result2;
- }
- done:
- return result;
- }
- int q6asm_audio_client_buf_free(unsigned int dir,
- struct audio_client *ac)
- {
- struct audio_port_data *port;
- int cnt = 0;
- int rc = 0;
- pr_debug("%s: Session id %d\n", __func__, ac->session);
- mutex_lock(&ac->cmd_lock);
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[dir];
- if (!port->buf) {
- pr_err("%s: buf NULL\n", __func__);
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- cnt = port->max_buf_cnt - 1;
- if (cnt >= 0) {
- rc = q6asm_memory_unmap_regions(ac, dir);
- if (rc < 0)
- pr_err("%s: Memory_unmap_regions failed %d\n",
- __func__, rc);
- }
- while (cnt >= 0) {
- if (port->buf[cnt].data) {
- if (!rc || atomic_read(&ac->reset))
- msm_audio_ion_free(
- port->buf[cnt].dma_buf);
- port->buf[cnt].dma_buf = NULL;
- port->buf[cnt].data = NULL;
- port->buf[cnt].phys = 0;
- --(port->max_buf_cnt);
- }
- --cnt;
- }
- kfree(port->buf);
- port->buf = NULL;
- }
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- /**
- * q6asm_audio_client_buf_free_contiguous -
- * frees the memory buffers for ASM
- *
- * @dir: RX or TX direction
- * @ac: audio client handle
- *
- * Returns 0 on success or error on failure
- */
- 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: Memory_unmap_regions failed %d\n",
- __func__, rc);
- }
- if (port->buf[0].data) {
- pr_debug("%s: data[%pK], phys[%pK], dma_buf[%pK]\n",
- __func__,
- port->buf[0].data,
- &port->buf[0].phys,
- port->buf[0].dma_buf);
- if (!rc || atomic_read(&ac->reset))
- msm_audio_ion_free(port->buf[0].dma_buf);
- port->buf[0].dma_buf = NULL;
- }
- while (cnt >= 0) {
- port->buf[cnt].data = NULL;
- port->buf[cnt].phys = 0;
- cnt--;
- }
- port->max_buf_cnt = 0;
- kfree(port->buf);
- port->buf = NULL;
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- EXPORT_SYMBOL(q6asm_audio_client_buf_free_contiguous);
- /**
- * q6asm_audio_client_free -
- * frees the audio client for ASM
- *
- * @ac: audio client handle
- *
- */
- void q6asm_audio_client_free(struct audio_client *ac)
- {
- int loopcnt;
- struct audio_port_data *port;
- if (!ac) {
- pr_err("%s: ac %pK\n", __func__, ac);
- return;
- }
- if (!ac->session) {
- pr_err("%s: ac session invalid\n", __func__);
- return;
- }
- mutex_lock(&session_lock);
- pr_debug("%s: Session id %d\n", __func__, ac->session);
- if (ac->io_mode & SYNC_IO_MODE) {
- for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
- port = &ac->port[loopcnt];
- if (!port->buf)
- continue;
- pr_debug("%s: loopcnt = %d\n",
- __func__, loopcnt);
- q6asm_audio_client_buf_free(loopcnt, ac);
- }
- }
- rtac_set_asm_handle(ac->session, NULL);
- apr_deregister(ac->apr2);
- apr_deregister(ac->apr);
- q6asm_mmap_apr_dereg();
- ac->apr2 = NULL;
- ac->apr = NULL;
- ac->mmap_apr = NULL;
- q6asm_session_free(ac);
- pr_debug("%s: APR De-Register\n", __func__);
- /*done:*/
- mutex_unlock(&session_lock);
- }
- EXPORT_SYMBOL(q6asm_audio_client_free);
- /**
- * q6asm_set_io_mode -
- * Update IO mode for ASM
- *
- * @ac: audio client handle
- * @mode1: IO mode to update
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_set_io_mode(struct audio_client *ac, uint32_t mode1)
- {
- uint32_t mode;
- int ret = 0;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- ac->io_mode &= 0xFF00;
- mode = (mode1 & 0xF);
- pr_debug("%s: ac->mode after anding with FF00:0x%x,\n",
- __func__, ac->io_mode);
- if ((mode == ASYNC_IO_MODE) || (mode == SYNC_IO_MODE)) {
- ac->io_mode |= mode1;
- pr_debug("%s: Set Mode to 0x%x\n", __func__, ac->io_mode);
- } else {
- pr_err("%s: Not an valid IO Mode:%d\n", __func__, ac->io_mode);
- ret = -EINVAL;
- }
- return ret;
- }
- EXPORT_SYMBOL(q6asm_set_io_mode);
- void *q6asm_mmap_apr_reg(void)
- {
- if ((atomic_read(&this_mmap.ref_cnt) == 0) ||
- (this_mmap.apr == NULL)) {
- this_mmap.apr = apr_register("ADSP", "ASM",
- (apr_fn)q6asm_srvc_callback,
- 0x0FFFFFFFF, &this_mmap);
- if (this_mmap.apr == NULL) {
- pr_debug("%s: Unable to register APR ASM common port\n",
- __func__);
- goto fail;
- }
- }
- atomic_inc(&this_mmap.ref_cnt);
- return this_mmap.apr;
- fail:
- return NULL;
- }
- /**
- * q6asm_send_stream_cmd -
- * command to send for ASM stream
- *
- * @ac: audio client handle
- * @data: event data
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_send_stream_cmd(struct audio_client *ac,
- struct msm_adsp_event_data *data)
- {
- char *asm_params = NULL;
- struct apr_hdr hdr;
- int rc;
- uint32_t sz = 0;
- uint64_t actual_sz = 0;
- int session_id = 0;
- if (!data || !ac) {
- pr_err("%s: %s is NULL\n", __func__,
- (!data) ? "data" : "ac");
- rc = -EINVAL;
- goto done;
- }
- session_id = q6asm_get_session_id_from_audio_client(ac);
- if (!session_id) {
- rc = -EINVAL;
- goto done;
- }
- if (data->event_type >= ARRAY_SIZE(adsp_reg_event_opcode)) {
- pr_err("%s: event %u out of boundary of array size of (%lu)\n",
- __func__, data->event_type,
- (long)ARRAY_SIZE(adsp_reg_event_opcode));
- rc = -EINVAL;
- goto done;
- }
- actual_sz = sizeof(struct apr_hdr) + data->payload_len;
- if (actual_sz > U32_MAX) {
- pr_err("%s: payload size 0x%X exceeds limit\n",
- __func__, data->payload_len);
- rc = -EINVAL;
- goto done;
- }
- sz = (uint32_t)actual_sz;
- asm_params = kzalloc(sz, GFP_KERNEL);
- if (!asm_params) {
- rc = -ENOMEM;
- goto done;
- }
- mutex_lock(&session[session_id].mutex_lock_per_session);
- if (!q6asm_is_valid_audio_client(ac)) {
- rc = -EINVAL;
- goto fail_send_param;
- }
- q6asm_add_hdr_async(ac, &hdr, sz, TRUE);
- atomic_set(&ac->cmd_state_pp, -1);
- hdr.opcode = adsp_reg_event_opcode[data->event_type];
- memcpy(asm_params, &hdr, sizeof(struct apr_hdr));
- memcpy(asm_params + sizeof(struct apr_hdr),
- data->payload, data->payload_len);
- rc = apr_send_pkt(ac->apr, (uint32_t *) asm_params);
- if (rc < 0) {
- pr_err("%s: stream event cmd apr pkt failed\n", __func__);
- rc = -EINVAL;
- goto fail_send_param;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state_pp) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout for stream event cmd resp\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_send_param;
- }
- if (atomic_read(&ac->cmd_state_pp) > 0) {
- pr_err("%s: DSP returned error[%s] for stream event cmd\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state_pp)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state_pp));
- goto fail_send_param;
- }
- rc = 0;
- fail_send_param:
- mutex_unlock(&session[session_id].mutex_lock_per_session);
- kfree(asm_params);
- done:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_send_stream_cmd);
- /**
- * q6asm_audio_client_alloc -
- * Alloc audio client for ASM
- *
- * @cb: callback fn
- * @priv: private data
- *
- * Returns ac pointer on success or NULL on failure
- */
- struct audio_client *q6asm_audio_client_alloc(app_cb cb, void *priv)
- {
- struct audio_client *ac;
- int n;
- int lcnt = 0;
- int rc = 0;
- ac = kzalloc(sizeof(struct audio_client), GFP_KERNEL);
- if (!ac)
- return NULL;
- mutex_lock(&session_lock);
- n = q6asm_session_alloc(ac);
- if (n <= 0) {
- pr_err("%s: ASM Session alloc fail n=%d\n", __func__, n);
- mutex_unlock(&session_lock);
- kfree(ac);
- goto fail_session;
- }
- ac->session = n;
- ac->cb = cb;
- ac->path_delay = UINT_MAX;
- ac->priv = priv;
- ac->io_mode = SYNC_IO_MODE;
- ac->perf_mode = LEGACY_PCM_MODE;
- ac->fptr_cache_ops = NULL;
- /* DSP expects stream id from 1 */
- ac->stream_id = 1;
- ac->apr = apr_register("ADSP", "ASM",
- (apr_fn)q6asm_callback,
- ((ac->session) << 8 | 0x0001),
- ac);
- if (ac->apr == NULL) {
- pr_err("%s: Registration with APR failed\n", __func__);
- mutex_unlock(&session_lock);
- goto fail_apr1;
- }
- ac->apr2 = apr_register("ADSP", "ASM",
- (apr_fn)q6asm_callback,
- ((ac->session) << 8 | 0x0002),
- ac);
- if (ac->apr2 == NULL) {
- pr_err("%s: Registration with APR-2 failed\n", __func__);
- mutex_unlock(&session_lock);
- goto fail_apr2;
- }
- rtac_set_asm_handle(n, ac->apr);
- pr_debug("%s: Registering the common port with APR\n", __func__);
- ac->mmap_apr = q6asm_mmap_apr_reg();
- if (ac->mmap_apr == NULL) {
- mutex_unlock(&session_lock);
- goto fail_mmap;
- }
- init_waitqueue_head(&ac->cmd_wait);
- init_waitqueue_head(&ac->time_wait);
- init_waitqueue_head(&ac->mem_wait);
- atomic_set(&ac->time_flag, 1);
- atomic_set(&ac->reset, 0);
- INIT_LIST_HEAD(&ac->port[0].mem_map_handle);
- INIT_LIST_HEAD(&ac->port[1].mem_map_handle);
- pr_debug("%s: mem_map_handle list init'ed\n", __func__);
- mutex_init(&ac->cmd_lock);
- for (lcnt = 0; lcnt <= OUT; lcnt++) {
- mutex_init(&ac->port[lcnt].lock);
- spin_lock_init(&ac->port[lcnt].dsp_lock);
- }
- atomic_set(&ac->cmd_state, 0);
- atomic_set(&ac->cmd_state_pp, 0);
- atomic_set(&ac->mem_state, 0);
- rc = send_asm_custom_topology(ac);
- if (rc < 0) {
- mutex_unlock(&session_lock);
- goto fail_mmap;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- mutex_unlock(&session_lock);
- return ac;
- fail_mmap:
- apr_deregister(ac->apr2);
- fail_apr2:
- apr_deregister(ac->apr);
- fail_apr1:
- q6asm_session_free(ac);
- fail_session:
- return NULL;
- }
- EXPORT_SYMBOL(q6asm_audio_client_alloc);
- /**
- * q6asm_get_audio_client -
- * Retrieve audio client for ASM
- *
- * @session_id: ASM session id
- *
- * Returns valid pointer on success or NULL on failure
- */
- struct audio_client *q6asm_get_audio_client(int session_id)
- {
- if (session_id == ASM_CONTROL_SESSION)
- return &common_client;
- if ((session_id <= 0) || (session_id > ASM_ACTIVE_STREAMS_ALLOWED)) {
- pr_err("%s: invalid session: %d\n", __func__, session_id);
- goto err;
- }
- if (!(session[session_id].ac)) {
- pr_err("%s: session not active: %d\n", __func__, session_id);
- goto err;
- }
- return session[session_id].ac;
- err:
- return NULL;
- }
- EXPORT_SYMBOL(q6asm_get_audio_client);
- /**
- * q6asm_audio_client_buf_alloc -
- * Allocs memory from ION for ASM
- *
- * @dir: RX or TX direction
- * @ac: Audio client handle
- * @bufsz: size of each buffer
- * @bufcnt: number of buffers to alloc
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_audio_client_buf_alloc(unsigned int dir,
- struct audio_client *ac,
- unsigned int bufsz,
- uint32_t bufcnt)
- {
- int cnt = 0;
- int rc = 0;
- struct audio_buffer *buf;
- size_t len;
- if (!(ac) || !(bufsz) || ((dir != IN) && (dir != OUT))) {
- pr_err("%s: ac %pK bufsz %d dir %d\n", __func__, ac, bufsz,
- dir);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n", __func__, ac->session,
- bufsz, bufcnt);
- if (ac->session <= 0 || ac->session > 8) {
- pr_err("%s: Session ID is invalid, session = %d\n", __func__,
- ac->session);
- goto fail;
- }
- if (ac->io_mode & SYNC_IO_MODE) {
- if (ac->port[dir].buf) {
- pr_debug("%s: buffer already allocated\n", __func__);
- return 0;
- }
- mutex_lock(&ac->cmd_lock);
- if (bufcnt > (U32_MAX/sizeof(struct audio_buffer))) {
- pr_err("%s: Buffer size overflows", __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
- GFP_KERNEL);
- if (!buf) {
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- ac->port[dir].buf = buf;
- while (cnt < bufcnt) {
- if (bufsz > 0) {
- if (!buf[cnt].data) {
- rc = msm_audio_ion_alloc(
- &buf[cnt].dma_buf,
- bufsz,
- &buf[cnt].phys,
- &len,
- &buf[cnt].data);
- if (rc) {
- pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
- __func__, rc);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[cnt].used = 1;
- buf[cnt].size = bufsz;
- buf[cnt].actual_size = bufsz;
- pr_debug("%s: data[%pK]phys[%pK][%pK]\n",
- __func__,
- buf[cnt].data,
- &buf[cnt].phys,
- &buf[cnt].phys);
- cnt++;
- }
- }
- }
- ac->port[dir].max_buf_cnt = cnt;
- mutex_unlock(&ac->cmd_lock);
- rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt, 0);
- if (rc < 0) {
- pr_err("%s: CMD Memory_map_regions failed %d for size %d\n",
- __func__, rc, bufsz);
- goto fail;
- }
- }
- return 0;
- fail:
- q6asm_audio_client_buf_free(dir, ac);
- return -EINVAL;
- }
- EXPORT_SYMBOL(q6asm_audio_client_buf_alloc);
- /**
- * q6asm_audio_client_buf_alloc_contiguous -
- * Alloc contiguous memory from ION for ASM
- *
- * @dir: RX or TX direction
- * @ac: Audio client handle
- * @bufsz: size of each buffer
- * @bufcnt: number of buffers to alloc
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_audio_client_buf_alloc_contiguous(unsigned int dir,
- struct audio_client *ac,
- unsigned int bufsz,
- unsigned int bufcnt)
- {
- int cnt = 0;
- int rc = 0;
- struct audio_buffer *buf;
- size_t len;
- int bytes_to_alloc;
- if (!(ac) || ((dir != IN) && (dir != OUT))) {
- pr_err("%s: ac %pK dir %d\n", __func__, ac, dir);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]bufsz[%d]bufcnt[%d]\n",
- __func__, ac->session,
- bufsz, bufcnt);
- if (ac->session <= 0 || ac->session > ASM_ACTIVE_STREAMS_ALLOWED) {
- pr_err("%s: Session ID is invalid, session = %d\n", __func__,
- ac->session);
- goto fail;
- }
- if (ac->port[dir].buf) {
- pr_err("%s: buffer already allocated\n", __func__);
- return 0;
- }
- mutex_lock(&ac->cmd_lock);
- buf = kzalloc(((sizeof(struct audio_buffer))*bufcnt),
- GFP_KERNEL);
- if (!buf) {
- pr_err("%s: buffer allocation failed\n", __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- ac->port[dir].buf = buf;
- /* check for integer overflow */
- if ((bufcnt > 0) && ((INT_MAX / bufcnt) < bufsz)) {
- pr_err("%s: integer overflow\n", __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- bytes_to_alloc = bufsz * bufcnt;
- /* The size to allocate should be multiple of 4K bytes */
- bytes_to_alloc = PAGE_ALIGN(bytes_to_alloc);
- rc = msm_audio_ion_alloc(&buf[0].dma_buf,
- bytes_to_alloc,
- &buf[0].phys, &len,
- &buf[0].data);
- if (rc) {
- pr_err("%s: Audio ION alloc is failed, rc = %d\n",
- __func__, rc);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[0].used = dir ^ 1;
- buf[0].size = bufsz;
- buf[0].actual_size = bufsz;
- cnt = 1;
- while (cnt < bufcnt) {
- if (bufsz > 0) {
- buf[cnt].data = buf[0].data + (cnt * bufsz);
- buf[cnt].phys = buf[0].phys + (cnt * bufsz);
- if (!buf[cnt].data) {
- pr_err("%s: Buf alloc failed\n",
- __func__);
- mutex_unlock(&ac->cmd_lock);
- goto fail;
- }
- buf[cnt].used = dir ^ 1;
- buf[cnt].size = bufsz;
- buf[cnt].actual_size = bufsz;
- pr_debug("%s: data[%pK]phys[%pK][%pK]\n",
- __func__,
- buf[cnt].data,
- &buf[cnt].phys,
- &buf[cnt].phys);
- }
- cnt++;
- }
- ac->port[dir].max_buf_cnt = cnt;
- mutex_unlock(&ac->cmd_lock);
- rc = q6asm_memory_map_regions(ac, dir, bufsz, cnt, 1);
- if (rc < 0) {
- pr_err("%s: CMD Memory_map_regions failed %d for size %d\n",
- __func__, rc, bufsz);
- goto fail;
- }
- return 0;
- fail:
- q6asm_audio_client_buf_free_contiguous(dir, ac);
- return -EINVAL;
- }
- EXPORT_SYMBOL(q6asm_audio_client_buf_alloc_contiguous);
- static int32_t q6asm_srvc_callback(struct apr_client_data *data, void *priv)
- {
- uint32_t dir = 0;
- uint32_t i = IN;
- uint32_t *payload;
- unsigned long dsp_flags = 0;
- unsigned long flags = 0;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- union asm_token_struct asm_token;
- struct audio_client *ac = NULL;
- struct audio_port_data *port;
- int session_id;
- if (!data) {
- pr_err("%s: Invalid CB\n", __func__);
- return 0;
- }
- payload = data->payload;
- if (data->opcode == RESET_EVENTS) {
- pr_debug("%s: Reset event is received: %d %d apr[%pK]\n",
- __func__,
- data->reset_event,
- data->reset_proc,
- this_mmap.apr);
- atomic_set(&this_mmap.ref_cnt, 0);
- apr_reset(this_mmap.apr);
- this_mmap.apr = NULL;
- for (; i <= OUT; i++) {
- list_for_each_safe(ptr, next,
- &common_client.port[i].mem_map_handle) {
- buf_node = list_entry(ptr,
- struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr ==
- common_client.port[i].buf->phys) {
- list_del(&buf_node->list);
- kfree(buf_node);
- }
- }
- pr_debug("%s: Clearing custom topology\n", __func__);
- }
- cal_utils_clear_cal_block_q6maps(ASM_MAX_CAL_TYPES, cal_data);
- common_client.mmap_apr = NULL;
- mutex_lock(&cal_data[ASM_CUSTOM_TOP_CAL]->lock);
- set_custom_topology = 1;
- mutex_unlock(&cal_data[ASM_CUSTOM_TOP_CAL]->lock);
- topology_map_handle = 0;
- rtac_clear_mapping(ASM_RTAC_CAL);
- return 0;
- }
- asm_token.token = data->token;
- session_id = asm_token._token.session_id;
- if ((session_id > 0 && session_id <= ASM_ACTIVE_STREAMS_ALLOWED))
- spin_lock_irqsave(&(session[session_id].session_lock), flags);
- ac = q6asm_get_audio_client(session_id);
- dir = q6asm_get_flag_from_token(&asm_token, ASM_DIRECTION_OFFSET);
- if (!ac) {
- pr_debug("%s: session[%d] already freed\n",
- __func__, session_id);
- if ((session_id > 0 &&
- session_id <= ASM_ACTIVE_STREAMS_ALLOWED))
- spin_unlock_irqrestore(
- &(session[session_id].session_lock), flags);
- return 0;
- }
- if (data->payload_size >= 2 * sizeof(uint32_t)) {
- pr_debug("%s:ptr0[0x%x]ptr1[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]sid[%d]dir[%d]\n",
- __func__, payload[0], payload[1], data->opcode,
- data->token, data->payload_size, data->src_port,
- data->dest_port, asm_token._token.session_id, dir);
- pr_debug("%s:Payload = [0x%x] status[0x%x]\n",
- __func__, payload[0], payload[1]);
- } else if (data->payload_size == sizeof(uint32_t)) {
- pr_debug("%s:ptr0[0x%x]opcode[0x%x] token[0x%x]payload_s[%d] src[%d] dest[%d]sid[%d]dir[%d]\n",
- __func__, payload[0], data->opcode,
- data->token, data->payload_size, data->src_port,
- data->dest_port, asm_token._token.session_id, dir);
- pr_debug("%s:Payload = [0x%x]\n",
- __func__, payload[0]);
- }
- if (data->opcode == APR_BASIC_RSP_RESULT) {
- switch (payload[0]) {
- case ASM_CMD_SHARED_MEM_MAP_REGIONS:
- case ASM_CMD_SHARED_MEM_UNMAP_REGIONS:
- case ASM_CMD_ADD_TOPOLOGIES:
- if (data->payload_size >= 2 * sizeof(uint32_t) && payload[1] != 0) {
- pr_err("%s: cmd = 0x%x returned error = 0x%x sid:%d\n",
- __func__, payload[0], payload[1],
- asm_token._token.session_id);
- if (payload[0] ==
- ASM_CMD_SHARED_MEM_UNMAP_REGIONS)
- atomic_set(&ac->unmap_cb_success, 0);
- atomic_set(&ac->mem_state, payload[1]);
- wake_up(&ac->mem_wait);
- } else {
- if (payload[0] ==
- ASM_CMD_SHARED_MEM_UNMAP_REGIONS)
- atomic_set(&ac->unmap_cb_success, 1);
- }
- if (atomic_cmpxchg(&ac->mem_state, -1, 0) == -1)
- wake_up(&ac->mem_wait);
- if (data->payload_size >= 2 * sizeof(uint32_t))
- dev_vdbg(ac->dev, "%s: Payload = [0x%x] status[0x%x]\n",
- __func__, payload[0], payload[1]);
- else
- dev_vdbg(ac->dev, "%s: Payload size of %d is less than expected.\n",
- __func__, data->payload_size);
- break;
- default:
- pr_debug("%s: command[0x%x] not expecting rsp\n",
- __func__, payload[0]);
- break;
- }
- if ((session_id > 0 &&
- session_id <= ASM_ACTIVE_STREAMS_ALLOWED))
- spin_unlock_irqrestore(
- &(session[session_id].session_lock), flags);
- return 0;
- }
- port = &ac->port[dir];
- switch (data->opcode) {
- case ASM_CMDRSP_SHARED_MEM_MAP_REGIONS:{
- pr_debug("%s:PL#0[0x%x] dir=0x%x s_id=0x%x\n",
- __func__, payload[0], dir, asm_token._token.session_id);
- spin_lock_irqsave(&port->dsp_lock, dsp_flags);
- if (atomic_cmpxchg(&ac->mem_state, -1, 0) == -1) {
- ac->port[dir].tmp_hdl = payload[0];
- wake_up(&ac->mem_wait);
- }
- spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
- break;
- }
- case ASM_CMD_SHARED_MEM_UNMAP_REGIONS:{
- if (data->payload_size >= 2 * sizeof(uint32_t))
- pr_debug("%s: PL#0[0x%x]PL#1 [0x%x]\n",
- __func__, payload[0], payload[1]);
- else
- pr_debug("%s: Payload size of %d is less than expected.\n",
- __func__, data->payload_size);
- spin_lock_irqsave(&port->dsp_lock, dsp_flags);
- if (atomic_cmpxchg(&ac->mem_state, -1, 0) == -1)
- wake_up(&ac->mem_wait);
- spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
- break;
- }
- default:
- if (data->payload_size >= 2 * sizeof(uint32_t))
- pr_debug("%s: command[0x%x]success [0x%x]\n",
- __func__, payload[0], payload[1]);
- else
- pr_debug("%s: Payload size of %d is less than expected.\n",
- __func__, data->payload_size);
- }
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- data->payload, ac->priv);
- if ((session_id > 0 && session_id <= ASM_ACTIVE_STREAMS_ALLOWED))
- spin_unlock_irqrestore(
- &(session[session_id].session_lock), flags);
- return 0;
- }
- static void q6asm_process_mtmx_get_param_rsp(struct audio_client *ac,
- struct asm_mtmx_strtr_get_params_cmdrsp *cmdrsp)
- {
- struct asm_session_mtmx_strtr_param_session_time_v3_t *time;
- if (cmdrsp->err_code) {
- dev_err_ratelimited(ac->dev,
- "%s: err=%x, mod_id=%x, param_id=%x\n",
- __func__, cmdrsp->err_code,
- cmdrsp->param_info.module_id,
- cmdrsp->param_info.param_id);
- return;
- }
- dev_dbg_ratelimited(ac->dev,
- "%s: mod_id=%x, param_id=%x\n", __func__,
- cmdrsp->param_info.module_id,
- cmdrsp->param_info.param_id);
- switch (cmdrsp->param_info.module_id) {
- case ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC:
- switch (cmdrsp->param_info.param_id) {
- case ASM_SESSION_MTMX_STRTR_PARAM_SESSION_TIME_V3:
- time = &cmdrsp->param_data.session_time;
- dev_vdbg(ac->dev, "%s: GET_TIME_V3, time_lsw=%x, time_msw=%x, abs l %x, m %x\n",
- __func__, time->session_time_lsw,
- time->session_time_msw,
- time->absolute_time_lsw,
- time->absolute_time_msw);
- ac->dsp_ts.abs_time_stamp = (uint64_t)(((uint64_t)
- time->absolute_time_msw << 32) |
- time->absolute_time_lsw);
- ac->dsp_ts.time_stamp = (uint64_t)(((uint64_t)
- time->session_time_msw << 32) |
- time->session_time_lsw);
- ac->dsp_ts.last_time_stamp = (uint64_t)(((uint64_t)
- time->time_stamp_msw << 32) |
- time->time_stamp_lsw);
- if (time->flags &
- ASM_SESSION_MTMX_STRTR_PARAM_STIME_TSTMP_FLG_BMASK)
- dev_warn_ratelimited(ac->dev,
- "%s: recv inval tstmp\n",
- __func__);
- if (atomic_cmpxchg(&ac->time_flag, 1, 0))
- wake_up(&ac->time_wait);
- break;
- default:
- dev_err(ac->dev, "%s: unexpected param_id %x\n",
- __func__, cmdrsp->param_info.param_id);
- break;
- }
- break;
- default:
- dev_err(ac->dev, "%s: unexpected mod_id %x\n", __func__,
- cmdrsp->param_info.module_id);
- break;
- }
- }
- static int32_t q6asm_callback(struct apr_client_data *data, void *priv)
- {
- int i = 0;
- struct audio_client *ac = (struct audio_client *)priv;
- unsigned long dsp_flags = 0;
- uint32_t *payload;
- uint32_t wakeup_flag = 1;
- int32_t ret = 0;
- union asm_token_struct asm_token;
- uint8_t buf_index;
- struct msm_adsp_event_data *pp_event_package = NULL;
- uint32_t payload_size = 0;
- unsigned long flags = 0;
- int session_id;
- if (ac == NULL) {
- pr_err("%s: ac NULL\n", __func__);
- return -EINVAL;
- }
- if (data == NULL) {
- pr_err("%s: data NULL\n", __func__);
- return -EINVAL;
- }
- session_id = q6asm_get_session_id_from_audio_client(ac);
- if (session_id <= 0 || session_id > ASM_ACTIVE_STREAMS_ALLOWED) {
- pr_err("%s: Session ID is invalid, session = %d\n", __func__,
- session_id);
- return -EINVAL;
- }
- spin_lock_irqsave(&(session[session_id].session_lock), flags);
- if (!q6asm_is_valid_audio_client(ac)) {
- pr_err("%s: audio client pointer is invalid, ac = %pK\n",
- __func__, ac);
- spin_unlock_irqrestore(
- &(session[session_id].session_lock), flags);
- return -EINVAL;
- }
- payload = data->payload;
- asm_token.token = data->token;
- if (q6asm_get_flag_from_token(&asm_token, ASM_CMD_NO_WAIT_OFFSET)) {
- pr_debug("%s: No wait command opcode[0x%x] cmd_opcode:%x\n",
- __func__, data->opcode, payload ? payload[0] : 0);
- wakeup_flag = 0;
- }
- if (data->opcode == RESET_EVENTS) {
- atomic_set(&ac->reset, 1);
- if (ac->apr == NULL) {
- ac->apr = ac->apr2;
- ac->apr2 = NULL;
- }
- pr_debug("%s: Reset event is received: %d %d apr[%pK]\n",
- __func__,
- data->reset_event, data->reset_proc, ac->apr);
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- (uint32_t *)data->payload, ac->priv);
- apr_reset(ac->apr);
- ac->apr = NULL;
- atomic_set(&ac->time_flag, 0);
- atomic_set(&ac->cmd_state, 0);
- atomic_set(&ac->mem_state, 0);
- atomic_set(&ac->cmd_state_pp, 0);
- wake_up(&ac->time_wait);
- wake_up(&ac->cmd_wait);
- wake_up(&ac->mem_wait);
- spin_unlock_irqrestore(
- &(session[session_id].session_lock), flags);
- return 0;
- }
- dev_vdbg(ac->dev, "%s: session[%d]opcode[0x%x] token[0x%x]payload_size[%d] src[%d] dest[%d]\n",
- __func__,
- ac->session, data->opcode,
- data->token, data->payload_size, data->src_port,
- data->dest_port);
- if ((data->opcode != ASM_DATA_EVENT_RENDERED_EOS) &&
- (data->opcode != ASM_DATA_EVENT_EOS) &&
- (data->opcode != ASM_SESSION_EVENTX_OVERFLOW) &&
- (data->opcode != ASM_SESSION_EVENT_RX_UNDERFLOW)) {
- if (payload == NULL) {
- pr_err("%s: payload is null\n", __func__);
- spin_unlock_irqrestore(
- &(session[session_id].session_lock), flags);
- return -EINVAL;
- }
- if(data->payload_size >= 2 * sizeof(uint32_t))
- dev_vdbg(ac->dev, "%s: Payload = [0x%x] status[0x%x] opcode 0x%x\n",
- __func__, payload[0], payload[1], data->opcode);
- else
- dev_vdbg(ac->dev, "%s: Payload size of %d is less than expected.\n",
- __func__, data->payload_size);
- }
- if (data->opcode == APR_BASIC_RSP_RESULT) {
- switch (payload[0]) {
- case ASM_STREAM_CMD_SET_PP_PARAMS_V2:
- case ASM_STREAM_CMD_SET_PP_PARAMS_V3:
- if (rtac_make_asm_callback(ac->session, payload,
- data->payload_size))
- break;
- case ASM_SESSION_CMD_PAUSE:
- case ASM_SESSION_CMD_SUSPEND:
- case ASM_DATA_CMD_EOS:
- case ASM_STREAM_CMD_CLOSE:
- case ASM_STREAM_CMD_FLUSH:
- case ASM_SESSION_CMD_RUN_V2:
- case ASM_SESSION_CMD_REGISTER_FORX_OVERFLOW_EVENTS:
- case ASM_STREAM_CMD_FLUSH_READBUFS:
- pr_debug("%s: session %d opcode 0x%x token 0x%x Payload = [0x%x] src %d dest %d\n",
- __func__, ac->session, data->opcode, data->token,
- payload[0], data->src_port, data->dest_port);
- ret = q6asm_is_valid_session(data, priv);
- if (ret != 0) {
- pr_err("%s: session invalid %d\n", __func__, ret);
- spin_unlock_irqrestore(
- &(session[session_id].session_lock), flags);
- return ret;
- }
- case ASM_SESSION_CMD_SET_MTMX_STRTR_PARAMS_V2:
- case ASM_STREAM_CMD_OPEN_READ_V3:
- case ASM_STREAM_CMD_OPEN_WRITE_V3:
- case ASM_STREAM_CMD_OPEN_PULL_MODE_WRITE:
- case ASM_STREAM_CMD_OPEN_PUSH_MODE_READ:
- case ASM_STREAM_CMD_OPEN_READWRITE_V2:
- case ASM_STREAM_CMD_OPEN_LOOPBACK_V2:
- case ASM_STREAM_CMD_OPEN_TRANSCODE_LOOPBACK:
- case ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2:
- case ASM_DATA_CMD_IEC_60958_MEDIA_FMT:
- case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
- case ASM_STREAM_CMD_SET_ENCDEC_PARAM_V2:
- case ASM_STREAM_CMD_REGISTER_ENCDEC_EVENTS:
- case ASM_STREAM_CMD_REGISTER_IEC_61937_FMT_UPDATE:
- case ASM_DATA_CMD_REMOVE_INITIAL_SILENCE:
- case ASM_DATA_CMD_REMOVE_TRAILING_SILENCE:
- case ASM_SESSION_CMD_REGISTER_FOR_RX_UNDERFLOW_EVENTS:
- case ASM_STREAM_CMD_OPEN_READ_COMPRESSED:
- case ASM_STREAM_CMD_OPEN_WRITE_COMPRESSED:
- if (data->payload_size >= 2 * sizeof(uint32_t)) {
- pr_debug("%s: session %d opcode 0x%x token 0x%x Payload = [0x%x] stat 0x%x src %d dest %d\n",
- __func__, ac->session,
- data->opcode, data->token,
- payload[0], payload[1],
- data->src_port, data->dest_port);
- if (payload[1] != 0) {
- pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
- __func__, payload[0], payload[1]);
- if (wakeup_flag) {
- if ((is_adsp_reg_event(payload[0]) >=
- 0) ||
- (payload[0] ==
- ASM_STREAM_CMD_SET_PP_PARAMS_V2) ||
- (payload[0] ==
- ASM_STREAM_CMD_SET_PP_PARAMS_V3))
- atomic_set(&ac->cmd_state_pp,
- payload[1]);
- else
- atomic_set(&ac->cmd_state,
- payload[1]);
- wake_up(&ac->cmd_wait);
- }
- spin_unlock_irqrestore(
- &(session[session_id].session_lock),
- flags);
- return 0;
- }
- } else {
- pr_err("%s: payload size of %x is less than expected.\n",
- __func__, data->payload_size);
- }
- if ((is_adsp_reg_event(payload[0]) >= 0) ||
- (payload[0] == ASM_STREAM_CMD_SET_PP_PARAMS_V2) ||
- (payload[0] == ASM_STREAM_CMD_SET_PP_PARAMS_V3)) {
- if (atomic_read(&ac->cmd_state_pp) &&
- wakeup_flag) {
- atomic_set(&ac->cmd_state_pp, 0);
- wake_up(&ac->cmd_wait);
- }
- } else {
- if (atomic_read(&ac->cmd_state) &&
- wakeup_flag) {
- atomic_set(&ac->cmd_state, 0);
- wake_up(&ac->cmd_wait);
- }
- }
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- (uint32_t *)data->payload, ac->priv);
- break;
- case ASM_CMD_ADD_TOPOLOGIES:
- if (data->payload_size >= 2 * sizeof(uint32_t)) {
- pr_debug("%s:Payload = [0x%x]stat[0x%x]\n",
- __func__, payload[0], payload[1]);
- if (payload[1] != 0) {
- pr_err("%s: cmd = 0x%x returned error = 0x%x\n",
- __func__, payload[0], payload[1]);
- if (wakeup_flag) {
- atomic_set(&ac->mem_state, payload[1]);
- wake_up(&ac->mem_wait);
- }
- spin_unlock_irqrestore(
- &(session[session_id].session_lock),
- flags);
- return 0;
- }
- } else {
- pr_err("%s: payload size of %x is less than expected.\n",
- __func__, data->payload_size);
- }
- if (atomic_read(&ac->mem_state) && wakeup_flag) {
- atomic_set(&ac->mem_state, 0);
- wake_up(&ac->mem_wait);
- }
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- (uint32_t *)data->payload, ac->priv);
- break;
- case ASM_DATA_EVENT_WATERMARK: {
- if (data->payload_size >= 2 * sizeof(uint32_t))
- pr_debug("%s: Watermark opcode[0x%x] status[0x%x]",
- __func__, payload[0], payload[1]);
- else
- pr_err("%s: payload size of %x is less than expected.\n",
- __func__, data->payload_size);
- break;
- }
- case ASM_STREAM_CMD_GET_PP_PARAMS_V2:
- case ASM_STREAM_CMD_GET_PP_PARAMS_V3:
- pr_debug("%s: ASM_STREAM_CMD_GET_PP_PARAMS session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session, data->opcode,
- data->token, data->src_port, data->dest_port);
- /* Should only come here if there is an APR */
- /* error or malformed APR packet. Otherwise */
- /* response will be returned as */
- /* ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2 */
- if (data->payload_size >= 2 * sizeof(uint32_t)) {
- if (payload[1] != 0) {
- pr_err("%s: ASM get param error = %d, resuming\n",
- __func__, payload[1]);
- rtac_make_asm_callback(ac->session, payload,
- data->payload_size);
- }
- } else {
- pr_err("%s: payload size of %x is less than expected.\n",
- __func__, data->payload_size);
- }
- break;
- case ASM_STREAM_CMD_REGISTER_PP_EVENTS:
- pr_debug("%s: ASM_STREAM_CMD_REGISTER_PP_EVENTS session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session,
- data->opcode, data->token,
- data->src_port, data->dest_port);
- if (data->payload_size >= 2 * sizeof(uint32_t)) {
- if (payload[1] != 0)
- pr_err("%s: ASM get param error = %d, resuming\n",
- __func__, payload[1]);
- atomic_set(&ac->cmd_state_pp, payload[1]);
- wake_up(&ac->cmd_wait);
- } else {
- pr_err("%s: payload size of %x is less than expected.\n",
- __func__, data->payload_size);
- }
- break;
- default:
- pr_debug("%s: command[0x%x] not expecting rsp\n",
- __func__, payload[0]);
- break;
- }
- spin_unlock_irqrestore(
- &(session[session_id].session_lock), flags);
- return 0;
- }
- switch (data->opcode) {
- case ASM_DATA_EVENT_WRITE_DONE_V2:{
- struct audio_port_data *port = &ac->port[IN];
- if (data->payload_size >= 2 * sizeof(uint32_t))
- dev_vdbg(ac->dev, "%s: Rxed opcode[0x%x] status[0x%x] token[%d]",
- __func__, payload[0], payload[1],
- data->token);
- else
- dev_err(ac->dev, "%s: payload size of %x is less than expected.\n",
- __func__, data->payload_size);
- if (ac->io_mode & SYNC_IO_MODE) {
- if (port->buf == NULL) {
- pr_err("%s: Unexpected Write Done\n",
- __func__);
- spin_unlock_irqrestore(
- &(session[session_id].session_lock),
- flags);
- return -EINVAL;
- }
- spin_lock_irqsave(&port->dsp_lock, dsp_flags);
- buf_index = asm_token._token.buf_index;
- if (buf_index < 0 || buf_index >= port->max_buf_cnt) {
- pr_debug("%s: Invalid buffer index %u\n",
- __func__, buf_index);
- spin_unlock_irqrestore(&port->dsp_lock,
- dsp_flags);
- spin_unlock_irqrestore(
- &(session[session_id].session_lock),
- flags);
- return -EINVAL;
- }
- if ( data->payload_size >= 2 * sizeof(uint32_t) &&
- (lower_32_bits(port->buf[buf_index].phys) !=
- payload[0] ||
- msm_audio_populate_upper_32_bits(
- port->buf[buf_index].phys) != payload[1])) {
- pr_debug("%s: Expected addr %pK\n",
- __func__, &port->buf[buf_index].phys);
- pr_err("%s: rxedl[0x%x] rxedu [0x%x]\n",
- __func__, payload[0], payload[1]);
- spin_unlock_irqrestore(&port->dsp_lock,
- dsp_flags);
- spin_unlock_irqrestore(
- &(session[session_id].session_lock),
- flags);
- return -EINVAL;
- }
- port->buf[buf_index].used = 1;
- spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
- config_debug_fs_write_cb();
- for (i = 0; i < port->max_buf_cnt; i++)
- dev_vdbg(ac->dev, "%s %d\n",
- __func__, port->buf[i].used);
- }
- break;
- }
- case ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2:
- case ASM_STREAM_CMDRSP_GET_PP_PARAMS_V3:
- pr_debug("%s: ASM_STREAM_CMDRSP_GET_PP_PARAMS session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session, data->opcode, data->token,
- data->src_port, data->dest_port);
- if (payload[0] != 0) {
- pr_err("%s: ASM_STREAM_CMDRSP_GET_PP_PARAMS returned error = 0x%x\n",
- __func__, payload[0]);
- } else if (generic_get_data) {
- generic_get_data->valid = 1;
- if (generic_get_data->is_inband) {
- if (data->payload_size >= 4 * sizeof(uint32_t))
- pr_debug("%s: payload[1] = 0x%x, payload[2]=0x%x, payload[3]=0x%x\n",
- __func__, payload[1], payload[2], payload[3]);
- else
- pr_err("%s: payload size of %x is less than expected.\n",
- __func__,
- data->payload_size);
- if (data->payload_size >= (4 + (payload[3]>>2)) * sizeof(uint32_t)) {
- generic_get_data->size_in_ints = payload[3]>>2;
- for (i = 0; i < payload[3]>>2; i++) {
- generic_get_data->ints[i] =
- payload[4+i];
- pr_debug("%s: ASM callback val %i = %i\n",
- __func__, i, payload[4+i]);
- }
- } else {
- pr_err("%s: payload size of %x is less than expected.\n",
- __func__, data->payload_size);
- }
- pr_debug("%s: callback size in ints = %i\n",
- __func__,
- generic_get_data->size_in_ints);
- }
- if (atomic_read(&ac->cmd_state) && wakeup_flag) {
- atomic_set(&ac->cmd_state, 0);
- wake_up(&ac->cmd_wait);
- }
- break;
- }
- rtac_make_asm_callback(ac->session, payload,
- data->payload_size);
- break;
- case ASM_DATA_EVENT_READ_DONE_V2:{
- struct audio_port_data *port = &ac->port[OUT];
- config_debug_fs_read_cb();
- dev_vdbg(ac->dev, "%s: ReadDone: status=%d buff_add=0x%x act_size=%d offset=%d\n",
- __func__, payload[READDONE_IDX_STATUS],
- payload[READDONE_IDX_BUFADD_LSW],
- payload[READDONE_IDX_SIZE],
- payload[READDONE_IDX_OFFSET]);
- dev_vdbg(ac->dev, "%s: ReadDone:msw_ts=%d lsw_ts=%d memmap_hdl=0x%x flags=%d id=%d num=%d\n",
- __func__, payload[READDONE_IDX_MSW_TS],
- payload[READDONE_IDX_LSW_TS],
- payload[READDONE_IDX_MEMMAP_HDL],
- payload[READDONE_IDX_FLAGS],
- payload[READDONE_IDX_SEQ_ID],
- payload[READDONE_IDX_NUMFRAMES]);
- if (ac->io_mode & SYNC_IO_MODE) {
- if (port->buf == NULL) {
- pr_err("%s: Unexpected Read Done\n", __func__);
- spin_unlock_irqrestore(
- &(session[session_id].session_lock),
- flags);
- return -EINVAL;
- }
- spin_lock_irqsave(&port->dsp_lock, dsp_flags);
- buf_index = asm_token._token.buf_index;
- if (buf_index < 0 || buf_index >= port->max_buf_cnt) {
- pr_debug("%s: Invalid buffer index %u\n",
- __func__, buf_index);
- spin_unlock_irqrestore(&port->dsp_lock,
- dsp_flags);
- spin_unlock_irqrestore(
- &(session[session_id].session_lock),
- flags);
- return -EINVAL;
- }
- port->buf[buf_index].used = 0;
- if (lower_32_bits(port->buf[buf_index].phys) !=
- payload[READDONE_IDX_BUFADD_LSW] ||
- msm_audio_populate_upper_32_bits(
- port->buf[buf_index].phys) !=
- payload[READDONE_IDX_BUFADD_MSW]) {
- dev_vdbg(ac->dev, "%s: Expected addr %pK\n",
- __func__, &port->buf[buf_index].phys);
- pr_err("%s: rxedl[0x%x] rxedu[0x%x]\n",
- __func__,
- payload[READDONE_IDX_BUFADD_LSW],
- payload[READDONE_IDX_BUFADD_MSW]);
- spin_unlock_irqrestore(&port->dsp_lock,
- dsp_flags);
- break;
- }
- port->buf[buf_index].actual_size =
- payload[READDONE_IDX_SIZE];
- spin_unlock_irqrestore(&port->dsp_lock, dsp_flags);
- }
- break;
- }
- case ASM_DATA_EVENT_EOS:
- case ASM_DATA_EVENT_RENDERED_EOS:
- pr_debug("%s: EOS ACK received: rxed session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session,
- data->opcode, data->token,
- data->src_port, data->dest_port);
- break;
- case ASM_SESSION_EVENTX_OVERFLOW:
- pr_debug("%s: ASM_SESSION_EVENTX_OVERFLOW session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session,
- data->opcode, data->token,
- data->src_port, data->dest_port);
- break;
- case ASM_SESSION_EVENT_RX_UNDERFLOW:
- pr_debug("%s: ASM_SESSION_EVENT_RX_UNDERFLOW session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session,
- data->opcode, data->token,
- data->src_port, data->dest_port);
- break;
- case ASM_SESSION_CMDRSP_GET_SESSIONTIME_V3:
- if (data->payload_size >= 3 * sizeof(uint32_t)) {
- dev_vdbg(ac->dev, "%s: ASM_SESSION_CMDRSP_GET_SESSIONTIME_V3, payload[0] = %d, payload[1] = %d, payload[2] = %d\n",
- __func__,
- payload[0], payload[1], payload[2]);
- ac->dsp_ts.time_stamp =
- (uint64_t)(((uint64_t)payload[2] << 32) |
- payload[1]);
- } else {
- dev_err(ac->dev, "%s: payload size of %x is less than expected.n",
- __func__, data->payload_size);
- }
- if (atomic_cmpxchg(&ac->time_flag, 1, 0))
- wake_up(&ac->time_wait);
- break;
- case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY:
- case ASM_DATA_EVENT_ENC_SR_CM_CHANGE_NOTIFY:
- pr_debug("%s: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY session %d opcode 0x%x token 0x%x src %d dest %d\n",
- __func__, ac->session,
- data->opcode, data->token,
- data->src_port, data->dest_port);
- if (data->payload_size >= 4 * sizeof(uint32_t))
- 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]);
- else
- pr_debug("%s: payload size of %x is less than expected.\n",
- __func__, data->payload_size);
- break;
- case ASM_SESSION_CMDRSP_GET_MTMX_STRTR_PARAMS_V2:
- q6asm_process_mtmx_get_param_rsp(ac, (void *) payload);
- break;
- case ASM_STREAM_PP_EVENT:
- case ASM_STREAM_CMD_ENCDEC_EVENTS:
- case ASM_IEC_61937_MEDIA_FMT_EVENT:
- if (data->payload_size >= 2 * sizeof(uint32_t))
- pr_debug("%s: ASM_STREAM_EVENT payload[0][0x%x] payload[1][0x%x]",
- __func__, payload[0], payload[1]);
- else if (data->payload_size >= sizeof(uint32_t))
- pr_debug("%s: ASM_STREAM_EVENT payload[0][0x%x]",
- __func__, payload[0]);
- else
- pr_debug("%s: payload size of %x is less than expected.\n",
- __func__, data->payload_size);
- i = is_adsp_raise_event(data->opcode);
- if (i < 0) {
- spin_unlock_irqrestore(
- &(session[session_id].session_lock), flags);
- return 0;
- }
- /* repack payload for asm_stream_pp_event
- * package is composed of event type + size + actual payload
- */
- payload_size = data->payload_size;
- if (payload_size > UINT_MAX - sizeof(struct msm_adsp_event_data)) {
- pr_err("%s: payload size = %d exceeds limit.\n",
- __func__, payload_size);
- spin_unlock(&(session[session_id].session_lock));
- return -EINVAL;
- }
- pp_event_package = kzalloc(payload_size
- + sizeof(struct msm_adsp_event_data),
- GFP_ATOMIC);
- if (!pp_event_package) {
- spin_unlock_irqrestore(
- &(session[session_id].session_lock), flags);
- return -ENOMEM;
- }
- pp_event_package->event_type = i;
- pp_event_package->payload_len = payload_size;
- memcpy((void *)pp_event_package->payload,
- data->payload, payload_size);
- if ((data->opcode == ASM_IEC_61937_MEDIA_FMT_EVENT) &&
- (payload_size == 4)) {
- switch (payload[0]) {
- case ASM_MEDIA_FMT_AC3:
- ((uint32_t *)pp_event_package->payload)[0] =
- SND_AUDIOCODEC_AC3;
- break;
- case ASM_MEDIA_FMT_EAC3:
- ((uint32_t *)pp_event_package->payload)[0] =
- SND_AUDIOCODEC_EAC3;
- break;
- case ASM_MEDIA_FMT_DTS:
- ((uint32_t *)pp_event_package->payload)[0] =
- SND_AUDIOCODEC_DTS;
- break;
- case ASM_MEDIA_FMT_TRUEHD:
- ((uint32_t *)pp_event_package->payload)[0] =
- SND_AUDIOCODEC_TRUEHD;
- break;
- case ASM_MEDIA_FMT_AAC_V2:
- ((uint32_t *)pp_event_package->payload)[0] =
- SND_AUDIOCODEC_AAC;
- break;
- default:
- pr_debug("%s: Event with unknown media_fmt 0x%x\n",
- __func__, payload[0]);
- }
- }
- ac->cb(data->opcode, data->token,
- (void *)pp_event_package, ac->priv);
- kfree(pp_event_package);
- spin_unlock_irqrestore(
- &(session[session_id].session_lock), flags);
- return 0;
- case ASM_SESSION_CMDRSP_ADJUST_SESSION_CLOCK_V2:
- if (data->payload_size >= 3 * sizeof(uint32_t))
- pr_debug("%s: ASM_SESSION_CMDRSP_ADJUST_SESSION_CLOCK_V2 sesion %d status 0x%x msw %u lsw %u\n",
- __func__, ac->session, payload[0], payload[2],
- payload[1]);
- else
- pr_err("%s: payload size of %x is less than expected.\n",
- __func__, data->payload_size);
- wake_up(&ac->cmd_wait);
- break;
- case ASM_SESSION_CMDRSP_GET_PATH_DELAY_V2:
- if (data->payload_size >= 3 * sizeof(uint32_t))
- pr_debug("%s: ASM_SESSION_CMDRSP_GET_PATH_DELAY_V2 session %d status 0x%x msw %u lsw %u\n",
- __func__, ac->session, payload[0], payload[2],
- payload[1]);
- else
- pr_err("%s: payload size of %x is less than expected.\n",
- __func__, data->payload_size);
- if (payload[0] == 0 && data->payload_size >= 2 * sizeof(uint32_t)) {
- atomic_set(&ac->cmd_state, 0);
- /* ignore msw, as a delay that large shouldn't happen */
- ac->path_delay = payload[1];
- } else {
- atomic_set(&ac->cmd_state, payload[0]);
- ac->path_delay = UINT_MAX;
- }
- wake_up(&ac->cmd_wait);
- break;
- }
- if (ac->cb)
- ac->cb(data->opcode, data->token,
- data->payload, ac->priv);
- spin_unlock_irqrestore(
- &(session[session_id].session_lock), flags);
- return 0;
- }
- /**
- * q6asm_is_cpu_buf_avail -
- * retrieve next CPU buf avail
- *
- * @dir: RX or TX direction
- * @ac: Audio client handle
- * @size: size pointer to be updated with size of buffer
- * @index: index pointer to be updated with
- * CPU buffer index available
- *
- * Returns buffer pointer on success or NULL on failure
- */
- 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))) {
- pr_err("%s: ac %pK dir %d\n", __func__, ac, dir);
- 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_err("%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;
- dev_vdbg(ac->dev, "%s: session[%d]index[%d] data[%pK]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 = q6asm_get_next_buf(ac, port->cpu_buf,
- port->max_buf_cnt);
- mutex_unlock(&port->lock);
- return data;
- }
- return NULL;
- }
- EXPORT_SYMBOL(q6asm_is_cpu_buf_avail);
- /**
- * q6asm_cpu_buf_release -
- * releases cpu buffer for ASM
- *
- * @dir: RX or TX direction
- * @ac: Audio client handle
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_cpu_buf_release(int dir, struct audio_client *ac)
- {
- struct audio_port_data *port;
- int ret = 0;
- int idx;
- if (!ac || ((dir != IN) && (dir != OUT))) {
- pr_err("%s: ac %pK dir %d\n", __func__, ac, dir);
- ret = -EINVAL;
- goto exit;
- }
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[dir];
- mutex_lock(&port->lock);
- idx = port->cpu_buf;
- if (port->cpu_buf == 0) {
- port->cpu_buf = port->max_buf_cnt - 1;
- } else if (port->cpu_buf < port->max_buf_cnt) {
- port->cpu_buf = port->cpu_buf - 1;
- } else {
- pr_err("%s: buffer index(%d) out of range\n",
- __func__, port->cpu_buf);
- ret = -EINVAL;
- mutex_unlock(&port->lock);
- goto exit;
- }
- port->buf[port->cpu_buf].used = dir ^ 1;
- mutex_unlock(&port->lock);
- }
- exit:
- return ret;
- }
- EXPORT_SYMBOL(q6asm_cpu_buf_release);
- /**
- * q6asm_is_cpu_buf_avail_nolock -
- * retrieve next CPU buf avail without lock acquire
- *
- * @dir: RX or TX direction
- * @ac: Audio client handle
- * @size: size pointer to be updated with size of buffer
- * @index: index pointer to be updated with
- * CPU buffer index available
- *
- * Returns buffer pointer on success or NULL on failure
- */
- 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))) {
- pr_err("%s: ac %pK dir %d\n", __func__, ac, dir);
- return NULL;
- }
- port = &ac->port[dir];
- idx = port->cpu_buf;
- if (port->buf == NULL) {
- pr_err("%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_err("%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;
- dev_vdbg(ac->dev, "%s: session[%d]index[%d] data[%pK]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 = q6asm_get_next_buf(ac, port->cpu_buf,
- port->max_buf_cnt);
- return data;
- }
- EXPORT_SYMBOL(q6asm_is_cpu_buf_avail_nolock);
- 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)) {
- pr_err("%s: ac %pK dir %d\n", __func__, ac, dir);
- 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("%s: Next buf idx[0x%x] not available, dir[%d]\n",
- __func__, idx, dir);
- mutex_unlock(&port->lock);
- return ret;
- }
- dev_vdbg(ac->dev, "%s: session[%d]dsp_buf=%d cpu_buf=%d\n",
- __func__,
- ac->session, port->dsp_buf, port->cpu_buf);
- ret = ((port->dsp_buf != port->cpu_buf) ? 0 : -1);
- mutex_unlock(&port->lock);
- }
- return ret;
- }
- static void __q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg, uint32_t stream_id)
- {
- unsigned long flags = 0;
- dev_vdbg(ac->dev, "%s: pkt_size=%d cmd_flg=%d session=%d stream_id=%d\n",
- __func__, pkt_size, cmd_flg, ac->session, stream_id);
- mutex_lock(&ac->cmd_lock);
- spin_lock_irqsave(&(session[ac->session].session_lock), flags);
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL", __func__);
- spin_unlock_irqrestore(
- &(session[ac->session].session_lock), flags);
- mutex_unlock(&ac->cmd_lock);
- return;
- }
- hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
- APR_HDR_LEN(sizeof(struct apr_hdr)),
- APR_PKT_VER);
- hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
- hdr->src_domain = APR_DOMAIN_APPS;
- hdr->dest_svc = APR_SVC_ASM;
- hdr->dest_domain = APR_DOMAIN_ADSP;
- hdr->src_port = ((ac->session << 8) & 0xFF00) | (stream_id);
- hdr->dest_port = ((ac->session << 8) & 0xFF00) | (stream_id);
- if (cmd_flg)
- q6asm_update_token(&hdr->token,
- ac->session,
- 0, /* Stream ID is NA */
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- hdr->pkt_size = pkt_size;
- spin_unlock_irqrestore(
- &(session[ac->session].session_lock), flags);
- mutex_unlock(&ac->cmd_lock);
- }
- static void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg)
- {
- __q6asm_add_hdr(ac, hdr, pkt_size, cmd_flg, ac->stream_id);
- }
- static void q6asm_stream_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg, int32_t stream_id)
- {
- __q6asm_add_hdr(ac, hdr, pkt_size, cmd_flg, stream_id);
- }
- static void __q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg,
- uint32_t stream_id, u8 no_wait_flag)
- {
- dev_vdbg(ac->dev, "%s: pkt_size = %d, cmd_flg = %d, session = %d stream_id=%d\n",
- __func__, pkt_size, cmd_flg, ac->session, stream_id);
- hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
- APR_HDR_LEN(sizeof(struct apr_hdr)),
- APR_PKT_VER);
- if (ac->apr == NULL) {
- pr_err("%s: AC APR is NULL", __func__);
- return;
- }
- hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
- hdr->src_domain = APR_DOMAIN_APPS;
- hdr->dest_svc = APR_SVC_ASM;
- hdr->dest_domain = APR_DOMAIN_ADSP;
- hdr->src_port = ((ac->session << 8) & 0xFF00) | (stream_id);
- hdr->dest_port = ((ac->session << 8) & 0xFF00) | (stream_id);
- if (cmd_flg) {
- q6asm_update_token(&hdr->token,
- ac->session,
- 0, /* Stream ID is NA */
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- no_wait_flag);
- }
- hdr->pkt_size = pkt_size;
- }
- static void q6asm_add_hdr_async(struct audio_client *ac, struct apr_hdr *hdr,
- uint32_t pkt_size, uint32_t cmd_flg)
- {
- __q6asm_add_hdr_async(ac, hdr, pkt_size, cmd_flg,
- ac->stream_id, WAIT_CMD);
- }
- static void q6asm_stream_add_hdr_async(struct audio_client *ac,
- struct apr_hdr *hdr, uint32_t pkt_size,
- uint32_t cmd_flg, int32_t stream_id)
- {
- __q6asm_add_hdr_async(ac, hdr, pkt_size, cmd_flg,
- stream_id, NO_WAIT_CMD);
- }
- static void q6asm_add_hdr_custom_topology(struct audio_client *ac,
- struct apr_hdr *hdr,
- uint32_t pkt_size)
- {
- pr_debug("%s: pkt_size=%d session=%d\n",
- __func__, pkt_size, ac->session);
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return;
- }
- mutex_lock(&ac->cmd_lock);
- hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
- APR_HDR_LEN(sizeof(struct apr_hdr)),
- APR_PKT_VER);
- hdr->src_svc = ((struct apr_svc *)ac->apr)->id;
- hdr->src_domain = APR_DOMAIN_APPS;
- hdr->dest_svc = APR_SVC_ASM;
- hdr->dest_domain = APR_DOMAIN_ADSP;
- hdr->src_port = ((ac->session << 8) & 0xFF00) | 0x01;
- hdr->dest_port = 0;
- q6asm_update_token(&hdr->token,
- ac->session,
- 0, /* Stream ID is NA */
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- hdr->pkt_size = pkt_size;
- mutex_unlock(&ac->cmd_lock);
- }
- static void q6asm_add_mmaphdr(struct audio_client *ac, struct apr_hdr *hdr,
- u32 pkt_size, int dir)
- {
- pr_debug("%s: pkt size=%d\n",
- __func__, pkt_size);
- 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;
- q6asm_update_token(&hdr->token,
- ac->session,
- 0, /* Stream ID is NA */
- 0, /* Buffer index is NA */
- dir,
- WAIT_CMD);
- hdr->pkt_size = pkt_size;
- }
- /**
- * q6asm_set_pp_params
- * command to set ASM parameter data
- * send memory mapping header for out of band case
- * send pre-packed parameter data for in band case
- *
- * @ac: audio client handle
- * @mem_hdr: memory mapping header
- * @param_data: pre-packed parameter payload
- * @param_size: size of pre-packed parameter data
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_set_pp_params(struct audio_client *ac,
- struct mem_mapping_hdr *mem_hdr, u8 *param_data,
- u32 param_size)
- {
- struct asm_stream_cmd_set_pp_params *asm_set_param = NULL;
- int pkt_size = 0;
- int ret = 0;
- int session_id = 0;
- if (ac == NULL) {
- pr_err("%s: Audio Client is NULL\n", __func__);
- return -EINVAL;
- } else if (ac->apr == NULL) {
- pr_err("%s: APR pointer is NULL\n", __func__);
- return -EINVAL;
- }
- session_id = q6asm_get_session_id_from_audio_client(ac);
- if (!session_id)
- return -EINVAL;
- pkt_size = sizeof(struct asm_stream_cmd_set_pp_params);
- /* Add param size to packet size when sending in-band only */
- if (param_data != NULL)
- pkt_size += param_size;
- asm_set_param = kzalloc(pkt_size, GFP_KERNEL);
- if (!asm_set_param)
- return -ENOMEM;
- mutex_lock(&session[session_id].mutex_lock_per_session);
- if (!q6asm_is_valid_audio_client(ac)) {
- ret = -EINVAL;
- goto done;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- ret = -EINVAL;
- goto done;
- }
- q6asm_add_hdr_async(ac, &asm_set_param->apr_hdr, pkt_size, TRUE);
- /* With pre-packed data, only the opcode differs from V2 and V3. */
- if (q6common_is_instance_id_supported())
- asm_set_param->apr_hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V3;
- else
- asm_set_param->apr_hdr.opcode = ASM_STREAM_CMD_SET_PP_PARAMS_V2;
- asm_set_param->payload_size = param_size;
- if (mem_hdr != NULL) {
- /* Out of band case */
- asm_set_param->mem_hdr = *mem_hdr;
- } else if (param_data != NULL) {
- /*
- * In band case. Parameter data must be pre-packed with its
- * header before calling this function. Use
- * q6common_pack_pp_params to pack parameter data and header
- * correctly.
- */
- memcpy(&asm_set_param->param_data, param_data, param_size);
- } else {
- pr_err("%s: Received NULL pointers for both mem header and param data\n",
- __func__);
- ret = -EINVAL;
- goto done;
- }
- atomic_set(&ac->cmd_state_pp, -1);
- ret = apr_send_pkt(ac->apr, (uint32_t *)asm_set_param);
- if (ret < 0) {
- pr_err("%s: apr send failed rc %d\n", __func__, ret);
- ret = -EINVAL;
- goto done;
- }
- ret = wait_event_timeout(ac->cmd_wait,
- atomic_read(&ac->cmd_state_pp) >= 0,
- msecs_to_jiffies(TIMEOUT_MS));
- if (!ret) {
- pr_err("%s: timeout sending apr pkt\n", __func__);
- ret = -ETIMEDOUT;
- goto done;
- }
- if (atomic_read(&ac->cmd_state_pp) > 0) {
- pr_err("%s: DSP returned error[%s]\n", __func__,
- adsp_err_get_err_str(atomic_read(&ac->cmd_state_pp)));
- ret = adsp_err_get_lnx_err_code(atomic_read(&ac->cmd_state_pp));
- goto done;
- }
- ret = 0;
- done:
- mutex_unlock(&session[session_id].mutex_lock_per_session);
- kfree(asm_set_param);
- return ret;
- }
- EXPORT_SYMBOL(q6asm_set_pp_params);
- /**
- * q6asm_pack_and_set_pp_param_in_band
- * command to pack and set parameter data for in band case
- *
- * @ac: audio client handle
- * @param_hdr: parameter header
- * @param_data: parameter data
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_pack_and_set_pp_param_in_band(struct audio_client *ac,
- struct param_hdr_v3 param_hdr,
- u8 *param_data)
- {
- u8 *packed_data = NULL;
- u32 packed_size = sizeof(union param_hdrs) + param_hdr.param_size;
- int ret = 0;
- if (ac == NULL) {
- pr_err("%s: Audio Client is NULL\n", __func__);
- return -EINVAL;
- }
- packed_data = kzalloc(packed_size, GFP_KERNEL);
- if (packed_data == NULL)
- return -ENOMEM;
- ret = q6common_pack_pp_params(packed_data, ¶m_hdr, param_data,
- &packed_size);
- if (ret) {
- pr_err("%s: Failed to pack params, error %d\n", __func__, ret);
- goto done;
- }
- ret = q6asm_set_pp_params(ac, NULL, packed_data, packed_size);
- done:
- kfree(packed_data);
- return ret;
- }
- EXPORT_SYMBOL(q6asm_pack_and_set_pp_param_in_band);
- /**
- * q6asm_set_soft_volume_module_instance_ids
- * command to set module and instance ids for soft volume
- *
- * @instance: soft volume instance
- * @param_hdr: parameter header
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_set_soft_volume_module_instance_ids(int instance,
- struct param_hdr_v3 *param_hdr)
- {
- if (param_hdr == NULL) {
- pr_err("%s: Param header is NULL\n", __func__);
- return -EINVAL;
- }
- switch (instance) {
- case SOFT_VOLUME_INSTANCE_2:
- param_hdr->module_id = ASM_MODULE_ID_VOL_CTRL2;
- param_hdr->instance_id = INSTANCE_ID_0;
- return 0;
- case SOFT_VOLUME_INSTANCE_1:
- param_hdr->module_id = ASM_MODULE_ID_VOL_CTRL;
- param_hdr->instance_id = INSTANCE_ID_0;
- return 0;
- default:
- pr_err("%s: Invalid instance %d\n", __func__, instance);
- return -EINVAL;
- }
- }
- EXPORT_SYMBOL(q6asm_set_soft_volume_module_instance_ids);
- /**
- * q6asm_open_read_compressed -
- * command to open ASM in compressed read mode
- *
- * @ac: Audio client handle
- * @format: capture format for ASM
- * @passthrough_flag: flag to indicate passthrough option
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_open_read_compressed(struct audio_client *ac, uint32_t format,
- uint32_t passthrough_flag)
- {
- int rc = 0;
- struct asm_stream_cmd_open_read_compressed open;
- if (ac == NULL) {
- pr_err("%s: ac[%pK] NULL\n", __func__, ac);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: APR handle[%pK] NULL\n", __func__, ac->apr);
- rc = -EINVAL;
- goto fail_cmd;
- }
- pr_debug("%s: session[%d] wr_format[0x%x]\n", __func__, ac->session,
- format);
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_COMPRESSED;
- atomic_set(&ac->cmd_state, -1);
- /*
- * Below flag indicates whether DSP shall keep IEC61937 packing or
- * unpack to raw compressed format
- */
- if (format == FORMAT_IEC61937) {
- open.mode_flags = 0x1;
- open.frames_per_buf = 1;
- pr_debug("%s: Flag 1 IEC61937 output\n", __func__);
- } else {
- open.mode_flags = 0;
- open.frames_per_buf = 1;
- pr_debug("%s: Flag 0 RAW_COMPR output\n", __func__);
- }
- 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);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for OPEN_READ_COMPR rc[%d]\n",
- __func__, rc);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_open_read_compressed);
- static int __q6asm_open_read(struct audio_client *ac,
- uint32_t format, uint16_t bits_per_sample,
- uint32_t pcm_format_block_ver,
- bool ts_mode, uint32_t enc_cfg_id)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_read_v3 open;
- struct q6asm_cal_info cal_info;
- config_debug_fs_reset_index();
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- atomic_set(&ac->cmd_state, -1);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_READ_V3;
- /* Stream prio : High, provide meta info with encoded frames */
- open.src_endpointype = ASM_END_POINT_DEVICE_MATRIX;
- rc = q6asm_get_asm_topology_apptype(&cal_info);
- open.preprocopo_id = cal_info.topology_id;
- open.bits_per_sample = bits_per_sample;
- open.mode_flags = 0x0;
- ac->topology = open.preprocopo_id;
- ac->app_type = cal_info.app_type;
- if (ac->perf_mode == LOW_LATENCY_PCM_MODE) {
- open.mode_flags |= ASM_LOW_LATENCY_TX_STREAM_SESSION <<
- ASM_SHIFT_STREAM_PERF_MODE_FLAG_IN_OPEN_READ;
- } else {
- open.mode_flags |= ASM_LEGACY_STREAM_SESSION <<
- ASM_SHIFT_STREAM_PERF_MODE_FLAG_IN_OPEN_READ;
- }
- switch (format) {
- case FORMAT_LINEAR_PCM:
- open.mode_flags |= 0x00;
- open.enc_cfg_id = q6asm_get_pcm_format_id(pcm_format_block_ver);
- if (ts_mode)
- open.mode_flags |= ABSOLUTE_TIMESTAMP_ENABLE;
- break;
- case FORMAT_MPEG4_AAC:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_G711_ALAW_FS:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_G711_ALAW_FS;
- break;
- case FORMAT_G711_MLAW_FS:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_G711_MLAW_FS;
- break;
- case FORMAT_V13K:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_V13K_FS;
- break;
- case FORMAT_EVRC:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_EVRC_FS;
- break;
- case FORMAT_AMRNB:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = ASM_MEDIA_FMT_AMRWB_FS;
- break;
- case FORMAT_BESPOKE:
- open.mode_flags |= BUFFER_META_ENABLE;
- open.enc_cfg_id = enc_cfg_id;
- if (ts_mode)
- open.mode_flags |= ABSOLUTE_TIMESTAMP_ENABLE;
- break;
- default:
- pr_err("%s: Invalid format 0x%x\n",
- __func__, format);
- rc = -EINVAL;
- 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);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for open read\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- ac->io_mode |= TUN_READ_IO_MODE;
- return 0;
- fail_cmd:
- return rc;
- }
- /**
- * q6asm_open_read -
- * command to open ASM in read mode
- *
- * @ac: Audio client handle
- * @format: capture format for ASM
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_open_read(struct audio_client *ac,
- uint32_t format)
- {
- return __q6asm_open_read(ac, format, 16,
- PCM_MEDIA_FORMAT_V2 /*media fmt block ver*/,
- false/*ts_mode*/, ENC_CFG_ID_NONE);
- }
- EXPORT_SYMBOL(q6asm_open_read);
- int q6asm_open_read_v2(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample)
- {
- return __q6asm_open_read(ac, format, bits_per_sample,
- PCM_MEDIA_FORMAT_V2 /*media fmt block ver*/,
- false/*ts_mode*/, ENC_CFG_ID_NONE);
- }
- /*
- * asm_open_read_v3 - Opens audio capture session
- *
- * @ac: Client session handle
- * @format: encoder format
- * @bits_per_sample: bit width of capture session
- */
- int q6asm_open_read_v3(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample)
- {
- return __q6asm_open_read(ac, format, bits_per_sample,
- PCM_MEDIA_FORMAT_V3/*media fmt block ver*/,
- false/*ts_mode*/, ENC_CFG_ID_NONE);
- }
- EXPORT_SYMBOL(q6asm_open_read_v3);
- /*
- * asm_open_read_v4 - Opens audio capture session
- *
- * @ac: Client session handle
- * @format: encoder format
- * @bits_per_sample: bit width of capture session
- * @ts_mode: timestamp mode
- */
- int q6asm_open_read_v4(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, bool ts_mode,
- uint32_t enc_cfg_id)
- {
- return __q6asm_open_read(ac, format, bits_per_sample,
- PCM_MEDIA_FORMAT_V4 /*media fmt block ver*/,
- ts_mode, enc_cfg_id);
- }
- EXPORT_SYMBOL(q6asm_open_read_v4);
- /*
- * asm_open_read_v5 - Opens audio capture session
- *
- * @ac: Client session handle
- * @format: encoder format
- * @bits_per_sample: bit width of capture session
- * @ts_mode: timestamp mode
- */
- int q6asm_open_read_v5(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, bool ts_mode, uint32_t enc_cfg_id)
- {
- return __q6asm_open_read(ac, format, bits_per_sample,
- PCM_MEDIA_FORMAT_V5 /*media fmt block ver*/,
- ts_mode, enc_cfg_id);
- }
- EXPORT_SYMBOL(q6asm_open_read_v5);
- /**
- * q6asm_open_write_compressed -
- * command to open ASM in compressed write mode
- *
- * @ac: Audio client handle
- * @format: playback format for ASM
- * @passthrough_flag: flag to indicate passthrough option
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_open_write_compressed(struct audio_client *ac, uint32_t format,
- uint32_t passthrough_flag)
- {
- int rc = 0;
- struct asm_stream_cmd_open_write_compressed open;
- if (ac == NULL) {
- pr_err("%s: ac[%pK] NULL\n", __func__, ac);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: APR handle[%pK] NULL\n", __func__, ac->apr);
- rc = -EINVAL;
- goto fail_cmd;
- }
- 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;
- atomic_set(&ac->cmd_state, -1);
- switch (format) {
- case FORMAT_AC3:
- open.fmt_id = ASM_MEDIA_FMT_AC3;
- break;
- case FORMAT_EAC3:
- open.fmt_id = ASM_MEDIA_FMT_EAC3;
- break;
- case FORMAT_DTS:
- open.fmt_id = ASM_MEDIA_FMT_DTS;
- break;
- case FORMAT_DSD:
- open.fmt_id = ASM_MEDIA_FMT_DSD;
- break;
- case FORMAT_GEN_COMPR:
- open.fmt_id = ASM_MEDIA_FMT_GENERIC_COMPRESSED;
- break;
- case FORMAT_TRUEHD:
- open.fmt_id = ASM_MEDIA_FMT_TRUEHD;
- break;
- case FORMAT_IEC61937:
- open.fmt_id = ASM_MEDIA_FMT_IEC;
- break;
- default:
- pr_err("%s: Invalid format[%d]\n", __func__, format);
- rc = -EINVAL;
- goto fail_cmd;
- }
- /* Below flag indicates the DSP that Compressed audio input
- * stream is not IEC 61937 or IEC 60958 packetizied
- */
- if (passthrough_flag == COMPRESSED_PASSTHROUGH ||
- passthrough_flag == COMPRESSED_PASSTHROUGH_DSD ||
- passthrough_flag == COMPRESSED_PASSTHROUGH_GEN) {
- open.flags = 0x0;
- pr_debug("%s: Flag 0 COMPRESSED_PASSTHROUGH\n", __func__);
- } else if (passthrough_flag == COMPRESSED_PASSTHROUGH_CONVERT) {
- open.flags = 0x8;
- pr_debug("%s: Flag 8 - COMPRESSED_PASSTHROUGH_CONVERT\n",
- __func__);
- } else if (passthrough_flag == COMPRESSED_PASSTHROUGH_IEC61937) {
- open.flags = 0x1;
- pr_debug("%s: Flag 1 - COMPRESSED_PASSTHROUGH_IEC61937\n",
- __func__);
- } else {
- pr_err("%s: Invalid passthrough type[%d]\n",
- __func__, passthrough_flag);
- rc = -EINVAL;
- 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);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for OPEN_WRITE_COMPR rc[%d]\n",
- __func__, rc);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_open_write_compressed);
- static int __q6asm_open_write(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, uint32_t stream_id,
- bool is_gapless_mode,
- uint32_t pcm_format_block_ver)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_write_v3 open;
- struct q6asm_cal_info cal_info;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- dev_vdbg(ac->dev, "%s: session[%d] wr_format[0x%x]\n",
- __func__, ac->session, format);
- q6asm_stream_add_hdr(ac, &open.hdr, sizeof(open), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&open.hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- dev_vdbg(ac->dev, "%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, open.hdr.token, stream_id, ac->session);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V3;
- open.mode_flags = 0x00;
- if (ac->perf_mode == ULL_POST_PROCESSING_PCM_MODE)
- open.mode_flags |= ASM_ULL_POST_PROCESSING_STREAM_SESSION;
- else if (ac->perf_mode == ULTRA_LOW_LATENCY_PCM_MODE)
- open.mode_flags |= ASM_ULTRA_LOW_LATENCY_STREAM_SESSION;
- else if (ac->perf_mode == LOW_LATENCY_PCM_MODE)
- open.mode_flags |= ASM_LOW_LATENCY_STREAM_SESSION;
- else {
- open.mode_flags |= ASM_LEGACY_STREAM_SESSION;
- if (is_gapless_mode)
- open.mode_flags |= 1 << ASM_SHIFT_GAPLESS_MODE_FLAG;
- }
- /* source endpoint : matrix */
- open.sink_endpointype = ASM_END_POINT_DEVICE_MATRIX;
- open.bits_per_sample = bits_per_sample;
- rc = q6asm_get_asm_topology_apptype(&cal_info);
- open.postprocopo_id = cal_info.topology_id;
- if (ac->perf_mode != LEGACY_PCM_MODE)
- open.postprocopo_id = ASM_STREAM_POSTPROCOPO_ID_NONE;
- pr_debug("%s: perf_mode %d asm_topology 0x%x bps %d\n", __func__,
- ac->perf_mode, open.postprocopo_id, open.bits_per_sample);
- /*
- * For Gapless playback it will use the same session for next stream,
- * So use the same topology
- */
- if (!ac->topology) {
- ac->topology = open.postprocopo_id;
- ac->app_type = cal_info.app_type;
- }
- switch (format) {
- case FORMAT_LINEAR_PCM:
- open.dec_fmt_id = q6asm_get_pcm_format_id(pcm_format_block_ver);
- break;
- case FORMAT_MPEG4_AAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_MPEG4_MULTI_AAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_WMA_V9:
- open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V9_V2;
- break;
- case FORMAT_WMA_V10PRO:
- open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V10PRO_V2;
- break;
- case FORMAT_AMRNB:
- open.dec_fmt_id = ASM_MEDIA_FMT_AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.dec_fmt_id = ASM_MEDIA_FMT_AMRWB_FS;
- break;
- case FORMAT_AMR_WB_PLUS:
- open.dec_fmt_id = ASM_MEDIA_FMT_AMR_WB_PLUS_V2;
- break;
- case FORMAT_MP3:
- open.dec_fmt_id = ASM_MEDIA_FMT_MP3;
- break;
- case FORMAT_AC3:
- open.dec_fmt_id = ASM_MEDIA_FMT_AC3;
- break;
- case FORMAT_EAC3:
- open.dec_fmt_id = ASM_MEDIA_FMT_EAC3;
- break;
- case FORMAT_MP2:
- open.dec_fmt_id = ASM_MEDIA_FMT_MP2;
- break;
- case FORMAT_FLAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_FLAC;
- break;
- case FORMAT_ALAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_ALAC;
- break;
- case FORMAT_VORBIS:
- open.dec_fmt_id = ASM_MEDIA_FMT_VORBIS;
- break;
- case FORMAT_APE:
- open.dec_fmt_id = ASM_MEDIA_FMT_APE;
- break;
- case FORMAT_DSD:
- open.dec_fmt_id = ASM_MEDIA_FMT_DSD;
- break;
- case FORMAT_APTX:
- open.dec_fmt_id = ASM_MEDIA_FMT_APTX;
- break;
- case FORMAT_GEN_COMPR:
- open.dec_fmt_id = ASM_MEDIA_FMT_GENERIC_COMPRESSED;
- break;
- default:
- pr_err("%s: Invalid format 0x%x\n", __func__, format);
- rc = -EINVAL;
- 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);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for open write\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- ac->io_mode |= TUN_WRITE_IO_MODE;
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_open_write(struct audio_client *ac, uint32_t format)
- {
- return __q6asm_open_write(ac, format, 16, ac->stream_id,
- false /*gapless*/,
- PCM_MEDIA_FORMAT_V2 /*pcm_format_block_ver*/);
- }
- EXPORT_SYMBOL(q6asm_open_write);
- int q6asm_open_write_v2(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- ac->stream_id, false /*gapless*/,
- PCM_MEDIA_FORMAT_V2 /*pcm_format_block_ver*/);
- }
- /*
- * q6asm_open_write_v3 - Opens audio playback session
- *
- * @ac: Client session handle
- * @format: decoder format
- * @bits_per_sample: bit width of playback session
- */
- int q6asm_open_write_v3(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- ac->stream_id, false /*gapless*/,
- PCM_MEDIA_FORMAT_V3 /*pcm_format_block_ver*/);
- }
- EXPORT_SYMBOL(q6asm_open_write_v3);
- /*
- * q6asm_open_write_v4 - Opens audio playback session
- *
- * @ac: Client session handle
- * @format: decoder format
- * @bits_per_sample: bit width of playback session
- */
- int q6asm_open_write_v4(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- ac->stream_id, false /*gapless*/,
- PCM_MEDIA_FORMAT_V4 /*pcm_format_block_ver*/);
- }
- EXPORT_SYMBOL(q6asm_open_write_v4);
- int q6asm_stream_open_write_v2(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, int32_t stream_id,
- bool is_gapless_mode)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- stream_id, is_gapless_mode,
- PCM_MEDIA_FORMAT_V2 /*pcm_format_block_ver*/);
- }
- /*
- * q6asm_stream_open_write_v3 - Creates audio stream for playback
- *
- * @ac: Client session handle
- * @format: asm playback format
- * @bits_per_sample: bit width of requested stream
- * @stream_id: stream id of stream to be associated with this session
- * @is_gapless_mode: true if gapless mode needs to be enabled
- */
- int q6asm_stream_open_write_v3(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, int32_t stream_id,
- bool is_gapless_mode)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- stream_id, is_gapless_mode,
- PCM_MEDIA_FORMAT_V3 /*pcm_format_block_ver*/);
- }
- EXPORT_SYMBOL(q6asm_stream_open_write_v3);
- /*
- * q6asm_open_write_v5 - Opens audio playback session
- *
- * @ac: Client session handle
- * @format: decoder format
- * @bits_per_sample: bit width of playback session
- */
- int q6asm_open_write_v5(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- ac->stream_id, false /*gapless*/,
- PCM_MEDIA_FORMAT_V5 /*pcm_format_block_ver*/);
- }
- EXPORT_SYMBOL(q6asm_open_write_v5);
- /*
- * q6asm_stream_open_write_v4 - Creates audio stream for playback
- *
- * @ac: Client session handle
- * @format: asm playback format
- * @bits_per_sample: bit width of requested stream
- * @stream_id: stream id of stream to be associated with this session
- * @is_gapless_mode: true if gapless mode needs to be enabled
- */
- int q6asm_stream_open_write_v4(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, int32_t stream_id,
- bool is_gapless_mode)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- stream_id, is_gapless_mode,
- PCM_MEDIA_FORMAT_V4 /*pcm_format_block_ver*/);
- }
- EXPORT_SYMBOL(q6asm_stream_open_write_v4);
- /*
- * q6asm_stream_open_write_v5 - Creates audio stream for playback
- *
- * @ac: Client session handle
- * @format: asm playback format
- * @bits_per_sample: bit width of requested stream
- * @stream_id: stream id of stream to be associated with this session
- * @is_gapless_mode: true if gapless mode needs to be enabled
- */
- int q6asm_stream_open_write_v5(struct audio_client *ac, uint32_t format,
- uint16_t bits_per_sample, int32_t stream_id,
- bool is_gapless_mode)
- {
- return __q6asm_open_write(ac, format, bits_per_sample,
- stream_id, is_gapless_mode,
- PCM_MEDIA_FORMAT_V5 /*pcm_format_block_ver*/);
- }
- EXPORT_SYMBOL(q6asm_stream_open_write_v5);
- static int __q6asm_open_read_write(struct audio_client *ac, uint32_t rd_format,
- uint32_t wr_format, bool is_meta_data_mode,
- uint32_t bits_per_sample,
- bool overwrite_topology, int topology)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_readwrite_v2 open;
- struct q6asm_cal_info cal_info;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- pr_debug("%s: wr_format[0x%x]rd_format[0x%x]\n",
- __func__, wr_format, rd_format);
- ac->io_mode |= NT_MODE;
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- atomic_set(&ac->cmd_state, -1);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_READWRITE_V2;
- open.mode_flags = is_meta_data_mode ? BUFFER_META_ENABLE : 0;
- open.bits_per_sample = bits_per_sample;
- /* source endpoint : matrix */
- rc = q6asm_get_asm_topology_apptype(&cal_info);
- open.postprocopo_id = cal_info.topology_id;
- open.postprocopo_id = overwrite_topology ?
- topology : open.postprocopo_id;
- ac->topology = open.postprocopo_id;
- ac->app_type = cal_info.app_type;
- switch (wr_format) {
- case FORMAT_LINEAR_PCM:
- case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
- open.dec_fmt_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- break;
- case FORMAT_MPEG4_AAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_MPEG4_MULTI_AAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_WMA_V9:
- open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V9_V2;
- break;
- case FORMAT_WMA_V10PRO:
- open.dec_fmt_id = ASM_MEDIA_FMT_WMA_V10PRO_V2;
- break;
- case FORMAT_AMRNB:
- open.dec_fmt_id = ASM_MEDIA_FMT_AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.dec_fmt_id = ASM_MEDIA_FMT_AMRWB_FS;
- break;
- case FORMAT_AMR_WB_PLUS:
- open.dec_fmt_id = ASM_MEDIA_FMT_AMR_WB_PLUS_V2;
- break;
- case FORMAT_V13K:
- open.dec_fmt_id = ASM_MEDIA_FMT_V13K_FS;
- break;
- case FORMAT_EVRC:
- open.dec_fmt_id = ASM_MEDIA_FMT_EVRC_FS;
- break;
- case FORMAT_EVRCB:
- open.dec_fmt_id = ASM_MEDIA_FMT_EVRCB_FS;
- break;
- case FORMAT_EVRCWB:
- open.dec_fmt_id = ASM_MEDIA_FMT_EVRCWB_FS;
- break;
- case FORMAT_MP3:
- open.dec_fmt_id = ASM_MEDIA_FMT_MP3;
- break;
- case FORMAT_ALAC:
- open.dec_fmt_id = ASM_MEDIA_FMT_ALAC;
- break;
- case FORMAT_APE:
- open.dec_fmt_id = ASM_MEDIA_FMT_APE;
- break;
- case FORMAT_DSD:
- open.dec_fmt_id = ASM_MEDIA_FMT_DSD;
- break;
- case FORMAT_G711_ALAW_FS:
- open.dec_fmt_id = ASM_MEDIA_FMT_G711_ALAW_FS;
- break;
- case FORMAT_G711_MLAW_FS:
- open.dec_fmt_id = ASM_MEDIA_FMT_G711_MLAW_FS;
- break;
- default:
- pr_err("%s: Invalid format 0x%x\n",
- __func__, wr_format);
- rc = -EINVAL;
- goto fail_cmd;
- }
- switch (rd_format) {
- case FORMAT_LINEAR_PCM:
- case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
- open.enc_cfg_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- break;
- case FORMAT_MPEG4_AAC:
- open.enc_cfg_id = ASM_MEDIA_FMT_AAC_V2;
- break;
- case FORMAT_G711_ALAW_FS:
- open.enc_cfg_id = ASM_MEDIA_FMT_G711_ALAW_FS;
- break;
- case FORMAT_G711_MLAW_FS:
- open.enc_cfg_id = ASM_MEDIA_FMT_G711_MLAW_FS;
- break;
- case FORMAT_V13K:
- open.enc_cfg_id = ASM_MEDIA_FMT_V13K_FS;
- break;
- case FORMAT_EVRC:
- open.enc_cfg_id = ASM_MEDIA_FMT_EVRC_FS;
- break;
- case FORMAT_AMRNB:
- open.enc_cfg_id = ASM_MEDIA_FMT_AMRNB_FS;
- break;
- case FORMAT_AMRWB:
- open.enc_cfg_id = ASM_MEDIA_FMT_AMRWB_FS;
- break;
- case FORMAT_ALAC:
- open.enc_cfg_id = ASM_MEDIA_FMT_ALAC;
- break;
- case FORMAT_APE:
- open.enc_cfg_id = ASM_MEDIA_FMT_APE;
- break;
- default:
- pr_err("%s: Invalid format 0x%x\n",
- __func__, rd_format);
- rc = -EINVAL;
- goto fail_cmd;
- }
- dev_vdbg(ac->dev, "%s: rdformat[0x%x]wrformat[0x%x]\n", __func__,
- open.enc_cfg_id, open.dec_fmt_id);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &open);
- if (rc < 0) {
- pr_err("%s: open failed op[0x%x]rc[%d]\n",
- __func__, open.hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for open read-write\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- /**
- * q6asm_open_read_write -
- * command to open ASM in read/write mode
- *
- * @ac: Audio client handle
- * @rd_format: capture format for ASM
- * @wr_format: playback format for ASM
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_open_read_write(struct audio_client *ac, uint32_t rd_format,
- uint32_t wr_format)
- {
- return __q6asm_open_read_write(ac, rd_format, wr_format,
- true/*meta data mode*/,
- 16 /*bits_per_sample*/,
- false /*overwrite_topology*/, 0);
- }
- EXPORT_SYMBOL(q6asm_open_read_write);
- /**
- * q6asm_open_read_write_v2 -
- * command to open ASM in bi-directional read/write mode
- *
- * @ac: Audio client handle
- * @rd_format: capture format for ASM
- * @wr_format: playback format for ASM
- * @is_meta_data_mode: mode to indicate if meta data present
- * @bits_per_sample: number of bits per sample
- * @overwrite_topology: topology to be overwritten flag
- * @topology: Topology for ASM
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_open_read_write_v2(struct audio_client *ac, uint32_t rd_format,
- uint32_t wr_format, bool is_meta_data_mode,
- uint32_t bits_per_sample, bool overwrite_topology,
- int topology)
- {
- return __q6asm_open_read_write(ac, rd_format, wr_format,
- is_meta_data_mode, bits_per_sample,
- overwrite_topology, topology);
- }
- EXPORT_SYMBOL(q6asm_open_read_write_v2);
- /**
- * q6asm_open_loopback_v2 -
- * command to open ASM in loopback mode
- *
- * @ac: Audio client handle
- * @bits_per_sample: number of bits per sample
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_open_loopback_v2(struct audio_client *ac, uint16_t bits_per_sample)
- {
- int rc = 0x00;
- struct q6asm_cal_info cal_info;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- if (ac->perf_mode == LOW_LATENCY_PCM_MODE) {
- struct asm_stream_cmd_open_transcode_loopback_t open;
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- atomic_set(&ac->cmd_state, -1);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_TRANSCODE_LOOPBACK;
- open.mode_flags = 0;
- open.src_endpoint_type = 0;
- open.sink_endpoint_type = 0;
- open.src_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- open.sink_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
- /* source endpoint : matrix */
- rc = q6asm_get_asm_topology_apptype(&cal_info);
- open.audproc_topo_id = cal_info.topology_id;
- ac->app_type = cal_info.app_type;
- if (ac->perf_mode == LOW_LATENCY_PCM_MODE)
- open.mode_flags |= ASM_LOW_LATENCY_STREAM_SESSION;
- else
- open.mode_flags |= ASM_LEGACY_STREAM_SESSION;
- ac->topology = open.audproc_topo_id;
- open.bits_per_sample = bits_per_sample;
- open.reserved = 0;
- pr_debug("%s: opening a transcode_loopback with mode_flags =[%d] session[%d]\n",
- __func__, open.mode_flags, ac->session);
- 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);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {/*if(ac->perf_mode == LEGACY_PCM_MODE)*/
- struct asm_stream_cmd_open_loopback_v2 open;
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- atomic_set(&ac->cmd_state, -1);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_LOOPBACK_V2;
- open.mode_flags = 0;
- open.src_endpointype = 0;
- open.sink_endpointype = 0;
- /* source endpoint : matrix */
- rc = q6asm_get_asm_topology_apptype(&cal_info);
- open.postprocopo_id = cal_info.topology_id;
- ac->app_type = cal_info.app_type;
- ac->topology = open.postprocopo_id;
- open.bits_per_sample = bits_per_sample;
- open.reserved = 0;
- pr_debug("%s: opening a loopback_v2 with mode_flags =[%d] session[%d]\n",
- __func__, open.mode_flags, ac->session);
- 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);
- rc = -EINVAL;
- goto fail_cmd;
- }
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for open_loopback\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_open_loopback_v2);
- /**
- * q6asm_open_transcode_loopback -
- * command to open ASM in transcode loopback mode
- *
- * @ac: Audio client handle
- * @bits_per_sample: number of bits per sample
- * @source_format: Format of clip
- * @sink_format: end device supported format
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_open_transcode_loopback(struct audio_client *ac,
- uint16_t bits_per_sample,
- uint32_t source_format, uint32_t sink_format)
- {
- int rc = 0x00;
- struct asm_stream_cmd_open_transcode_loopback_t open;
- struct q6asm_cal_info cal_info;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- q6asm_add_hdr(ac, &open.hdr, sizeof(open), TRUE);
- atomic_set(&ac->cmd_state, -1);
- open.hdr.opcode = ASM_STREAM_CMD_OPEN_TRANSCODE_LOOPBACK;
- open.mode_flags = 0;
- open.src_endpoint_type = 0;
- open.sink_endpoint_type = 0;
- switch (source_format) {
- case FORMAT_LINEAR_PCM:
- case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
- open.src_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V3;
- break;
- case FORMAT_AC3:
- open.src_format_id = ASM_MEDIA_FMT_AC3;
- break;
- case FORMAT_EAC3:
- open.src_format_id = ASM_MEDIA_FMT_EAC3;
- break;
- default:
- pr_err("%s: Unsupported src fmt [%d]\n",
- __func__, source_format);
- return -EINVAL;
- }
- switch (sink_format) {
- case FORMAT_LINEAR_PCM:
- case FORMAT_MULTI_CHANNEL_LINEAR_PCM:
- open.sink_format_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V3;
- break;
- default:
- pr_err("%s: Unsupported sink fmt [%d]\n",
- __func__, sink_format);
- return -EINVAL;
- }
- /* source endpoint : matrix */
- rc = q6asm_get_asm_topology_apptype(&cal_info);
- open.audproc_topo_id = cal_info.topology_id;
- ac->app_type = cal_info.app_type;
- if (ac->perf_mode == LOW_LATENCY_PCM_MODE)
- open.mode_flags |= ASM_LOW_LATENCY_STREAM_SESSION;
- else
- open.mode_flags |= ASM_LEGACY_STREAM_SESSION;
- ac->topology = open.audproc_topo_id;
- open.bits_per_sample = bits_per_sample;
- open.reserved = 0;
- pr_debug("%s: opening a transcode_loopback with mode_flags =[%d] session[%d]\n",
- __func__, open.mode_flags, ac->session);
- 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);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for open_transcode_loopback\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_open_transcode_loopback);
- static
- int q6asm_set_shared_circ_buff(struct audio_client *ac,
- struct asm_stream_cmd_open_shared_io *open,
- int bufsz, int bufcnt,
- int dir)
- {
- struct audio_buffer *buf_circ;
- int bytes_to_alloc, rc;
- size_t len;
- mutex_lock(&ac->cmd_lock);
- if (ac->port[dir].buf) {
- pr_err("%s: Buffer already allocated\n", __func__);
- rc = -EINVAL;
- goto done;
- }
- buf_circ = kzalloc(sizeof(struct audio_buffer), GFP_KERNEL);
- if (!buf_circ) {
- rc = -ENOMEM;
- goto done;
- }
- bytes_to_alloc = bufsz * bufcnt;
- bytes_to_alloc = PAGE_ALIGN(bytes_to_alloc);
- rc = msm_audio_ion_alloc(&buf_circ->dma_buf,
- bytes_to_alloc,
- &buf_circ->phys,
- &len, &buf_circ->data);
- if (rc) {
- pr_err("%s: Audio ION alloc is failed, rc = %d\n", __func__,
- rc);
- kfree(buf_circ);
- goto done;
- }
- ac->port[dir].buf = buf_circ;
- buf_circ->used = dir ^ 1;
- buf_circ->size = bytes_to_alloc;
- buf_circ->actual_size = bytes_to_alloc;
- memset(buf_circ->data, 0, buf_circ->actual_size);
- ac->port[dir].max_buf_cnt = 1;
- open->shared_circ_buf_mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
- open->shared_circ_buf_num_regions = 1;
- open->shared_circ_buf_property_flag = 0x00;
- open->shared_circ_buf_start_phy_addr_lsw =
- lower_32_bits(buf_circ->phys);
- open->shared_circ_buf_start_phy_addr_msw =
- msm_audio_populate_upper_32_bits(buf_circ->phys);
- open->shared_circ_buf_size = bufsz * bufcnt;
- open->map_region_circ_buf.shm_addr_lsw = lower_32_bits(buf_circ->phys);
- open->map_region_circ_buf.shm_addr_msw =
- msm_audio_populate_upper_32_bits(buf_circ->phys);
- open->map_region_circ_buf.mem_size_bytes = bytes_to_alloc;
- done:
- mutex_unlock(&ac->cmd_lock);
- return rc;
- }
- static
- int q6asm_set_shared_pos_buff(struct audio_client *ac,
- struct asm_stream_cmd_open_shared_io *open,
- int dir)
- {
- struct audio_buffer *buf_pos = &ac->shared_pos_buf;
- int rc;
- size_t len;
- int bytes_to_alloc = sizeof(struct asm_shared_position_buffer);
- mutex_lock(&ac->cmd_lock);
- bytes_to_alloc = PAGE_ALIGN(bytes_to_alloc);
- rc = msm_audio_ion_alloc(&buf_pos->dma_buf,
- bytes_to_alloc,
- &buf_pos->phys, &len,
- &buf_pos->data);
- if (rc) {
- pr_err("%s: Audio pos buf ION alloc is failed, rc = %d\n",
- __func__, rc);
- goto done;
- }
- buf_pos->used = dir ^ 1;
- buf_pos->size = bytes_to_alloc;
- buf_pos->actual_size = bytes_to_alloc;
- open->shared_pos_buf_mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
- open->shared_pos_buf_num_regions = 1;
- open->shared_pos_buf_property_flag = 0x00;
- open->shared_pos_buf_phy_addr_lsw = lower_32_bits(buf_pos->phys);
- open->shared_pos_buf_phy_addr_msw =
- msm_audio_populate_upper_32_bits(buf_pos->phys);
- open->map_region_pos_buf.shm_addr_lsw = lower_32_bits(buf_pos->phys);
- open->map_region_pos_buf.shm_addr_msw =
- msm_audio_populate_upper_32_bits(buf_pos->phys);
- open->map_region_pos_buf.mem_size_bytes = bytes_to_alloc;
- done:
- mutex_unlock(&ac->cmd_lock);
- return rc;
- }
- /*
- * q6asm_open_shared_io: Open an ASM session for pull mode (playback)
- * or push mode (capture).
- * parameters
- * config - session parameters (channels, bits_per_sample, sr)
- * dir - stream direction (IN for playback, OUT for capture)
- * use_default_chmap: true if default channel map to be used
- * channel_map: input channel map
- * returns 0 if successful, error code otherwise
- */
- int q6asm_open_shared_io(struct audio_client *ac,
- struct shared_io_config *config,
- int dir, bool use_default_chmap, u8 *channel_map)
- {
- struct asm_stream_cmd_open_shared_io *open;
- u8 *channel_mapping;
- int i, size_of_open, num_watermarks, bufsz, bufcnt, rc, flags = 0;
- struct q6asm_cal_info cal_info;
- if (!ac || !config)
- return -EINVAL;
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- return -EINVAL;
- }
- if (config->channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__,
- config->channels);
- return -EINVAL;
- }
- bufsz = config->bufsz;
- bufcnt = config->bufcnt;
- num_watermarks = 0;
- ac->config = *config;
- if (ac->session <= 0 || ac->session > SESSION_MAX) {
- pr_err("%s: Session %d is out of bounds\n",
- __func__, ac->session);
- return -EINVAL;
- }
- size_of_open = sizeof(struct asm_stream_cmd_open_shared_io) +
- (sizeof(struct asm_shared_watermark_level) * num_watermarks);
- open = kzalloc(PAGE_ALIGN(size_of_open), GFP_KERNEL);
- if (!open)
- return -ENOMEM;
- q6asm_stream_add_hdr(ac, &open->hdr, size_of_open, TRUE,
- ac->stream_id);
- atomic_set(&ac->cmd_state, 1);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x, perf %d\n",
- __func__, open->hdr.token, ac->stream_id, ac->session,
- ac->perf_mode);
- open->hdr.opcode =
- dir == IN ? ASM_STREAM_CMD_OPEN_PULL_MODE_WRITE :
- ASM_STREAM_CMD_OPEN_PUSH_MODE_READ;
- pr_debug("%s perf_mode %d\n", __func__, ac->perf_mode);
- if (dir == IN)
- if (ac->perf_mode == ULL_POST_PROCESSING_PCM_MODE)
- flags = 4 << ASM_SHIFT_STREAM_PERF_FLAG_PULL_MODE_WRITE;
- else if (ac->perf_mode == ULTRA_LOW_LATENCY_PCM_MODE)
- flags = 2 << ASM_SHIFT_STREAM_PERF_FLAG_PULL_MODE_WRITE;
- else if (ac->perf_mode == LOW_LATENCY_PCM_MODE)
- flags = 1 << ASM_SHIFT_STREAM_PERF_FLAG_PULL_MODE_WRITE;
- else
- pr_err("Invalid perf mode for pull write\n");
- else
- if (ac->perf_mode == LOW_LATENCY_PCM_MODE)
- flags = ASM_LOW_LATENCY_TX_STREAM_SESSION <<
- ASM_SHIFT_STREAM_PERF_FLAG_PUSH_MODE_READ;
- else
- pr_err("Invalid perf mode for push read\n");
- if (flags == 0) {
- pr_err("%s: Invalid mode[%d]\n", __func__,
- ac->perf_mode);
- kfree(open);
- return -EINVAL;
- }
- pr_debug("open.mode_flags = 0x%x\n", flags);
- open->mode_flags = flags;
- open->endpoint_type = ASM_END_POINT_DEVICE_MATRIX;
- open->topo_bits_per_sample = config->bits_per_sample;
- rc = q6asm_get_asm_topology_apptype(&cal_info);
- open->topo_id = cal_info.topology_id;
- if (config->format == FORMAT_LINEAR_PCM)
- open->fmt_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V3;
- else {
- pr_err("%s: Invalid format[%d]\n", __func__, config->format);
- rc = -EINVAL;
- goto done;
- }
- rc = q6asm_set_shared_circ_buff(ac, open, bufsz, bufcnt, dir);
- if (rc)
- goto done;
- ac->port[dir].tmp_hdl = 0;
- rc = q6asm_set_shared_pos_buff(ac, open, dir);
- if (rc)
- goto done;
- /* asm_multi_channel_pcm_fmt_blk_v3 */
- open->fmt.num_channels = config->channels;
- open->fmt.bits_per_sample = config->bits_per_sample;
- open->fmt.sample_rate = config->rate;
- open->fmt.is_signed = 1;
- open->fmt.sample_word_size = config->sample_word_size;
- channel_mapping = open->fmt.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- rc = q6asm_map_channels(channel_mapping, config->channels,
- false);
- if (rc) {
- pr_err("%s: Map channels failed, ret: %d\n",
- __func__, rc);
- goto done;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- open->num_watermark_levels = num_watermarks;
- for (i = 0; i < num_watermarks; i++) {
- open->watermark[i].watermark_level_bytes = i *
- ((bufsz * bufcnt) / num_watermarks);
- pr_debug("%s: Watermark level set for %i\n",
- __func__,
- open->watermark[i].watermark_level_bytes);
- }
- 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 done;
- }
- pr_debug("%s: sent open apr pkt\n", __func__);
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) <= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: Timeout. Waited for open write apr pkt rc[%d]\n",
- __func__, rc);
- rc = -ETIMEDOUT;
- goto done;
- }
- if (atomic_read(&ac->cmd_state) < 0) {
- pr_err("%s: DSP returned error [%d]\n", __func__,
- atomic_read(&ac->cmd_state));
- rc = -EINVAL;
- goto done;
- }
- ac->io_mode |= TUN_WRITE_IO_MODE;
- rc = 0;
- done:
- kfree(open);
- return rc;
- }
- EXPORT_SYMBOL(q6asm_open_shared_io);
- /*
- * q6asm_shared_io_buf: Returns handle to the shared circular buffer being
- * used for pull/push mode.
- * parameters
- * dir - used to identify input/output port
- * returns buffer handle
- */
- struct audio_buffer *q6asm_shared_io_buf(struct audio_client *ac,
- int dir)
- {
- struct audio_port_data *port;
- if (!ac) {
- pr_err("%s: ac is null\n", __func__);
- return NULL;
- }
- port = &ac->port[dir];
- return port->buf;
- }
- EXPORT_SYMBOL(q6asm_shared_io_buf);
- /*
- * q6asm_shared_io_free: Frees memory allocated for a pull/push session
- * parameters
- * dir - port direction
- * returns 0 if successful, error otherwise
- */
- int q6asm_shared_io_free(struct audio_client *ac, int dir)
- {
- struct audio_port_data *port;
- if (!ac) {
- pr_err("%s: audio client is null\n", __func__);
- return -EINVAL;
- }
- port = &ac->port[dir];
- mutex_lock(&ac->cmd_lock);
- if (port->buf && port->buf->data) {
- msm_audio_ion_free(port->buf->dma_buf);
- port->buf->dma_buf = NULL;
- port->max_buf_cnt = 0;
- kfree(port->buf);
- port->buf = NULL;
- }
- if (ac->shared_pos_buf.data) {
- msm_audio_ion_free(ac->shared_pos_buf.dma_buf);
- ac->shared_pos_buf.dma_buf = NULL;
- }
- mutex_unlock(&ac->cmd_lock);
- return 0;
- }
- EXPORT_SYMBOL(q6asm_shared_io_free);
- /*
- * q6asm_get_shared_pos: Returns current read index/write index as observed
- * by the DSP. Note that this is an offset and iterates from [0,BUF_SIZE - 1]
- * parameters - (all output)
- * read_index - offset
- * wall_clk_msw1 - ADSP wallclock msw
- * wall_clk_lsw1 - ADSP wallclock lsw
- * returns 0 if successful, -EAGAIN if DSP failed to update after some
- * retries
- */
- int q6asm_get_shared_pos(struct audio_client *ac, uint32_t *read_index,
- uint32_t *wall_clk_msw1, uint32_t *wall_clk_lsw1)
- {
- struct asm_shared_position_buffer *pos_buf;
- uint32_t frame_cnt1, frame_cnt2;
- int i, j;
- if (!ac) {
- pr_err("%s: audio client is null\n", __func__);
- return -EINVAL;
- }
- pos_buf = ac->shared_pos_buf.data;
- /* always try to get the latest update in the shared pos buffer */
- for (i = 0; i < 2; i++) {
- /* retry until there is an update from DSP */
- for (j = 0; j < 5; j++) {
- frame_cnt1 = pos_buf->frame_counter;
- if (frame_cnt1 != 0)
- break;
- }
- *wall_clk_msw1 = pos_buf->wall_clock_us_msw;
- *wall_clk_lsw1 = pos_buf->wall_clock_us_lsw;
- *read_index = pos_buf->index;
- frame_cnt2 = pos_buf->frame_counter;
- if (frame_cnt1 != frame_cnt2)
- continue;
- return 0;
- }
- pr_err("%s out of tries trying to get a good read, try again\n",
- __func__);
- return -EAGAIN;
- }
- EXPORT_SYMBOL(q6asm_get_shared_pos);
- /**
- * q6asm_run -
- * command to set ASM to run state
- *
- * @ac: Audio client handle
- * @flags: Flags for session
- * @msw_ts: upper 32bits timestamp
- * @lsw_ts: lower 32bits timestamp
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_run(struct audio_client *ac, uint32_t flags,
- uint32_t msw_ts, uint32_t lsw_ts)
- {
- struct asm_session_cmd_run_v2 run;
- int rc;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- q6asm_add_hdr(ac, &run.hdr, sizeof(run), TRUE);
- atomic_set(&ac->cmd_state, -1);
- run.hdr.opcode = ASM_SESSION_CMD_RUN_V2;
- run.flags = flags;
- run.time_lsw = lsw_ts;
- run.time_msw = msw_ts;
- config_debug_fs_run();
- rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
- if (rc < 0) {
- pr_err("%s: Commmand run failed[%d]",
- __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for run success",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_run);
- static int __q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
- uint32_t msw_ts, uint32_t lsw_ts, uint32_t stream_id)
- {
- struct asm_session_cmd_run_v2 run;
- int rc;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- q6asm_stream_add_hdr_async(ac, &run.hdr, sizeof(run), TRUE, stream_id);
- atomic_set(&ac->cmd_state, 1);
- run.hdr.opcode = ASM_SESSION_CMD_RUN_V2;
- run.flags = flags;
- run.time_lsw = lsw_ts;
- run.time_msw = msw_ts;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &run);
- if (rc < 0) {
- pr_err("%s: Commmand run failed[%d]", __func__, rc);
- return -EINVAL;
- }
- return 0;
- }
- /**
- * q6asm_run_nowait -
- * command to set ASM to run state with no wait for ack
- *
- * @ac: Audio client handle
- * @flags: Flags for session
- * @msw_ts: upper 32bits timestamp
- * @lsw_ts: lower 32bits timestamp
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_run_nowait(struct audio_client *ac, uint32_t flags,
- uint32_t msw_ts, uint32_t lsw_ts)
- {
- return __q6asm_run_nowait(ac, flags, msw_ts, lsw_ts, ac->stream_id);
- }
- EXPORT_SYMBOL(q6asm_run_nowait);
- int q6asm_stream_run_nowait(struct audio_client *ac, uint32_t flags,
- uint32_t msw_ts, uint32_t lsw_ts, uint32_t stream_id)
- {
- return __q6asm_run_nowait(ac, flags, msw_ts, lsw_ts, stream_id);
- }
- /**
- * q6asm_enc_cfg_blk_custom -
- * command to set encode cfg block for custom
- *
- * @ac: Audio client handle
- * @sample_rate: Sample rate
- * @channels: number of ASM channels
- * @format: custom format flag
- * @cfg: generic encoder config
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_enc_cfg_blk_custom(struct audio_client *ac,
- uint32_t sample_rate, uint32_t channels,
- uint32_t format, void *cfg)
- {
- struct asm_custom_enc_cfg_t_v2 enc_cfg;
- int rc = 0;
- uint32_t custom_size;
- struct snd_enc_generic *enc_generic = (struct snd_enc_generic *) cfg;
- custom_size = enc_generic->reserved[1];
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: session[%d] size[%d] res[2]=[%d] res[3]=[%d]\n",
- __func__, ac->session, custom_size, enc_generic->reserved[2],
- enc_generic->reserved[3]);
- pr_debug("%s: res[4]=[%d] sr[%d] ch[%d] format[%d]\n",
- __func__, enc_generic->reserved[4], sample_rate,
- channels, format);
- memset(&enc_cfg, 0, sizeof(struct asm_custom_enc_cfg_t_v2));
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_custom_enc_cfg_t_v2) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = ENC_FRAMES_PER_BUFFER;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.num_channels = channels;
- enc_cfg.sample_rate = sample_rate;
- if (q6asm_map_channels(enc_cfg.channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (format == FORMAT_BESPOKE && custom_size &&
- custom_size <= sizeof(enc_cfg.custom_data)) {
- memcpy(enc_cfg.custom_data, &enc_generic->reserved[2],
- custom_size);
- enc_cfg.custom_size = custom_size;
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd %d failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_custom);
- /**
- * q6asm_enc_cfg_blk_aac -
- * command to set encode cfg block for aac
- *
- * @ac: Audio client handle
- * @frames_per_buf: number of frames per buffer
- * @sample_rate: Sample rate
- * @channels: number of ASM channels
- * @bit_rate: Bit rate info
- * @mode: mode of AAC stream encode
- * @format: aac format flag
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_enc_cfg_blk_aac(struct audio_client *ac,
- uint32_t frames_per_buf,
- uint32_t sample_rate, uint32_t channels,
- uint32_t bit_rate, uint32_t mode, uint32_t format)
- {
- struct asm_aac_enc_cfg_v2 enc_cfg;
- int rc = 0;
- pr_debug("%s: session[%d]frames[%d]SR[%d]ch[%d]bitrate[%d]mode[%d] format[%d]\n",
- __func__, ac->session, frames_per_buf,
- sample_rate, channels, bit_rate, mode, format);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_aac_enc_cfg_v2) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.bit_rate = bit_rate;
- enc_cfg.enc_mode = mode;
- enc_cfg.aac_fmt_flag = format;
- enc_cfg.channel_cfg = channels;
- enc_cfg.sample_rate = sample_rate;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd %d failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_aac);
- /**
- * q6asm_enc_cfg_blk_g711 -
- * command to set encode cfg block for g711
- *
- * @ac: Audio client handle
- * @frames_per_buf: number of frames per buffer
- * @sample_rate: Sample rate
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_enc_cfg_blk_g711(struct audio_client *ac,
- uint32_t frames_per_buf,
- uint32_t sample_rate)
- {
- struct asm_g711_enc_cfg_v2 enc_cfg;
- int rc = 0;
- pr_debug("%s: session[%d]frames[%d]SR[%d]\n",
- __func__, ac->session, frames_per_buf,
- sample_rate);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_g711_enc_cfg_v2) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.sample_rate = sample_rate;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd %d failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_g711);
- /**
- * q6asm_set_encdec_chan_map -
- * command to set encdec channel map
- *
- * @ac: Audio client handle
- * @channels: number of channels
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_set_encdec_chan_map(struct audio_client *ac,
- uint32_t num_channels)
- {
- struct asm_dec_out_chan_map_param chan_map;
- u8 *channel_mapping;
- int rc = 0;
- if (num_channels > MAX_CHAN_MAP_CHANNELS) {
- pr_err("%s: Invalid channel count %d\n", __func__,
- num_channels);
- return -EINVAL;
- }
- 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);
- atomic_set(&ac->cmd_state, -1);
- chan_map.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- chan_map.encdec.param_id = ASM_PARAM_ID_DEC_OUTPUT_CHAN_MAP;
- chan_map.encdec.param_size = sizeof(struct asm_dec_out_chan_map_param) -
- (sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_encdec_param));
- chan_map.num_channels = num_channels;
- channel_mapping = chan_map.channel_mapping;
- memset(channel_mapping, PCM_CHANNEL_NULL, MAX_CHAN_MAP_CHANNELS);
- if (q6asm_map_channels(channel_mapping, num_channels, false)) {
- pr_err("%s: map channels failed %d\n", __func__, num_channels);
- return -EINVAL;
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &chan_map);
- if (rc < 0) {
- pr_err("%s: Command opcode[0x%x]paramid[0x%x] failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
- ASM_PARAM_ID_DEC_OUTPUT_CHAN_MAP, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n", __func__,
- chan_map.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_set_encdec_chan_map);
- /*
- * q6asm_enc_cfg_blk_pcm_v5 - sends encoder configuration parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @use_default_chmap: true if default channel map to be used
- * @use_back_flavor: to configure back left and right channel
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- * @endianness: endianness of the pcm data
- * @mode: Mode to provide additional info about the pcm input data
- */
- static int q6asm_enc_cfg_blk_pcm_v5(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample, bool use_default_chmap,
- bool use_back_flavor, u8 *channel_map,
- uint16_t sample_word_size, uint16_t endianness,
- uint16_t mode)
- {
- struct asm_multi_channel_pcm_enc_cfg_v5 enc_cfg;
- struct asm_enc_cfg_blk_param_v2 enc_fg_blk;
- u8 *channel_mapping;
- u32 frames_per_buf = 0;
- int rc;
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL_V8) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&enc_cfg, 0, sizeof(enc_cfg));
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(enc_cfg) - sizeof(enc_cfg.hdr) -
- sizeof(enc_cfg.encdec);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(enc_fg_blk);
- enc_cfg.num_channels = channels;
- enc_cfg.bits_per_sample = bits_per_sample;
- enc_cfg.sample_rate = rate;
- enc_cfg.is_signed = 1;
- enc_cfg.sample_word_size = sample_word_size;
- enc_cfg.endianness = endianness;
- enc_cfg.mode = mode;
- channel_mapping = enc_cfg.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL_V8);
- if (use_default_chmap) {
- pr_debug("%s: setting default channel map for %d channels",
- __func__, channels);
- if (q6asm_map_channels(channel_mapping, channels,
- use_back_flavor)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- pr_debug("%s: Using pre-defined channel map", __func__);
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL_V8);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Command open failed %d\n", __func__, 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 opcode[0x%x]\n",
- __func__, enc_cfg.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_v5);
- /*
- * q6asm_enc_cfg_blk_pcm_v4 - sends encoder configuration parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @use_default_chmap: true if default channel map to be used
- * @use_back_flavor: to configure back left and right channel
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- * @endianness: endianness of the pcm data
- * @mode: Mode to provide additional info about the pcm input data
- */
- int q6asm_enc_cfg_blk_pcm_v4(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample, bool use_default_chmap,
- bool use_back_flavor, u8 *channel_map,
- uint16_t sample_word_size, uint16_t endianness,
- uint16_t mode)
- {
- struct asm_multi_channel_pcm_enc_cfg_v4 enc_cfg;
- struct asm_enc_cfg_blk_param_v2 enc_fg_blk;
- u8 *channel_mapping;
- u32 frames_per_buf = 0;
- int rc;
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&enc_cfg, 0, sizeof(enc_cfg));
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(enc_cfg) - sizeof(enc_cfg.hdr) -
- sizeof(enc_cfg.encdec);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(enc_fg_blk);
- enc_cfg.num_channels = channels;
- enc_cfg.bits_per_sample = bits_per_sample;
- enc_cfg.sample_rate = rate;
- enc_cfg.is_signed = 1;
- enc_cfg.sample_word_size = sample_word_size;
- enc_cfg.endianness = endianness;
- enc_cfg.mode = mode;
- channel_mapping = enc_cfg.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- pr_debug("%s: setting default channel map for %d channels",
- __func__, channels);
- if (q6asm_map_channels(channel_mapping, channels,
- use_back_flavor)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- pr_debug("%s: Using pre-defined channel map", __func__);
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Command open failed %d\n", __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n",
- __func__, enc_cfg.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_v4);
- /*
- * q6asm_enc_cfg_blk_pcm_v3 - sends encoder configuration parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @use_default_chmap: true if default channel map to be used
- * @use_back_flavor: to configure back left and right channel
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- */
- int q6asm_enc_cfg_blk_pcm_v3(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample, bool use_default_chmap,
- bool use_back_flavor, u8 *channel_map,
- uint16_t sample_word_size)
- {
- struct asm_multi_channel_pcm_enc_cfg_v3 enc_cfg;
- struct asm_enc_cfg_blk_param_v2 enc_fg_blk;
- u8 *channel_mapping;
- u32 frames_per_buf = 0;
- int rc;
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&enc_cfg, 0, sizeof(enc_cfg));
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(enc_cfg) - sizeof(enc_cfg.hdr) -
- sizeof(enc_cfg.encdec);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(enc_fg_blk);
- enc_cfg.num_channels = channels;
- enc_cfg.bits_per_sample = bits_per_sample;
- enc_cfg.sample_rate = rate;
- enc_cfg.is_signed = 1;
- enc_cfg.sample_word_size = sample_word_size;
- channel_mapping = enc_cfg.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- pr_debug("%s: setting default channel map for %d channels",
- __func__, channels);
- if (q6asm_map_channels(channel_mapping, channels,
- use_back_flavor)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- pr_debug("%s: Using pre-defined channel map", __func__);
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n",
- __func__, enc_cfg.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_v3);
- /**
- * q6asm_enc_cfg_blk_pcm_v2 -
- * command to set encode config block for pcm_v2
- *
- * @ac: Audio client handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: number of bits per sample
- * @use_default_chmap: Flag indicating to use default ch_map or not
- * @use_back_flavor: back flavor flag
- * @channel_map: Custom channel map settings
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_enc_cfg_blk_pcm_v2(struct audio_client *ac,
- uint32_t rate, uint32_t channels, uint16_t bits_per_sample,
- bool use_default_chmap, bool use_back_flavor, u8 *channel_map)
- {
- struct asm_multi_channel_pcm_enc_cfg_v2 enc_cfg;
- u8 *channel_mapping;
- u32 frames_per_buf = 0;
- int rc = 0;
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- return -EINVAL;
- }
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
- ac->session, rate, channels);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(enc_cfg) - sizeof(enc_cfg.hdr) -
- sizeof(enc_cfg.encdec);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.num_channels = channels;
- enc_cfg.bits_per_sample = bits_per_sample;
- enc_cfg.sample_rate = rate;
- enc_cfg.is_signed = 1;
- channel_mapping = enc_cfg.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- pr_debug("%s: setting default channel map for %d channels",
- __func__, channels);
- if (q6asm_map_channels(channel_mapping, channels,
- use_back_flavor)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- return -EINVAL;
- }
- } else {
- pr_debug("%s: Using pre-defined channel map", __func__);
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n",
- __func__, enc_cfg.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_v2);
- static int __q6asm_enc_cfg_blk_pcm_v5(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- return q6asm_enc_cfg_blk_pcm_v5(ac, rate, channels,
- bits_per_sample, true, false, NULL,
- sample_word_size, endianness, mode);
- }
- static int __q6asm_enc_cfg_blk_pcm_v4(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- return q6asm_enc_cfg_blk_pcm_v4(ac, rate, channels,
- bits_per_sample, true, false, NULL,
- sample_word_size, endianness, mode);
- }
- static int __q6asm_enc_cfg_blk_pcm_v3(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- uint16_t sample_word_size)
- {
- return q6asm_enc_cfg_blk_pcm_v3(ac, rate, channels,
- bits_per_sample, true, false, NULL,
- sample_word_size);
- }
- static int __q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels, uint16_t bits_per_sample)
- {
- return q6asm_enc_cfg_blk_pcm_v2(ac, rate, channels,
- bits_per_sample, true, false, NULL);
- }
- /**
- * q6asm_enc_cfg_blk_pcm -
- * command to set encode config block for pcm
- *
- * @ac: Audio client handle
- * @rate: sample rate
- * @channels: number of channels
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_enc_cfg_blk_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- return __q6asm_enc_cfg_blk_pcm(ac, rate, channels, 16);
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm);
- int q6asm_enc_cfg_blk_pcm_format_support(struct audio_client *ac,
- uint32_t rate, uint32_t channels, uint16_t bits_per_sample)
- {
- return __q6asm_enc_cfg_blk_pcm(ac, rate, channels, bits_per_sample);
- }
- /*
- * q6asm_enc_cfg_blk_pcm_format_support_v3 - sends encoder configuration
- * parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- */
- int q6asm_enc_cfg_blk_pcm_format_support_v3(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- uint16_t sample_word_size)
- {
- return __q6asm_enc_cfg_blk_pcm_v3(ac, rate, channels,
- bits_per_sample, sample_word_size);
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_format_support_v3);
- /*
- * q6asm_enc_cfg_blk_pcm_format_support_v4 - sends encoder configuration
- * parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- * @endianness: endianness of the pcm data
- * @mode: Mode to provide additional info about the pcm input data
- */
- int q6asm_enc_cfg_blk_pcm_format_support_v4(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- return __q6asm_enc_cfg_blk_pcm_v4(ac, rate, channels,
- bits_per_sample, sample_word_size,
- endianness, mode);
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_format_support_v4);
- /*
- * q6asm_enc_cfg_blk_pcm_format_support_v5 - sends encoder configuration
- * parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- * @endianness: endianness of the pcm data
- * @mode: Mode to provide additional info about the pcm input data
- */
- int q6asm_enc_cfg_blk_pcm_format_support_v5(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- return __q6asm_enc_cfg_blk_pcm_v5(ac, rate, channels,
- bits_per_sample, sample_word_size,
- endianness, mode);
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_format_support_v5);
- /**
- * q6asm_enc_cfg_blk_pcm_native -
- * command to set encode config block for pcm_native
- *
- * @ac: Audio client handle
- * @rate: sample rate
- * @channels: number of channels
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_enc_cfg_blk_pcm_native(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- struct asm_multi_channel_pcm_enc_cfg_v2 enc_cfg;
- u8 *channel_mapping;
- u32 frames_per_buf = 0;
- int rc = 0;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: Session %d, rate = %d, channels = %d\n", __func__,
- ac->session, rate, channels);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(enc_cfg) - sizeof(enc_cfg.hdr) -
- sizeof(enc_cfg.encdec);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.num_channels = 0;/*channels;*/
- enc_cfg.bits_per_sample = 16;
- enc_cfg.sample_rate = 0;/*rate;*/
- enc_cfg.is_signed = 1;
- channel_mapping = enc_cfg.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n", __func__, channels);
- return -EINVAL;
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n",
- __func__, enc_cfg.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_pcm_native);
- /*
- * q6asm_map_channels:
- * Provide default asm channel mapping for given channel count.
- *
- * @channel_mapping: buffer pointer to write back channel maps.
- * @channels: channel count for which channel map is required.
- * @use_back_flavor: use back channels instead of surround channels.
- * Returns 0 for success, -EINVAL for unsupported channel count.
- */
- int q6asm_map_channels(u8 *channel_mapping, uint32_t channels,
- bool use_back_flavor)
- {
- u8 *lchannel_mapping;
- lchannel_mapping = channel_mapping;
- pr_debug("%s: channels passed: %d\n", __func__, channels);
- if (channels == 1) {
- lchannel_mapping[0] = PCM_CHANNEL_FC;
- } else if (channels == 2) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- } else if (channels == 3) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- } else if (channels == 4) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = use_back_flavor ?
- PCM_CHANNEL_LB : PCM_CHANNEL_LS;
- lchannel_mapping[3] = use_back_flavor ?
- PCM_CHANNEL_RB : PCM_CHANNEL_RS;
- } else if (channels == 5) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- lchannel_mapping[3] = use_back_flavor ?
- PCM_CHANNEL_LB : PCM_CHANNEL_LS;
- lchannel_mapping[4] = use_back_flavor ?
- PCM_CHANNEL_RB : PCM_CHANNEL_RS;
- } else if (channels == 6) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- lchannel_mapping[3] = PCM_CHANNEL_LFE;
- lchannel_mapping[4] = use_back_flavor ?
- PCM_CHANNEL_LB : PCM_CHANNEL_LS;
- lchannel_mapping[5] = use_back_flavor ?
- PCM_CHANNEL_RB : PCM_CHANNEL_RS;
- } else if (channels == 7) {
- /*
- * Configured for 5.1 channel mapping + 1 channel for debug
- * Can be customized based on DSP.
- */
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- lchannel_mapping[3] = PCM_CHANNEL_LFE;
- lchannel_mapping[4] = use_back_flavor ?
- PCM_CHANNEL_LB : PCM_CHANNEL_LS;
- lchannel_mapping[5] = use_back_flavor ?
- PCM_CHANNEL_RB : PCM_CHANNEL_RS;
- lchannel_mapping[6] = PCM_CHANNEL_CS;
- } else if (channels == 8) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- lchannel_mapping[3] = PCM_CHANNEL_LFE;
- lchannel_mapping[4] = PCM_CHANNEL_LB;
- lchannel_mapping[5] = PCM_CHANNEL_RB;
- lchannel_mapping[6] = PCM_CHANNEL_LS;
- lchannel_mapping[7] = PCM_CHANNEL_RS;
- } else if (channels == 10) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_LFE;
- lchannel_mapping[3] = PCM_CHANNEL_FC;
- lchannel_mapping[4] = PCM_CHANNEL_LB;
- lchannel_mapping[5] = PCM_CHANNEL_RB;
- lchannel_mapping[6] = PCM_CHANNEL_LS;
- lchannel_mapping[7] = PCM_CHANNEL_RS;
- lchannel_mapping[8] = PCM_CHANNEL_TFL;
- lchannel_mapping[9] = PCM_CHANNEL_TFR;
- } else if (channels == 12) {
- /*
- * Configured for 7.1.4 channel mapping
- * Todo: Needs to be checked
- */
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- lchannel_mapping[3] = PCM_CHANNEL_LFE;
- lchannel_mapping[4] = PCM_CHANNEL_LB;
- lchannel_mapping[5] = PCM_CHANNEL_RB;
- lchannel_mapping[6] = PCM_CHANNEL_LS;
- lchannel_mapping[7] = PCM_CHANNEL_RS;
- lchannel_mapping[8] = PCM_CHANNEL_TFL;
- lchannel_mapping[9] = PCM_CHANNEL_TFR;
- lchannel_mapping[10] = PCM_CHANNEL_TSL;
- lchannel_mapping[11] = PCM_CHANNEL_TSR;
- } else if (channels == 14) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_LFE;
- lchannel_mapping[3] = PCM_CHANNEL_FC;
- lchannel_mapping[4] = PCM_CHANNEL_LB;
- lchannel_mapping[5] = PCM_CHANNEL_RB;
- lchannel_mapping[6] = PCM_CHANNEL_LS;
- lchannel_mapping[7] = PCM_CHANNEL_RS;
- lchannel_mapping[8] = PCM_CHANNEL_TFL;
- lchannel_mapping[9] = PCM_CHANNEL_TFR;
- lchannel_mapping[10] = PCM_CHANNEL_TSL;
- lchannel_mapping[11] = PCM_CHANNEL_TSR;
- lchannel_mapping[12] = PCM_CHANNEL_FLC;
- lchannel_mapping[13] = PCM_CHANNEL_FRC;
- } else if (channels == 16) {
- /*
- * Configured for 7.1.8 channel mapping
- * Todo: Needs to be checked
- */
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_FC;
- lchannel_mapping[3] = PCM_CHANNEL_LFE;
- lchannel_mapping[4] = PCM_CHANNEL_LB;
- lchannel_mapping[5] = PCM_CHANNEL_RB;
- lchannel_mapping[6] = PCM_CHANNEL_LS;
- lchannel_mapping[7] = PCM_CHANNEL_RS;
- lchannel_mapping[8] = PCM_CHANNEL_TFL;
- lchannel_mapping[9] = PCM_CHANNEL_TFR;
- lchannel_mapping[10] = PCM_CHANNEL_TSL;
- lchannel_mapping[11] = PCM_CHANNEL_TSR;
- lchannel_mapping[12] = PCM_CHANNEL_FLC;
- lchannel_mapping[13] = PCM_CHANNEL_FRC;
- lchannel_mapping[14] = PCM_CHANNEL_RLC;
- lchannel_mapping[15] = PCM_CHANNEL_RRC;
- } else if (channels == 32) {
- lchannel_mapping[0] = PCM_CHANNEL_FL;
- lchannel_mapping[1] = PCM_CHANNEL_FR;
- lchannel_mapping[2] = PCM_CHANNEL_LFE;
- lchannel_mapping[3] = PCM_CHANNEL_FC;
- lchannel_mapping[4] = PCM_CHANNEL_LS;
- lchannel_mapping[5] = PCM_CHANNEL_RS;
- lchannel_mapping[6] = PCM_CHANNEL_LB;
- lchannel_mapping[7] = PCM_CHANNEL_RB;
- lchannel_mapping[8] = PCM_CHANNEL_CS;
- lchannel_mapping[9] = PCM_CHANNEL_TS;
- lchannel_mapping[10] = PCM_CHANNEL_CVH;
- lchannel_mapping[11] = PCM_CHANNEL_MS;
- lchannel_mapping[12] = PCM_CHANNEL_FLC;
- lchannel_mapping[13] = PCM_CHANNEL_FRC;
- lchannel_mapping[14] = PCM_CHANNEL_RLC;
- lchannel_mapping[15] = PCM_CHANNEL_RRC;
- lchannel_mapping[16] = PCM_CHANNEL_LFE2;
- lchannel_mapping[17] = PCM_CHANNEL_SL;
- lchannel_mapping[18] = PCM_CHANNEL_SR;
- lchannel_mapping[19] = PCM_CHANNEL_TFL;
- lchannel_mapping[20] = PCM_CHANNEL_TFR;
- lchannel_mapping[21] = PCM_CHANNEL_TC;
- lchannel_mapping[22] = PCM_CHANNEL_TBL;
- lchannel_mapping[23] = PCM_CHANNEL_TBR;
- lchannel_mapping[24] = PCM_CHANNEL_TSL;
- lchannel_mapping[25] = PCM_CHANNEL_TSR;
- lchannel_mapping[26] = PCM_CHANNEL_TBC;
- lchannel_mapping[27] = PCM_CHANNEL_BFC;
- lchannel_mapping[28] = PCM_CHANNEL_BFL;
- lchannel_mapping[29] = PCM_CHANNEL_BFR;
- lchannel_mapping[30] = PCM_CHANNEL_LW;
- lchannel_mapping[31] = PCM_CHANNEL_RW;
- } else {
- pr_err("%s: ERROR.unsupported num_ch = %u\n",
- __func__, channels);
- return -EINVAL;
- }
- return 0;
- }
- EXPORT_SYMBOL(q6asm_map_channels);
- /**
- * q6asm_enable_sbrps -
- * command to enable sbrps for ASM
- *
- * @ac: Audio client handle
- * @sbr_ps_enable: flag for sbr_ps enable or disable
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_enable_sbrps(struct audio_client *ac,
- uint32_t sbr_ps_enable)
- {
- struct asm_aac_sbr_ps_flag_param sbrps;
- u32 frames_per_buf = 0;
- int rc = 0;
- pr_debug("%s: Session %d\n", __func__, ac->session);
- q6asm_add_hdr(ac, &sbrps.hdr, sizeof(sbrps), TRUE);
- atomic_set(&ac->cmd_state, -1);
- sbrps.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- sbrps.encdec.param_id = ASM_PARAM_ID_AAC_SBR_PS_FLAG;
- sbrps.encdec.param_size = sizeof(struct asm_aac_sbr_ps_flag_param) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- sbrps.encblk.frames_per_buf = frames_per_buf;
- sbrps.encblk.enc_cfg_blk_size = sbrps.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- sbrps.sbr_ps_flag = sbr_ps_enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &sbrps);
- if (rc < 0) {
- pr_err("%s: Command opcode[0x%x]paramid[0x%x] failed %d\n",
- __func__,
- ASM_STREAM_CMD_SET_ENCDEC_PARAM,
- ASM_PARAM_ID_AAC_SBR_PS_FLAG, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x] ", __func__, sbrps.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enable_sbrps);
- /**
- * q6asm_cfg_dual_mono_aac -
- * command to set config for dual mono aac
- *
- * @ac: Audio client handle
- * @sce_left: left sce val
- * @sce_right: right sce val
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_cfg_dual_mono_aac(struct audio_client *ac,
- uint16_t sce_left, uint16_t sce_right)
- {
- struct asm_aac_dual_mono_mapping_param dual_mono;
- int rc = 0;
- pr_debug("%s: Session %d, sce_left = %d, sce_right = %d\n",
- __func__, ac->session, sce_left, sce_right);
- q6asm_add_hdr(ac, &dual_mono.hdr, sizeof(dual_mono), TRUE);
- atomic_set(&ac->cmd_state, -1);
- dual_mono.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- dual_mono.encdec.param_id = ASM_PARAM_ID_AAC_DUAL_MONO_MAPPING;
- dual_mono.encdec.param_size = sizeof(dual_mono.left_channel_sce) +
- sizeof(dual_mono.right_channel_sce);
- dual_mono.left_channel_sce = sce_left;
- dual_mono.right_channel_sce = sce_right;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &dual_mono);
- if (rc < 0) {
- pr_err("%s: Command opcode[0x%x]paramid[0x%x] failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
- ASM_PARAM_ID_AAC_DUAL_MONO_MAPPING, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n", __func__,
- dual_mono.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_cfg_dual_mono_aac);
- /* Support for selecting stereo mixing coefficients for B family not done */
- int q6asm_cfg_aac_sel_mix_coef(struct audio_client *ac, uint32_t mix_coeff)
- {
- struct asm_aac_stereo_mix_coeff_selection_param_v2 aac_mix_coeff;
- int rc = 0;
- q6asm_add_hdr(ac, &aac_mix_coeff.hdr, sizeof(aac_mix_coeff), TRUE);
- atomic_set(&ac->cmd_state, -1);
- aac_mix_coeff.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- aac_mix_coeff.param_id =
- ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG_V2;
- aac_mix_coeff.param_size =
- sizeof(struct asm_aac_stereo_mix_coeff_selection_param_v2);
- aac_mix_coeff.aac_stereo_mix_coeff_flag = mix_coeff;
- pr_debug("%s: mix_coeff = %u\n", __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 %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM,
- ASM_PARAM_ID_AAC_STEREO_MIX_COEFF_SELECTION_FLAG_V2,
- rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n",
- __func__, aac_mix_coeff.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_cfg_aac_sel_mix_coef);
- /**
- * q6asm_enc_cfg_blk_qcelp -
- * command to set encode config block for QCELP
- *
- * @ac: Audio client handle
- * @frames_per_buf: Number of frames per buffer
- * @min_rate: Minimum Enc rate
- * @max_rate: Maximum Enc rate
- * reduced_rate_level: Reduced rate level
- * @rate_modulation_cmd: rate modulation command
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_enc_cfg_blk_qcelp(struct audio_client *ac, uint32_t frames_per_buf,
- uint16_t min_rate, uint16_t max_rate,
- uint16_t reduced_rate_level, uint16_t rate_modulation_cmd)
- {
- struct asm_v13k_enc_cfg enc_cfg;
- int rc = 0;
- pr_debug("%s: session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] reduced_rate_level[0x%4x]rate_modulation_cmd[0x%4x]\n",
- __func__,
- ac->session, frames_per_buf, min_rate, max_rate,
- reduced_rate_level, rate_modulation_cmd);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_v13k_enc_cfg) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.min_rate = min_rate;
- enc_cfg.max_rate = max_rate;
- enc_cfg.reduced_rate_cmd = reduced_rate_level;
- enc_cfg.rate_mod_cmd = rate_modulation_cmd;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd %d failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for setencdec v13k resp\n",
- __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_qcelp);
- /**
- * q6asm_enc_cfg_blk_evrc -
- * command to set encode config block for EVRC
- *
- * @ac: Audio client handle
- * @frames_per_buf: Number of frames per buffer
- * @min_rate: Minimum Enc rate
- * @max_rate: Maximum Enc rate
- * @rate_modulation_cmd: rate modulation command
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_enc_cfg_blk_evrc(struct audio_client *ac, uint32_t frames_per_buf,
- uint16_t min_rate, uint16_t max_rate,
- uint16_t rate_modulation_cmd)
- {
- struct asm_evrc_enc_cfg enc_cfg;
- int rc = 0;
- pr_debug("%s: session[%d]frames[%d]min_rate[0x%4x]max_rate[0x%4x] rate_modulation_cmd[0x%4x]\n",
- __func__, ac->session,
- frames_per_buf, min_rate, max_rate, rate_modulation_cmd);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_evrc_enc_cfg) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.min_rate = min_rate;
- enc_cfg.max_rate = max_rate;
- enc_cfg.rate_mod_cmd = rate_modulation_cmd;
- enc_cfg.reserved = 0;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd %d failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for encdec evrc\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_evrc);
- /**
- * q6asm_enc_cfg_blk_amrnb -
- * command to set encode config block for AMRNB
- *
- * @ac: Audio client handle
- * @frames_per_buf: Number of frames per buffer
- * @band_mode: Band mode used
- * @dtx_enable: DTX en flag
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_enc_cfg_blk_amrnb(struct audio_client *ac, uint32_t frames_per_buf,
- uint16_t band_mode, uint16_t dtx_enable)
- {
- struct asm_amrnb_enc_cfg enc_cfg;
- int rc = 0;
- pr_debug("%s: session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]\n",
- __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_amrnb_enc_cfg) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.enc_mode = band_mode;
- enc_cfg.dtx_mode = dtx_enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd %d failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for set encdec amrnb\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_amrnb);
- /**
- * q6asm_enc_cfg_blk_amrwb -
- * command to set encode config block for AMRWB
- *
- * @ac: Audio client handle
- * @frames_per_buf: Number of frames per buffer
- * @band_mode: Band mode used
- * @dtx_enable: DTX en flag
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_enc_cfg_blk_amrwb(struct audio_client *ac, uint32_t frames_per_buf,
- uint16_t band_mode, uint16_t dtx_enable)
- {
- struct asm_amrwb_enc_cfg enc_cfg;
- int rc = 0;
- pr_debug("%s: session[%d]frames[%d]band_mode[0x%4x]dtx_enable[0x%4x]\n",
- __func__, ac->session, frames_per_buf, band_mode, dtx_enable);
- q6asm_add_hdr(ac, &enc_cfg.hdr, sizeof(enc_cfg), TRUE);
- atomic_set(&ac->cmd_state, -1);
- enc_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- enc_cfg.encdec.param_id = ASM_PARAM_ID_ENCDEC_ENC_CFG_BLK_V2;
- enc_cfg.encdec.param_size = sizeof(struct asm_amrwb_enc_cfg) -
- sizeof(struct asm_stream_cmd_set_encdec_param);
- enc_cfg.encblk.frames_per_buf = frames_per_buf;
- enc_cfg.encblk.enc_cfg_blk_size = enc_cfg.encdec.param_size -
- sizeof(struct asm_enc_cfg_blk_param_v2);
- enc_cfg.enc_mode = band_mode;
- enc_cfg.dtx_mode = dtx_enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &enc_cfg);
- if (rc < 0) {
- pr_err("%s: Comamnd %d failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_enc_cfg_blk_amrwb);
- static int __q6asm_media_format_block_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample, int stream_id,
- bool use_default_chmap, char *channel_map)
- {
- struct asm_multi_channel_pcm_fmt_blk_v2 fmt;
- u8 *channel_mapping;
- int rc = 0;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
- channels);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&fmt.hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, fmt.hdr.token, stream_id, ac->session);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.num_channels = channels;
- fmt.bits_per_sample = bits_per_sample;
- fmt.sample_rate = rate;
- fmt.is_signed = 1;
- channel_mapping = fmt.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- return -EINVAL;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_media_format_block_pcm_v3(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- int stream_id,
- bool use_default_chmap,
- char *channel_map,
- uint16_t sample_word_size)
- {
- struct asm_multi_channel_pcm_fmt_blk_param_v3 fmt;
- u8 *channel_mapping;
- int rc;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- fmt.hdr.token = ((ac->session << 8) & 0xFFFF00) |
- (stream_id & 0xFF);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, fmt.hdr.token, stream_id, ac->session);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.param.num_channels = channels;
- fmt.param.bits_per_sample = bits_per_sample;
- fmt.param.sample_rate = rate;
- fmt.param.is_signed = 1;
- fmt.param.sample_word_size = sample_word_size;
- channel_mapping = fmt.param.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_media_format_block_pcm_v4(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- int stream_id,
- bool use_default_chmap,
- char *channel_map,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- struct asm_multi_channel_pcm_fmt_blk_param_v4 fmt;
- u8 *channel_mapping;
- int rc;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- fmt.hdr.token = ((ac->session << 8) & 0xFFFF00) |
- (stream_id & 0xFF);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, fmt.hdr.token, stream_id, ac->session);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.param.num_channels = channels;
- fmt.param.bits_per_sample = bits_per_sample;
- fmt.param.sample_rate = rate;
- fmt.param.is_signed = 1;
- fmt.param.sample_word_size = sample_word_size;
- fmt.param.endianness = endianness;
- fmt.param.mode = mode;
- channel_mapping = fmt.param.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_media_format_block_pcm_v5(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample,
- int stream_id,
- bool use_default_chmap,
- char *channel_map,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- struct asm_multi_channel_pcm_fmt_blk_param_v5 fmt;
- u8 *channel_mapping;
- int rc;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL_V8) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- fmt.hdr.token = ((ac->session << 8) & 0xFFFF00) |
- (stream_id & 0xFF);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, fmt.hdr.token, stream_id, ac->session);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.param.num_channels = (uint16_t) channels & 0xFFFF;
- fmt.param.bits_per_sample = bits_per_sample;
- fmt.param.sample_rate = rate;
- fmt.param.is_signed = 1;
- fmt.param.sample_word_size = sample_word_size;
- fmt.param.endianness = endianness;
- fmt.param.mode = mode;
- channel_mapping = fmt.param.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL_V8);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, fmt.param.num_channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL_V8);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, 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("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- /**
- * q6asm_media_format_block_pcm -
- * command to set mediafmt block for PCM on ASM stream
- *
- * @ac: Audio client handle
- * @rate: sample rate
- * @channels: number of ASM channels
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_media_format_block_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- return __q6asm_media_format_block_pcm(ac, rate,
- channels, 16, ac->stream_id,
- true, NULL);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_pcm);
- /**
- * q6asm_media_format_block_pcm_format_support -
- * command to set mediafmt block for PCM format support
- *
- * @ac: Audio client handle
- * @rate: sample rate
- * @channels: number of ASM channels
- * @bits_per_sample: number of bits per sample
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_media_format_block_pcm_format_support(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample)
- {
- return __q6asm_media_format_block_pcm(ac, rate,
- channels, bits_per_sample, ac->stream_id,
- true, NULL);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_pcm_format_support);
- int q6asm_media_format_block_pcm_format_support_v2(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- uint16_t bits_per_sample, int stream_id,
- bool use_default_chmap, char *channel_map)
- {
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- return -EINVAL;
- }
- return __q6asm_media_format_block_pcm(ac, rate,
- channels, bits_per_sample, stream_id,
- use_default_chmap, channel_map);
- }
- /*
- * q6asm_media_format_block_pcm_format_support_v3- sends pcm decoder
- * configuration parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @stream_id: stream id of stream to be associated with this session
- * @use_default_chmap: true if default channel map to be used
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- */
- int q6asm_media_format_block_pcm_format_support_v3(struct audio_client *ac,
- uint32_t rate,
- uint32_t channels,
- uint16_t bits_per_sample,
- int stream_id,
- bool use_default_chmap,
- char *channel_map,
- uint16_t sample_word_size)
- {
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- return -EINVAL;
- }
- return __q6asm_media_format_block_pcm_v3(ac, rate,
- channels, bits_per_sample, stream_id,
- use_default_chmap, channel_map,
- sample_word_size);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_pcm_format_support_v3);
- /*
- * q6asm_media_format_block_pcm_format_support_v4- sends pcm decoder
- * configuration parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @stream_id: stream id of stream to be associated with this session
- * @use_default_chmap: true if default channel map to be used
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- * @endianness: endianness of the pcm data
- * @mode: Mode to provide additional info about the pcm input data
- */
- int q6asm_media_format_block_pcm_format_support_v4(struct audio_client *ac,
- uint32_t rate,
- uint32_t channels,
- uint16_t bits_per_sample,
- int stream_id,
- bool use_default_chmap,
- char *channel_map,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- return -EINVAL;
- }
- return __q6asm_media_format_block_pcm_v4(ac, rate,
- channels, bits_per_sample, stream_id,
- use_default_chmap, channel_map,
- sample_word_size, endianness,
- mode);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_pcm_format_support_v4);
- /*
- * q6asm_media_format_block_pcm_format_support_v5- sends pcm decoder
- * configuration parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @stream_id: stream id of stream to be associated with this session
- * @use_default_chmap: true if default channel map to be used
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- * @endianness: endianness of the pcm data
- * @mode: Mode to provide additional info about the pcm input data
- */
- int q6asm_media_format_block_pcm_format_support_v5(struct audio_client *ac,
- uint32_t rate,
- uint32_t channels,
- uint16_t bits_per_sample,
- int stream_id,
- bool use_default_chmap,
- char *channel_map,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- if (!use_default_chmap && (channel_map == NULL)) {
- pr_err("%s: No valid chan map and can't use default\n",
- __func__);
- return -EINVAL;
- }
- return __q6asm_media_format_block_pcm_v5(ac, rate,
- channels, bits_per_sample, stream_id,
- use_default_chmap, channel_map,
- sample_word_size, endianness,
- mode);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_pcm_format_support_v5);
- static int __q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap, char *channel_map,
- uint16_t bits_per_sample)
- {
- struct asm_multi_channel_pcm_fmt_blk_v2 fmt;
- u8 *channel_mapping;
- int rc = 0;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]\n", __func__, ac->session, rate,
- channels);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.num_channels = channels;
- fmt.bits_per_sample = bits_per_sample;
- fmt.sample_rate = rate;
- fmt.is_signed = 1;
- channel_mapping = fmt.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- return -EINVAL;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_media_format_block_multi_ch_pcm_v3(struct audio_client *ac,
- uint32_t rate,
- uint32_t channels,
- bool use_default_chmap,
- char *channel_map,
- uint16_t bits_per_sample,
- uint16_t sample_word_size)
- {
- struct asm_multi_channel_pcm_fmt_blk_param_v3 fmt;
- u8 *channel_mapping;
- int rc;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.param.num_channels = channels;
- fmt.param.bits_per_sample = bits_per_sample;
- fmt.param.sample_rate = rate;
- fmt.param.is_signed = 1;
- fmt.param.sample_word_size = sample_word_size;
- channel_mapping = fmt.param.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_media_format_block_multi_ch_pcm_v4(struct audio_client *ac,
- uint32_t rate,
- uint32_t channels,
- bool use_default_chmap,
- char *channel_map,
- uint16_t bits_per_sample,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- struct asm_multi_channel_pcm_fmt_blk_param_v4 fmt;
- u8 *channel_mapping;
- int rc;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.param.num_channels = channels;
- fmt.param.bits_per_sample = bits_per_sample;
- fmt.param.sample_rate = rate;
- fmt.param.is_signed = 1;
- fmt.param.sample_word_size = sample_word_size;
- fmt.param.endianness = endianness;
- fmt.param.mode = mode;
- channel_mapping = fmt.param.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- static int __q6asm_media_format_block_multi_ch_pcm_v5(struct audio_client *ac,
- uint32_t rate,
- uint32_t channels,
- bool use_default_chmap,
- char *channel_map,
- uint16_t bits_per_sample,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- struct asm_multi_channel_pcm_fmt_blk_param_v5 fmt;
- u8 *channel_mapping;
- int rc;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL_V8) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]wordsize[%d]\n", __func__,
- ac->session, rate, channels,
- bits_per_sample, sample_word_size);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.param.num_channels = channels;
- fmt.param.bits_per_sample = bits_per_sample;
- fmt.param.sample_rate = rate;
- fmt.param.is_signed = 1;
- fmt.param.sample_word_size = sample_word_size;
- fmt.param.endianness = endianness;
- fmt.param.mode = mode;
- channel_mapping = fmt.param.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL_V8);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto fail_cmd;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL_V8);
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, 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 format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap, char *channel_map)
- {
- return __q6asm_media_format_block_multi_ch_pcm(ac, rate,
- channels, use_default_chmap, channel_map, 16);
- }
- int q6asm_media_format_block_multi_ch_pcm_v2(
- struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap, char *channel_map,
- uint16_t bits_per_sample)
- {
- return __q6asm_media_format_block_multi_ch_pcm(ac, rate,
- channels, use_default_chmap, channel_map,
- bits_per_sample);
- }
- /*
- * q6asm_media_format_block_multi_ch_pcm_v3 - sends pcm decoder configuration
- * parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @use_default_chmap: true if default channel map to be used
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- */
- int q6asm_media_format_block_multi_ch_pcm_v3(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap,
- char *channel_map,
- uint16_t bits_per_sample,
- uint16_t sample_word_size)
- {
- return __q6asm_media_format_block_multi_ch_pcm_v3(ac, rate, channels,
- use_default_chmap,
- channel_map,
- bits_per_sample,
- sample_word_size);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_multi_ch_pcm_v3);
- /*
- * q6asm_media_format_block_multi_ch_pcm_v4 - sends pcm decoder configuration
- * parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @use_default_chmap: true if default channel map to be used
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- * @endianness: endianness of the pcm data
- * @mode: Mode to provide additional info about the pcm input data
- */
- int q6asm_media_format_block_multi_ch_pcm_v4(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap,
- char *channel_map,
- uint16_t bits_per_sample,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- return __q6asm_media_format_block_multi_ch_pcm_v4(ac, rate, channels,
- use_default_chmap,
- channel_map,
- bits_per_sample,
- sample_word_size,
- endianness,
- mode);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_multi_ch_pcm_v4);
- /*
- * q6asm_media_format_block_multi_ch_pcm_v5 - sends pcm decoder configuration
- * parameters
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @bits_per_sample: bit width of encoder session
- * @use_default_chmap: true if default channel map to be used
- * @channel_map: input channel map
- * @sample_word_size: Size in bits of the word that holds a sample of a channel
- * @endianness: endianness of the pcm data
- * @mode: Mode to provide additional info about the pcm input data
- */
- int q6asm_media_format_block_multi_ch_pcm_v5(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap,
- char *channel_map,
- uint16_t bits_per_sample,
- uint16_t sample_word_size,
- uint16_t endianness,
- uint16_t mode)
- {
- return __q6asm_media_format_block_multi_ch_pcm_v5(ac, rate, channels,
- use_default_chmap,
- channel_map,
- bits_per_sample,
- sample_word_size,
- endianness,
- mode);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_multi_ch_pcm_v5);
- /*
- * q6asm_media_format_block_gen_compr - set up generic compress format params
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- * @use_default_chmap: true if default channel map to be used
- * @channel_map: input channel map
- * @bits_per_sample: bit width of gen compress stream
- */
- int q6asm_media_format_block_gen_compr(struct audio_client *ac,
- uint32_t rate, uint32_t channels,
- bool use_default_chmap, char *channel_map,
- uint16_t bits_per_sample)
- {
- struct asm_generic_compressed_fmt_blk_t fmt;
- u8 *channel_mapping;
- int rc = 0;
- if (channels > PCM_FORMAT_MAX_NUM_CHANNEL) {
- pr_err("%s: Invalid channel count %d\n", __func__, channels);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]rate[%d]ch[%d]bps[%d]\n",
- __func__, ac->session, rate,
- channels, bits_per_sample);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.num_channels = channels;
- fmt.bits_per_sample = bits_per_sample;
- fmt.sampling_rate = rate;
- channel_mapping = fmt.channel_mapping;
- memset(channel_mapping, 0, PCM_FORMAT_MAX_NUM_CHANNEL);
- if (use_default_chmap) {
- if (q6asm_map_channels(channel_mapping, channels, false)) {
- pr_err("%s: map channels failed %d\n",
- __func__, channels);
- return -EINVAL;
- }
- } else {
- memcpy(channel_mapping, channel_map,
- PCM_FORMAT_MAX_NUM_CHANNEL);
- }
- atomic_set(&ac->cmd_state, -1);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_gen_compr);
- /*
- * q6asm_media_format_block_iec - set up IEC61937 (compressed) or IEC60958
- * (pcm) format params. Both audio standards
- * use the same format and are used for
- * HDMI or SPDIF.
- *
- * @ac: Client session handle
- * @rate: sample rate
- * @channels: number of channels
- */
- int q6asm_media_format_block_iec(struct audio_client *ac,
- uint32_t rate, uint32_t channels)
- {
- struct asm_iec_compressed_fmt_blk_t fmt;
- int rc = 0;
- pr_debug("%s: session[%d]rate[%d]ch[%d]\n",
- __func__, ac->session, rate,
- channels);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- fmt.hdr.opcode = ASM_DATA_CMD_IEC_60958_MEDIA_FMT;
- fmt.num_channels = channels;
- fmt.sampling_rate = rate;
- atomic_set(&ac->cmd_state, -1);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for format update\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_iec);
- static int __q6asm_media_format_block_multi_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg, int stream_id)
- {
- struct asm_aac_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s: session[%d]rate[%d]ch[%d]\n", __func__, ac->session,
- cfg->sample_rate, cfg->ch_cfg);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&fmt.hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, fmt.hdr.token, stream_id, ac->session);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmt_blk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmt_blk);
- fmt.aac_fmt_flag = cfg->format;
- fmt.audio_objype = cfg->aot;
- /* If zero, PCE is assumed to be available in bitstream*/
- fmt.total_size_of_PCE_bits = 0;
- fmt.channel_config = cfg->ch_cfg;
- fmt.sample_rate = cfg->sample_rate;
- pr_debug("%s: format=0x%x cfg_size=%d aac-cfg=0x%x aot=%d ch=%d sr=%d\n",
- __func__, fmt.aac_fmt_flag, fmt.fmt_blk.fmt_blk_size,
- fmt.aac_fmt_flag,
- fmt.audio_objype,
- fmt.channel_config,
- fmt.sample_rate);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- /**
- * q6asm_media_format_block_multi_aac -
- * command to set mediafmt block for multi_aac on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: multi_aac config
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_media_format_block_multi_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg)
- {
- return __q6asm_media_format_block_multi_aac(ac, cfg, ac->stream_id);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_multi_aac);
- /**
- * q6asm_media_format_block_aac -
- * command to set mediafmt block for aac on ASM
- *
- * @ac: Audio client handle
- * @cfg: aac config
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_media_format_block_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg)
- {
- return __q6asm_media_format_block_multi_aac(ac, cfg, ac->stream_id);
- }
- EXPORT_SYMBOL(q6asm_media_format_block_aac);
- /**
- * q6asm_stream_media_format_block_aac -
- * command to set mediafmt block for aac on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: aac config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_stream_media_format_block_aac(struct audio_client *ac,
- struct asm_aac_cfg *cfg, int stream_id)
- {
- return __q6asm_media_format_block_multi_aac(ac, cfg, stream_id);
- }
- EXPORT_SYMBOL(q6asm_stream_media_format_block_aac);
- /**
- * q6asm_media_format_block_wma -
- * command to set mediafmt block for wma on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: wma config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_media_format_block_wma(struct audio_client *ac,
- void *cfg, int stream_id)
- {
- struct asm_wmastdv9_fmt_blk_v2 fmt;
- struct asm_wma_cfg *wma_cfg = (struct asm_wma_cfg *)cfg;
- int rc = 0;
- pr_debug("session[%d]format_tag[0x%4x] rate[%d] ch[0x%4x] bps[%d], balign[0x%4x], bit_sample[0x%4x], ch_msk[%d], enc_opt[0x%4x]\n",
- ac->session, wma_cfg->format_tag, wma_cfg->sample_rate,
- wma_cfg->ch_cfg, wma_cfg->avg_bytes_per_sec,
- wma_cfg->block_align, wma_cfg->valid_bits_per_sample,
- wma_cfg->ch_mask, wma_cfg->encode_opt);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.fmtag = wma_cfg->format_tag;
- fmt.num_channels = wma_cfg->ch_cfg;
- fmt.sample_rate = wma_cfg->sample_rate;
- fmt.avg_bytes_per_sec = wma_cfg->avg_bytes_per_sec;
- fmt.blk_align = wma_cfg->block_align;
- fmt.bits_per_sample =
- wma_cfg->valid_bits_per_sample;
- fmt.channel_mask = wma_cfg->ch_mask;
- fmt.enc_options = wma_cfg->encode_opt;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_wma);
- /**
- * q6asm_media_format_block_wmapro -
- * command to set mediafmt block for wmapro on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: wmapro config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_media_format_block_wmapro(struct audio_client *ac,
- void *cfg, int stream_id)
- {
- struct asm_wmaprov10_fmt_blk_v2 fmt;
- struct asm_wmapro_cfg *wmapro_cfg = (struct asm_wmapro_cfg *)cfg;
- int rc = 0;
- pr_debug("%s: 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",
- __func__,
- 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_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.fmtag = wmapro_cfg->format_tag;
- fmt.num_channels = wmapro_cfg->ch_cfg;
- fmt.sample_rate = wmapro_cfg->sample_rate;
- fmt.avg_bytes_per_sec =
- wmapro_cfg->avg_bytes_per_sec;
- fmt.blk_align = wmapro_cfg->block_align;
- fmt.bits_per_sample = wmapro_cfg->valid_bits_per_sample;
- fmt.channel_mask = wmapro_cfg->ch_mask;
- fmt.enc_options = wmapro_cfg->encode_opt;
- fmt.usAdvancedEncodeOpt = wmapro_cfg->adv_encode_opt;
- fmt.advanced_enc_options2 = wmapro_cfg->adv_encode_opt2;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd open failed %d\n", __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_wmapro);
- /**
- * q6asm_media_format_block_amrwbplus -
- * command to set mediafmt block for amrwbplus on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: amrwbplus config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_media_format_block_amrwbplus(struct audio_client *ac,
- struct asm_amrwbplus_cfg *cfg)
- {
- struct asm_amrwbplus_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s: session[%d]band-mode[%d]frame-fmt[%d]ch[%d]\n",
- __func__,
- ac->session,
- cfg->amr_band_mode,
- cfg->amr_frame_fmt,
- cfg->num_channels);
- q6asm_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.amr_frame_fmt = cfg->amr_frame_fmt;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Comamnd media format update failed.. %d\n",
- __func__, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_amrwbplus);
- /**
- * q6asm_stream_media_format_block_flac -
- * command to set mediafmt block for flac on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: FLAC config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_stream_media_format_block_flac(struct audio_client *ac,
- struct asm_flac_cfg *cfg, int stream_id)
- {
- struct asm_flac_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s :session[%d] rate[%d] ch[%d] size[%d] stream_id[%d]\n",
- __func__, ac->session, cfg->sample_rate, cfg->ch_cfg,
- cfg->sample_size, stream_id);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.is_stream_info_present = cfg->stream_info_present;
- fmt.num_channels = cfg->ch_cfg;
- fmt.min_blk_size = cfg->min_blk_size;
- fmt.max_blk_size = cfg->max_blk_size;
- fmt.sample_rate = cfg->sample_rate;
- fmt.min_frame_size = cfg->min_frame_size;
- fmt.max_frame_size = cfg->max_frame_size;
- fmt.sample_size = cfg->sample_size;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s :Comamnd media format update failed %d\n",
- __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s :timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_stream_media_format_block_flac);
- /**
- * q6asm_media_format_block_alac -
- * command to set mediafmt block for alac on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: ALAC config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_media_format_block_alac(struct audio_client *ac,
- struct asm_alac_cfg *cfg, int stream_id)
- {
- struct asm_alac_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s :session[%d]rate[%d]ch[%d]\n", __func__,
- ac->session, cfg->sample_rate, cfg->num_channels);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.frame_length = cfg->frame_length;
- fmt.compatible_version = cfg->compatible_version;
- fmt.bit_depth = cfg->bit_depth;
- fmt.pb = cfg->pb;
- fmt.mb = cfg->mb;
- fmt.kb = cfg->kb;
- fmt.num_channels = cfg->num_channels;
- fmt.max_run = cfg->max_run;
- fmt.max_frame_bytes = cfg->max_frame_bytes;
- fmt.avg_bit_rate = cfg->avg_bit_rate;
- fmt.sample_rate = cfg->sample_rate;
- fmt.channel_layout_tag = cfg->channel_layout_tag;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s :Comamnd media format update failed %d\n",
- __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s :timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_alac);
- /*
- * q6asm_media_format_block_g711 - sends g711 decoder configuration
- * parameters
- * @ac: Client session handle
- * @cfg: Audio stream manager configuration parameters
- * @stream_id: Stream id
- */
- int q6asm_media_format_block_g711(struct audio_client *ac,
- struct asm_g711_dec_cfg *cfg, int stream_id)
- {
- struct asm_g711_dec_fmt_blk_v2 fmt;
- int rc = 0;
- if (!ac) {
- pr_err("%s: audio client is null\n", __func__);
- return -EINVAL;
- }
- if (!cfg) {
- pr_err("%s: Invalid ASM config\n", __func__);
- return -EINVAL;
- }
- if (stream_id <= 0) {
- pr_err("%s: Invalid stream id\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s :session[%d]rate[%d]\n", __func__,
- ac->session, cfg->sample_rate);
- memset(&fmt, 0, sizeof(struct asm_g711_dec_fmt_blk_v2));
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.sample_rate = cfg->sample_rate;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s :Command media format update failed %d\n",
- __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s :timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_g711);
- /**
- * q6asm_stream_media_format_block_vorbis -
- * command to set mediafmt block for vorbis on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: vorbis config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_stream_media_format_block_vorbis(struct audio_client *ac,
- struct asm_vorbis_cfg *cfg, int stream_id)
- {
- struct asm_vorbis_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s :session[%d] bit_stream_fmt[%d] stream_id[%d]\n",
- __func__, ac->session, cfg->bit_stream_fmt, stream_id);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.bit_stream_fmt = cfg->bit_stream_fmt;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s :Comamnd media format update failed %d\n",
- __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s :timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_stream_media_format_block_vorbis);
- /**
- * q6asm_media_format_block_ape -
- * command to set mediafmt block for APE on ASM stream
- *
- * @ac: Audio client handle
- * @cfg: APE config
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_media_format_block_ape(struct audio_client *ac,
- struct asm_ape_cfg *cfg, int stream_id)
- {
- struct asm_ape_fmt_blk_v2 fmt;
- int rc = 0;
- pr_debug("%s :session[%d]rate[%d]ch[%d]\n", __func__,
- ac->session, cfg->sample_rate, cfg->num_channels);
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.compatible_version = cfg->compatible_version;
- fmt.compression_level = cfg->compression_level;
- fmt.format_flags = cfg->format_flags;
- fmt.blocks_per_frame = cfg->blocks_per_frame;
- fmt.final_frame_blocks = cfg->final_frame_blocks;
- fmt.total_frames = cfg->total_frames;
- fmt.bits_per_sample = cfg->bits_per_sample;
- fmt.num_channels = cfg->num_channels;
- fmt.sample_rate = cfg->sample_rate;
- fmt.seek_table_present = cfg->seek_table_present;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s :Comamnd media format update failed %d\n",
- __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s :timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_ape);
- /*
- * q6asm_media_format_block_dsd- Sends DSD Decoder
- * configuration parameters
- *
- * @ac: Client session handle
- * @cfg: DSD Media Format Configuration.
- * @stream_id: stream id of stream to be associated with this session
- *
- * Return 0 on success or negative error code on failure
- */
- int q6asm_media_format_block_dsd(struct audio_client *ac,
- struct asm_dsd_cfg *cfg, int stream_id)
- {
- struct asm_dsd_fmt_blk_v2 fmt;
- int rc;
- pr_debug("%s: session[%d] data_rate[%d] ch[%d]\n", __func__,
- ac->session, cfg->dsd_data_rate, cfg->num_channels);
- memset(&fmt, 0, sizeof(fmt));
- q6asm_stream_add_hdr(ac, &fmt.hdr, sizeof(fmt), TRUE, stream_id);
- fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- fmt.fmtblk.fmt_blk_size = sizeof(fmt) - sizeof(fmt.hdr) -
- sizeof(fmt.fmtblk);
- fmt.num_version = cfg->num_version;
- fmt.is_bitwise_big_endian = cfg->is_bitwise_big_endian;
- fmt.dsd_channel_block_size = cfg->dsd_channel_block_size;
- fmt.num_channels = cfg->num_channels;
- fmt.dsd_data_rate = cfg->dsd_data_rate;
- atomic_set(&ac->cmd_state, -1);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &fmt);
- if (rc < 0) {
- pr_err("%s: Command DSD media format update failed, err: %d\n",
- __func__, rc);
- goto done;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for DSD FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto done;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto done;
- }
- return 0;
- done:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_media_format_block_dsd);
- /**
- * q6asm_stream_media_format_block_aptx_dec -
- * command to set mediafmt block for APTX dec on ASM stream
- *
- * @ac: Audio client handle
- * @srate: sample rate
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_stream_media_format_block_aptx_dec(struct audio_client *ac,
- uint32_t srate, int stream_id)
- {
- struct asm_aptx_dec_fmt_blk_v2 aptx_fmt;
- int rc = 0;
- if (!ac->session) {
- pr_err("%s: ac session invalid\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- pr_debug("%s :session[%d] rate[%d] stream_id[%d]\n",
- __func__, ac->session, srate, stream_id);
- q6asm_stream_add_hdr(ac, &aptx_fmt.hdr, sizeof(aptx_fmt), TRUE,
- stream_id);
- atomic_set(&ac->cmd_state, -1);
- aptx_fmt.hdr.opcode = ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2;
- aptx_fmt.fmtblk.fmt_blk_size = sizeof(aptx_fmt) - sizeof(aptx_fmt.hdr) -
- sizeof(aptx_fmt.fmtblk);
- aptx_fmt.sample_rate = srate;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &aptx_fmt);
- if (rc < 0) {
- pr_err("%s :Comamnd media format update failed %d\n",
- __func__, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s :timeout. waited for FORMAT_UPDATE\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_stream_media_format_block_aptx_dec);
- static int __q6asm_ds1_set_endp_params(struct audio_client *ac, int param_id,
- int param_value, int stream_id)
- {
- struct asm_dec_ddp_endp_param_v2 ddp_cfg;
- int rc = 0;
- pr_debug("%s: session[%d] stream[%d],param_id[%d]param_value[%d]",
- __func__, ac->session, stream_id, param_id, param_value);
- q6asm_stream_add_hdr(ac, &ddp_cfg.hdr, sizeof(ddp_cfg), TRUE,
- stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&ddp_cfg.hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- ddp_cfg.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- ddp_cfg.encdec.param_id = param_id;
- ddp_cfg.encdec.param_size = sizeof(struct asm_dec_ddp_endp_param_v2) -
- (sizeof(struct apr_hdr) +
- sizeof(struct asm_stream_cmd_set_encdec_param));
- ddp_cfg.endp_param_value = param_value;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &ddp_cfg);
- if (rc < 0) {
- pr_err("%s: Command opcode[0x%x] failed %d\n",
- __func__, ASM_STREAM_CMD_SET_ENCDEC_PARAM, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout opcode[0x%x]\n", __func__,
- ddp_cfg.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- /**
- * q6asm_ds1_set_endp_params -
- * command to set DS1 params for ASM
- *
- * @ac: Audio client handle
- * @param_id: param id
- * @param_value: value of param
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_ds1_set_endp_params(struct audio_client *ac,
- int param_id, int param_value)
- {
- return __q6asm_ds1_set_endp_params(ac, param_id, param_value,
- ac->stream_id);
- }
- /**
- * q6asm_ds1_set_stream_endp_params -
- * command to set DS1 params for ASM stream
- *
- * @ac: Audio client handle
- * @param_id: param id
- * @param_value: value of param
- * @stream_id: stream ID info
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_ds1_set_stream_endp_params(struct audio_client *ac,
- int param_id, int param_value,
- int stream_id)
- {
- return __q6asm_ds1_set_endp_params(ac, param_id, param_value,
- stream_id);
- }
- EXPORT_SYMBOL(q6asm_ds1_set_stream_endp_params);
- /**
- * q6asm_memory_map -
- * command to send memory map for ASM
- *
- * @ac: Audio client handle
- * @buf_add: buffer address to map
- * @dir: RX or TX session
- * @bufsz: size of each buffer
- * @bufcnt: buffer count
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_memory_map(struct audio_client *ac, phys_addr_t buf_add, int dir,
- uint32_t bufsz, uint32_t bufcnt)
- {
- struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL;
- struct avs_shared_map_region_payload *mregions = NULL;
- struct audio_port_data *port = NULL;
- void *mmap_region_cmd = NULL;
- void *payload = NULL;
- struct asm_buffer_node *buffer_node = NULL;
- int rc = 0;
- int cmd_size = 0;
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->mmap_apr == NULL) {
- pr_err("%s: mmap APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- buffer_node = kmalloc(sizeof(struct asm_buffer_node), GFP_KERNEL);
- if (!buffer_node)
- return -ENOMEM;
- cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions)
- + sizeof(struct avs_shared_map_region_payload) * bufcnt;
- mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
- if (mmap_region_cmd == NULL) {
- rc = -EINVAL;
- kfree(buffer_node);
- return rc;
- }
- mmap_regions = (struct avs_cmd_shared_mem_map_regions *)
- mmap_region_cmd;
- q6asm_add_mmaphdr(ac, &mmap_regions->hdr, cmd_size, dir);
- atomic_set(&ac->mem_state, -1);
- mmap_regions->hdr.opcode = ASM_CMD_SHARED_MEM_MAP_REGIONS;
- mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
- mmap_regions->num_regions = bufcnt & 0x00ff;
- mmap_regions->property_flag = 0x00;
- payload = ((u8 *) mmap_region_cmd +
- sizeof(struct avs_cmd_shared_mem_map_regions));
- mregions = (struct avs_shared_map_region_payload *)payload;
- ac->port[dir].tmp_hdl = 0;
- port = &ac->port[dir];
- pr_debug("%s: buf_add 0x%pK, bufsz: %d\n", __func__,
- &buf_add, bufsz);
- mregions->shm_addr_lsw = lower_32_bits(buf_add);
- mregions->shm_addr_msw = msm_audio_populate_upper_32_bits(buf_add);
- mregions->mem_size_bytes = bufsz;
- ++mregions;
- rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) mmap_region_cmd);
- if (rc < 0) {
- pr_err("%s: mmap op[0x%x]rc[%d]\n", __func__,
- mmap_regions->hdr.opcode, rc);
- rc = -EINVAL;
- kfree(buffer_node);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) >= 0 &&
- ac->port[dir].tmp_hdl),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for memory_map\n", __func__);
- rc = -ETIMEDOUT;
- kfree(buffer_node);
- goto fail_cmd;
- }
- if (atomic_read(&ac->mem_state) > 0) {
- pr_err("%s: DSP returned error[%s] for memory_map\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->mem_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->mem_state));
- kfree(buffer_node);
- goto fail_cmd;
- }
- buffer_node->buf_phys_addr = buf_add;
- buffer_node->mmap_hdl = ac->port[dir].tmp_hdl;
- list_add_tail(&buffer_node->list, &ac->port[dir].mem_map_handle);
- ac->port[dir].tmp_hdl = 0;
- rc = 0;
- fail_cmd:
- kfree(mmap_region_cmd);
- return rc;
- }
- EXPORT_SYMBOL(q6asm_memory_map);
- /**
- * q6asm_memory_unmap -
- * command to send memory unmap for ASM
- *
- * @ac: Audio client handle
- * @buf_add: buffer address to unmap
- * @dir: RX or TX session
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_memory_unmap(struct audio_client *ac, phys_addr_t buf_add, int dir)
- {
- struct avs_cmd_shared_mem_unmap_regions mem_unmap;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- int rc = 0;
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (this_mmap.apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- q6asm_add_mmaphdr(ac, &mem_unmap.hdr,
- sizeof(struct avs_cmd_shared_mem_unmap_regions),
- dir);
- atomic_set(&ac->mem_state, -1);
- mem_unmap.hdr.opcode = ASM_CMD_SHARED_MEM_UNMAP_REGIONS;
- mem_unmap.mem_map_handle = 0;
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == buf_add) {
- pr_debug("%s: Found the element\n", __func__);
- mem_unmap.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- pr_debug("%s: mem_unmap-mem_map_handle: 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- if (mem_unmap.mem_map_handle == 0) {
- pr_err("%s: Do not send null mem handle to DSP\n", __func__);
- rc = 0;
- goto fail_cmd;
- }
- rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) &mem_unmap);
- if (rc < 0) {
- pr_err("%s: mem_unmap op[0x%x]rc[%d]\n", __func__,
- mem_unmap.hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for memory_unmap of handle 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- } else if (atomic_read(&ac->mem_state) > 0) {
- pr_err("%s DSP returned error [%s] map handle 0x%x\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->mem_state)),
- mem_unmap.mem_map_handle);
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->mem_state));
- goto fail_cmd;
- } else if (atomic_read(&ac->unmap_cb_success) == 0) {
- pr_err("%s: Error in mem unmap callback of handle 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == buf_add) {
- list_del(&buf_node->list);
- kfree(buf_node);
- break;
- }
- }
- return rc;
- }
- EXPORT_SYMBOL(q6asm_memory_unmap);
- /**
- * q6asm_memory_map_regions -
- * command to send memory map regions for ASM
- *
- * @ac: Audio client handle
- * @dir: RX or TX session
- * @bufsz: size of each buffer
- * @bufcnt: buffer count
- * @is_contiguous: alloc contiguous mem or not
- *
- * Returns 0 on success or error on failure
- */
- static int q6asm_memory_map_regions(struct audio_client *ac, int dir,
- uint32_t bufsz, uint32_t bufcnt,
- bool is_contiguous)
- {
- struct avs_cmd_shared_mem_map_regions *mmap_regions = NULL;
- struct avs_shared_map_region_payload *mregions = NULL;
- struct audio_port_data *port = NULL;
- struct audio_buffer *ab = NULL;
- void *mmap_region_cmd = NULL;
- void *payload = NULL;
- struct asm_buffer_node *buffer_node = NULL;
- int rc = 0;
- int i = 0;
- uint32_t cmd_size = 0;
- uint32_t bufcnt_t;
- uint32_t bufsz_t;
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->mmap_apr == NULL) {
- pr_err("%s: mmap APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- bufcnt_t = (is_contiguous) ? 1 : bufcnt;
- bufsz_t = (is_contiguous) ? (bufsz * bufcnt) : bufsz;
- if (is_contiguous) {
- /* The size to memory map should be multiple of 4K bytes */
- bufsz_t = PAGE_ALIGN(bufsz_t);
- }
- if (bufcnt_t > (UINT_MAX
- - sizeof(struct avs_cmd_shared_mem_map_regions))
- / sizeof(struct avs_shared_map_region_payload)) {
- pr_err("%s: Unsigned Integer Overflow. bufcnt_t = %u\n",
- __func__, bufcnt_t);
- return -EINVAL;
- }
- cmd_size = sizeof(struct avs_cmd_shared_mem_map_regions)
- + (sizeof(struct avs_shared_map_region_payload)
- * bufcnt_t);
- if (bufcnt > (UINT_MAX / sizeof(struct asm_buffer_node))) {
- pr_err("%s: Unsigned Integer Overflow. bufcnt = %u\n",
- __func__, bufcnt);
- return -EINVAL;
- }
- buffer_node = kzalloc(sizeof(struct asm_buffer_node) * bufcnt,
- GFP_KERNEL);
- if (!buffer_node)
- return -ENOMEM;
- mmap_region_cmd = kzalloc(cmd_size, GFP_KERNEL);
- if (mmap_region_cmd == NULL) {
- rc = -EINVAL;
- kfree(buffer_node);
- return rc;
- }
- mmap_regions = (struct avs_cmd_shared_mem_map_regions *)
- mmap_region_cmd;
- q6asm_add_mmaphdr(ac, &mmap_regions->hdr, cmd_size, dir);
- atomic_set(&ac->mem_state, -1);
- pr_debug("%s: mmap_region=0x%pK token=0x%x\n", __func__,
- mmap_regions, ((ac->session << 8) | dir));
- mmap_regions->hdr.opcode = ASM_CMD_SHARED_MEM_MAP_REGIONS;
- mmap_regions->mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
- mmap_regions->num_regions = bufcnt_t; /*bufcnt & 0x00ff; */
- mmap_regions->property_flag = 0x00;
- pr_debug("%s: map_regions->nregions = %d\n", __func__,
- mmap_regions->num_regions);
- payload = ((u8 *) mmap_region_cmd +
- sizeof(struct avs_cmd_shared_mem_map_regions));
- mregions = (struct avs_shared_map_region_payload *)payload;
- ac->port[dir].tmp_hdl = 0;
- port = &ac->port[dir];
- for (i = 0; i < bufcnt_t; i++) {
- ab = &port->buf[i];
- mregions->shm_addr_lsw = lower_32_bits(ab->phys);
- mregions->shm_addr_msw =
- msm_audio_populate_upper_32_bits(ab->phys);
- mregions->mem_size_bytes = bufsz_t;
- ++mregions;
- }
- rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) mmap_region_cmd);
- if (rc < 0) {
- pr_err("%s: mmap_regions op[0x%x]rc[%d]\n", __func__,
- mmap_regions->hdr.opcode, rc);
- rc = -EINVAL;
- kfree(buffer_node);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) >= 0 &&
- ac->port[dir].tmp_hdl),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for memory_map\n", __func__);
- rc = -ETIMEDOUT;
- kfree(buffer_node);
- goto fail_cmd;
- }
- if (atomic_read(&ac->mem_state) > 0) {
- pr_err("%s DSP returned error for memory_map [%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->mem_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->mem_state));
- kfree(buffer_node);
- goto fail_cmd;
- }
- mutex_lock(&ac->cmd_lock);
- for (i = 0; i < bufcnt; i++) {
- ab = &port->buf[i];
- buffer_node[i].buf_phys_addr = ab->phys;
- buffer_node[i].mmap_hdl = ac->port[dir].tmp_hdl;
- list_add_tail(&buffer_node[i].list,
- &ac->port[dir].mem_map_handle);
- pr_debug("%s: i=%d, bufadd[i] = 0x%pK, maphdl[i] = 0x%x\n",
- __func__, i, &buffer_node[i].buf_phys_addr,
- buffer_node[i].mmap_hdl);
- }
- ac->port[dir].tmp_hdl = 0;
- mutex_unlock(&ac->cmd_lock);
- rc = 0;
- fail_cmd:
- kfree(mmap_region_cmd);
- return rc;
- }
- EXPORT_SYMBOL(q6asm_memory_map_regions);
- /**
- * q6asm_memory_unmap_regions -
- * command to send memory unmap regions for ASM
- *
- * @ac: Audio client handle
- * @dir: RX or TX session
- *
- * Returns 0 on success or error on failure
- */
- static int q6asm_memory_unmap_regions(struct audio_client *ac, int dir)
- {
- struct avs_cmd_shared_mem_unmap_regions mem_unmap;
- struct audio_port_data *port = NULL;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- phys_addr_t buf_add;
- int rc = 0;
- int cmd_size = 0;
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->mmap_apr == NULL) {
- pr_err("%s: mmap APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: Session[%d]\n", __func__, ac->session);
- cmd_size = sizeof(struct avs_cmd_shared_mem_unmap_regions);
- q6asm_add_mmaphdr(ac, &mem_unmap.hdr, cmd_size, dir);
- atomic_set(&ac->mem_state, -1);
- port = &ac->port[dir];
- buf_add = port->buf->phys;
- mem_unmap.hdr.opcode = ASM_CMD_SHARED_MEM_UNMAP_REGIONS;
- mem_unmap.mem_map_handle = 0;
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == buf_add) {
- pr_debug("%s: Found the element\n", __func__);
- mem_unmap.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- pr_debug("%s: mem_unmap-mem_map_handle: 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- if (mem_unmap.mem_map_handle == 0) {
- pr_err("%s: Do not send null mem handle to DSP\n", __func__);
- rc = 0;
- goto fail_cmd;
- }
- rc = apr_send_pkt(ac->mmap_apr, (uint32_t *) &mem_unmap);
- if (rc < 0) {
- pr_err("mmap_regions op[0x%x]rc[%d]\n",
- mem_unmap.hdr.opcode, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->mem_wait,
- (atomic_read(&ac->mem_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for memory_unmap of handle 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- } else if (atomic_read(&ac->mem_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->mem_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->mem_state));
- goto fail_cmd;
- } else if (atomic_read(&ac->unmap_cb_success) == 0) {
- pr_err("%s: Error in mem unmap callback of handle 0x%x\n",
- __func__, mem_unmap.mem_map_handle);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == buf_add) {
- list_del(&buf_node->list);
- kfree(buf_node);
- break;
- }
- }
- return rc;
- }
- EXPORT_SYMBOL(q6asm_memory_unmap_regions);
- int q6asm_set_lrgain(struct audio_client *ac, int left_gain, int right_gain)
- {
- struct asm_volume_ctrl_multichannel_gain multi_ch_gain;
- struct param_hdr_v3 param_info;
- int rc = 0;
- memset(¶m_info, 0, sizeof(param_info));
- memset(&multi_ch_gain, 0, sizeof(multi_ch_gain));
- param_info.module_id = ASM_MODULE_ID_VOL_CTRL;
- param_info.instance_id = INSTANCE_ID_0;
- param_info.param_id = ASM_PARAM_ID_MULTICHANNEL_GAIN;
- param_info.param_size = sizeof(multi_ch_gain);
- multi_ch_gain.gain_data[0].channeltype = PCM_CHANNEL_FL;
- multi_ch_gain.gain_data[0].gain = left_gain << 15;
- multi_ch_gain.gain_data[1].channeltype = PCM_CHANNEL_FR;
- multi_ch_gain.gain_data[1].gain = right_gain << 15;
- multi_ch_gain.num_channels = 2;
- rc = q6asm_pack_and_set_pp_param_in_band(ac, param_info,
- (u8 *) &multi_ch_gain);
- if (rc < 0)
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, param_info.param_id, rc);
- return rc;
- }
- /*
- * q6asm_set_multich_gain: set multiple channel gains on an ASM session
- * @ac: audio client handle
- * @channels: number of channels caller intends to set gains
- * @gains: list of gains of audio channels
- * @ch_map: list of channel mapping. Only valid if use_default is false
- * @use_default: flag to indicate whether to use default mapping
- */
- int q6asm_set_multich_gain(struct audio_client *ac, uint32_t channels,
- uint32_t *gains, uint8_t *ch_map, bool use_default)
- {
- struct asm_volume_ctrl_multichannel_gain multich_gain;
- struct param_hdr_v3 param_info;
- int rc = 0;
- int i;
- u8 default_chmap[VOLUME_CONTROL_MAX_CHANNELS];
- if (ac == NULL) {
- pr_err("%s: Audio client is NULL\n", __func__);
- return -EINVAL;
- }
- if (gains == NULL) {
- dev_err(ac->dev, "%s: gain_list is NULL\n", __func__);
- rc = -EINVAL;
- goto done;
- }
- if (channels > VOLUME_CONTROL_MAX_CHANNELS) {
- dev_err(ac->dev, "%s: Invalid channel count %d\n",
- __func__, channels);
- rc = -EINVAL;
- goto done;
- }
- if (!use_default && ch_map == NULL) {
- dev_err(ac->dev, "%s: NULL channel map\n", __func__);
- rc = -EINVAL;
- goto done;
- }
- memset(¶m_info, 0, sizeof(param_info));
- memset(&multich_gain, 0, sizeof(multich_gain));
- param_info.module_id = ASM_MODULE_ID_VOL_CTRL;
- param_info.instance_id = INSTANCE_ID_0;
- param_info.param_id = ASM_PARAM_ID_MULTICHANNEL_GAIN;
- param_info.param_size = sizeof(multich_gain);
- if (use_default) {
- rc = q6asm_map_channels(default_chmap, channels, false);
- if (rc < 0)
- goto done;
- for (i = 0; i < channels; i++) {
- multich_gain.gain_data[i].channeltype =
- default_chmap[i];
- multich_gain.gain_data[i].gain = gains[i] << 15;
- }
- } else {
- for (i = 0; i < channels; i++) {
- multich_gain.gain_data[i].channeltype = ch_map[i];
- multich_gain.gain_data[i].gain = gains[i] << 15;
- }
- }
- multich_gain.num_channels = channels;
- rc = q6asm_pack_and_set_pp_param_in_band(ac, param_info,
- (u8 *) &multich_gain);
- if (rc)
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, param_info.param_id, rc);
- done:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_set_multich_gain);
- /**
- * q6asm_set_mute -
- * command to set mute for ASM
- *
- * @ac: Audio client handle
- * @muteflag: mute value
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_set_mute(struct audio_client *ac, int muteflag)
- {
- struct asm_volume_ctrl_mute_config mute;
- struct param_hdr_v3 param_info;
- int rc = 0;
- memset(&mute, 0, sizeof(mute));
- memset(¶m_info, 0, sizeof(param_info));
- param_info.module_id = ASM_MODULE_ID_VOL_CTRL;
- param_info.instance_id = INSTANCE_ID_0;
- param_info.param_id = ASM_PARAM_ID_VOL_CTRL_MUTE_CONFIG;
- param_info.param_size = sizeof(mute);
- mute.mute_flag = muteflag;
- rc = q6asm_pack_and_set_pp_param_in_band(ac, param_info, (u8 *) &mute);
- if (rc)
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, param_info.param_id, rc);
- return rc;
- }
- EXPORT_SYMBOL(q6asm_set_mute);
- static int __q6asm_set_volume(struct audio_client *ac, int volume, int instance)
- {
- struct asm_volume_ctrl_master_gain vol;
- struct param_hdr_v3 param_info;
- int rc = 0;
- memset(&vol, 0, sizeof(vol));
- memset(¶m_info, 0, sizeof(param_info));
- rc = q6asm_set_soft_volume_module_instance_ids(instance, ¶m_info);
- if (rc) {
- pr_err("%s: Failed to pack soft volume module and instance IDs, error %d\n",
- __func__, rc);
- return rc;
- }
- param_info.param_id = ASM_PARAM_ID_VOL_CTRL_MASTER_GAIN;
- param_info.param_size = sizeof(vol);
- vol.master_gain = volume;
- rc = q6asm_pack_and_set_pp_param_in_band(ac, param_info, (u8 *) &vol);
- if (rc)
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, param_info.param_id, rc);
- return rc;
- }
- /**
- * q6asm_set_volume -
- * command to set volume for ASM
- *
- * @ac: Audio client handle
- * @volume: volume level
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_set_volume(struct audio_client *ac, int volume)
- {
- return __q6asm_set_volume(ac, volume, SOFT_VOLUME_INSTANCE_1);
- }
- EXPORT_SYMBOL(q6asm_set_volume);
- int q6asm_set_volume_v2(struct audio_client *ac, int volume, int instance)
- {
- return __q6asm_set_volume(ac, volume, instance);
- }
- /**
- * q6asm_set_aptx_dec_bt_addr -
- * command to aptx decoder BT addr for ASM
- *
- * @ac: Audio client handle
- * @cfg: APTX decoder bt addr config
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_set_aptx_dec_bt_addr(struct audio_client *ac,
- struct aptx_dec_bt_addr_cfg *cfg)
- {
- struct aptx_dec_bt_dev_addr paylod;
- int sz = 0;
- int rc = 0;
- pr_debug("%s: BT addr nap %d, uap %d, lap %d\n", __func__, cfg->nap,
- cfg->uap, cfg->lap);
- if (ac == NULL) {
- pr_err("%s: AC handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct aptx_dec_bt_dev_addr);
- q6asm_add_hdr_async(ac, &paylod.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- paylod.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM;
- paylod.encdec.param_id = APTX_DECODER_BT_ADDRESS;
- paylod.encdec.param_size = sz - sizeof(paylod.hdr)
- - sizeof(paylod.encdec);
- paylod.bt_addr_cfg.lap = cfg->lap;
- paylod.bt_addr_cfg.uap = cfg->uap;
- paylod.bt_addr_cfg.nap = cfg->nap;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &paylod);
- if (rc < 0) {
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, paylod.encdec.param_id, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout, set-params paramid[0x%x]\n", __func__,
- paylod.encdec.param_id);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s] set-params paramid[0x%x]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)),
- paylod.encdec.param_id);
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- pr_debug("%s: set BT addr is success\n", __func__);
- rc = 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_set_aptx_dec_bt_addr);
- /**
- * q6asm_send_ion_fd -
- * command to send ION memory map for ASM
- *
- * @ac: Audio client handle
- * @fd: ION file desc
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_send_ion_fd(struct audio_client *ac, int fd)
- {
- struct dma_buf *dma_buf;
- dma_addr_t paddr;
- size_t pa_len = 0;
- void *vaddr;
- int ret;
- int sz = 0;
- struct avs_rtic_shared_mem_addr shm;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- ret = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- ret = -EINVAL;
- goto fail_cmd;
- }
- ret = msm_audio_ion_import(&dma_buf,
- fd,
- NULL,
- 0,
- &paddr,
- &pa_len,
- &vaddr);
- if (ret) {
- pr_err("%s: audio ION import failed, rc = %d\n",
- __func__, ret);
- ret = -ENOMEM;
- goto fail_cmd;
- }
- /* get payload length */
- sz = sizeof(struct avs_rtic_shared_mem_addr);
- q6asm_add_hdr_async(ac, &shm.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- shm.shm_buf_addr_lsw = lower_32_bits(paddr);
- shm.shm_buf_addr_msw = msm_audio_populate_upper_32_bits(paddr);
- shm.buf_size = pa_len;
- shm.shm_buf_num_regions = 1;
- shm.shm_buf_mem_pool_id = ADSP_MEMORY_MAP_SHMEM8_4K_POOL;
- shm.shm_buf_flag = 0x00;
- shm.encdec.param_id = AVS_PARAM_ID_RTIC_SHARED_MEMORY_ADDR;
- shm.encdec.param_size = sizeof(struct avs_rtic_shared_mem_addr) -
- sizeof(struct apr_hdr) -
- sizeof(struct asm_stream_cmd_set_encdec_param_v2);
- shm.encdec.service_id = OUT;
- shm.encdec.reserved = 0;
- shm.map_region.shm_addr_lsw = shm.shm_buf_addr_lsw;
- shm.map_region.shm_addr_msw = shm.shm_buf_addr_msw;
- shm.map_region.mem_size_bytes = pa_len;
- shm.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM_V2;
- ret = apr_send_pkt(ac->apr, (uint32_t *) &shm);
- if (ret < 0) {
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, shm.encdec.param_id, ret);
- ret = -EINVAL;
- goto fail_cmd;
- }
- ret = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!ret) {
- pr_err("%s: timeout, shm.encdec paramid[0x%x]\n", __func__,
- shm.encdec.param_id);
- ret = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s] shm.encdec paramid[0x%x]\n",
- __func__,
- adsp_err_get_err_str(atomic_read(&ac->cmd_state)),
- shm.encdec.param_id);
- ret = adsp_err_get_lnx_err_code(atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- ret = 0;
- fail_cmd:
- return ret;
- }
- EXPORT_SYMBOL(q6asm_send_ion_fd);
- /**
- * q6asm_send_rtic_event_ack -
- * command to send RTIC event ack
- *
- * @ac: Audio client handle
- * @param: params for event ack
- * @params_length: length of params
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_send_rtic_event_ack(struct audio_client *ac,
- void *param, uint32_t params_length)
- {
- char *asm_params = NULL;
- int sz, rc;
- struct avs_param_rtic_event_ack ack;
- if (!param || !ac) {
- pr_err("%s: %s is NULL\n", __func__,
- (!param) ? "param" : "ac");
- rc = -EINVAL;
- goto done;
- }
- sz = sizeof(struct avs_param_rtic_event_ack) + params_length;
- asm_params = kzalloc(sz, GFP_KERNEL);
- if (!asm_params) {
- rc = -ENOMEM;
- goto done;
- }
- q6asm_add_hdr_async(ac, &ack.hdr,
- sizeof(struct avs_param_rtic_event_ack) +
- params_length, TRUE);
- atomic_set(&ac->cmd_state, -1);
- ack.hdr.opcode = ASM_STREAM_CMD_SET_ENCDEC_PARAM_V2;
- ack.encdec.param_id = AVS_PARAM_ID_RTIC_EVENT_ACK;
- ack.encdec.param_size = params_length;
- ack.encdec.reserved = 0;
- ack.encdec.service_id = OUT;
- memcpy(asm_params, &ack, sizeof(struct avs_param_rtic_event_ack));
- memcpy(asm_params + sizeof(struct avs_param_rtic_event_ack),
- param, params_length);
- rc = apr_send_pkt(ac->apr, (uint32_t *) asm_params);
- if (rc < 0) {
- pr_err("%s: apr pkt failed for rtic event ack\n", __func__);
- rc = -EINVAL;
- goto fail_send_param;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout for rtic event ack cmd\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_send_param;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s] for rtic event ack cmd\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_send_param;
- }
- rc = 0;
- fail_send_param:
- kfree(asm_params);
- done:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_send_rtic_event_ack);
- /**
- * q6asm_set_softpause -
- * command to set pause for ASM
- *
- * @ac: Audio client handle
- * @pause_param: params for pause
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_set_softpause(struct audio_client *ac,
- struct asm_softpause_params *pause_param)
- {
- struct asm_soft_pause_params softpause;
- struct param_hdr_v3 param_info;
- int rc = 0;
- memset(&softpause, 0, sizeof(softpause));
- memset(¶m_info, 0, sizeof(param_info));
- param_info.module_id = ASM_MODULE_ID_VOL_CTRL;
- param_info.instance_id = INSTANCE_ID_0;
- param_info.param_id = ASM_PARAM_ID_SOFT_PAUSE_PARAMETERS;
- param_info.param_size = sizeof(softpause);
- softpause.enable_flag = pause_param->enable;
- softpause.period = pause_param->period;
- softpause.step = pause_param->step;
- softpause.ramping_curve = pause_param->rampingcurve;
- rc = q6asm_pack_and_set_pp_param_in_band(ac, param_info,
- (u8 *) &softpause);
- if (rc)
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, param_info.param_id, rc);
- return rc;
- }
- EXPORT_SYMBOL(q6asm_set_softpause);
- static int __q6asm_set_softvolume(struct audio_client *ac,
- struct asm_softvolume_params *softvol_param,
- int instance)
- {
- struct asm_soft_step_volume_params softvol;
- struct param_hdr_v3 param_info;
- int rc = 0;
- memset(&softvol, 0, sizeof(softvol));
- memset(¶m_info, 0, sizeof(param_info));
- rc = q6asm_set_soft_volume_module_instance_ids(instance, ¶m_info);
- if (rc) {
- pr_err("%s: Failed to pack soft volume module and instance IDs, error %d\n",
- __func__, rc);
- return rc;
- }
- param_info.param_id = ASM_PARAM_ID_SOFT_VOL_STEPPING_PARAMETERS;
- param_info.param_size = sizeof(softvol);
- softvol.period = softvol_param->period;
- softvol.step = softvol_param->step;
- softvol.ramping_curve = softvol_param->rampingcurve;
- rc = q6asm_pack_and_set_pp_param_in_band(ac, param_info,
- (u8 *) &softvol);
- if (rc)
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, param_info.param_id, rc);
- return rc;
- }
- /**
- * q6asm_set_softvolume -
- * command to set softvolume for ASM
- *
- * @ac: Audio client handle
- * @softvol_param: params for softvol
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_set_softvolume(struct audio_client *ac,
- struct asm_softvolume_params *softvol_param)
- {
- return __q6asm_set_softvolume(ac, softvol_param,
- SOFT_VOLUME_INSTANCE_1);
- }
- EXPORT_SYMBOL(q6asm_set_softvolume);
- /**
- * q6asm_set_softvolume_v2 -
- * command to set softvolume V2 for ASM
- *
- * @ac: Audio client handle
- * @softvol_param: params for softvol
- * @instance: instance to apply softvol
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_set_softvolume_v2(struct audio_client *ac,
- struct asm_softvolume_params *softvol_param,
- int instance)
- {
- return __q6asm_set_softvolume(ac, softvol_param, instance);
- }
- EXPORT_SYMBOL(q6asm_set_softvolume_v2);
- /**
- * q6asm_equalizer -
- * command to set equalizer for ASM
- *
- * @ac: Audio client handle
- * @eq_p: Equalizer params
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_equalizer(struct audio_client *ac, void *eq_p)
- {
- struct asm_eq_params eq;
- struct msm_audio_eq_stream_config *eq_params = NULL;
- struct param_hdr_v3 param_info;
- int i = 0;
- int rc = 0;
- if (ac == NULL) {
- pr_err("%s: Audio client is NULL\n", __func__);
- return -EINVAL;
- }
- if (eq_p == NULL) {
- pr_err("%s: [%d]: Invalid Eq param\n", __func__, ac->session);
- rc = -EINVAL;
- goto fail_cmd;
- }
- memset(&eq, 0, sizeof(eq));
- memset(¶m_info, 0, sizeof(param_info));
- eq_params = (struct msm_audio_eq_stream_config *) eq_p;
- param_info.module_id = ASM_MODULE_ID_EQUALIZER;
- param_info.instance_id = INSTANCE_ID_0;
- param_info.param_id = ASM_PARAM_ID_EQUALIZER_PARAMETERS;
- param_info.param_size = sizeof(eq);
- eq.enable_flag = eq_params->enable;
- eq.num_bands = eq_params->num_bands;
- pr_debug("%s: enable:%d numbands:%d\n", __func__, eq_params->enable,
- eq_params->num_bands);
- for (i = 0; i < eq_params->num_bands; i++) {
- eq.eq_bands[i].band_idx =
- eq_params->eq_bands[i].band_idx;
- eq.eq_bands[i].filterype =
- eq_params->eq_bands[i].filter_type;
- eq.eq_bands[i].center_freq_hz =
- eq_params->eq_bands[i].center_freq_hz;
- eq.eq_bands[i].filter_gain =
- eq_params->eq_bands[i].filter_gain;
- eq.eq_bands[i].q_factor =
- eq_params->eq_bands[i].q_factor;
- pr_debug("%s: filter_type:%u bandnum:%d\n", __func__,
- eq_params->eq_bands[i].filter_type, i);
- pr_debug("%s: center_freq_hz:%u bandnum:%d\n", __func__,
- eq_params->eq_bands[i].center_freq_hz, i);
- pr_debug("%s: filter_gain:%d bandnum:%d\n", __func__,
- eq_params->eq_bands[i].filter_gain, i);
- pr_debug("%s: q_factor:%d bandnum:%d\n", __func__,
- eq_params->eq_bands[i].q_factor, i);
- }
- rc = q6asm_pack_and_set_pp_param_in_band(ac, param_info, (u8 *) &eq);
- if (rc)
- pr_err("%s: set-params send failed paramid[0x%x] rc %d\n",
- __func__, param_info.param_id, rc);
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_equalizer);
- static int __q6asm_read(struct audio_client *ac, bool is_custom_len_reqd,
- int len)
- {
- struct asm_data_cmd_read_v2 read;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- struct audio_buffer *ab;
- int dsp_buf;
- struct audio_port_data *port;
- int rc;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[OUT];
- q6asm_add_hdr(ac, &read.hdr, sizeof(read), FALSE);
- mutex_lock(&port->lock);
- dsp_buf = port->dsp_buf;
- if (port->buf == NULL) {
- pr_err("%s: buf is NULL\n", __func__);
- mutex_unlock(&port->lock);
- return -EINVAL;
- }
- ab = &port->buf[dsp_buf];
- dev_vdbg(ac->dev, "%s: session[%d]dsp-buf[%d][%pK]cpu_buf[%d][%pK]\n",
- __func__,
- ac->session,
- dsp_buf,
- port->buf[dsp_buf].data,
- port->cpu_buf,
- &port->buf[port->cpu_buf].phys);
- read.hdr.opcode = ASM_DATA_CMD_READ_V2;
- read.buf_addr_lsw = lower_32_bits(ab->phys);
- read.buf_addr_msw = msm_audio_populate_upper_32_bits(ab->phys);
- list_for_each_safe(ptr, next, &ac->port[OUT].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == ab->phys) {
- read.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- dev_vdbg(ac->dev, "memory_map handle in q6asm_read: [%0x]:",
- read.mem_map_handle);
- read.buf_size = is_custom_len_reqd ? len : ab->size;
- read.seq_id = port->dsp_buf;
- q6asm_update_token(&read.hdr.token,
- 0, /* Session ID is NA */
- 0, /* Stream ID is NA */
- port->dsp_buf,
- 0, /* Direction flag is NA */
- WAIT_CMD);
- port->dsp_buf = q6asm_get_next_buf(ac, port->dsp_buf,
- port->max_buf_cnt);
- mutex_unlock(&port->lock);
- dev_vdbg(ac->dev, "%s: buf add[%pK] token[0x%x] uid[%d]\n",
- __func__, &ab->phys, read.hdr.token,
- read.seq_id);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
- if (rc < 0) {
- pr_err("%s: read op[0x%x]rc[%d]\n",
- __func__, read.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- }
- fail_cmd:
- return -EINVAL;
- }
- /**
- * q6asm_read -
- * command to read buffer data from DSP
- *
- * @ac: Audio client handle
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_read(struct audio_client *ac)
- {
- return __q6asm_read(ac, false/*is_custom_len_reqd*/, 0);
- }
- EXPORT_SYMBOL(q6asm_read);
- /**
- * q6asm_read_v2 -
- * command to read buffer data from DSP
- *
- * @ac: Audio client handle
- * @len: buffer size to read
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_read_v2(struct audio_client *ac, uint32_t len)
- {
- return __q6asm_read(ac, true /*is_custom_len_reqd*/, len);
- }
- EXPORT_SYMBOL(q6asm_read_v2);
- /**
- * q6asm_read_nolock -
- * command to read buffer data from DSP
- * with no wait for ack.
- *
- * @ac: Audio client handle
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_read_nolock(struct audio_client *ac)
- {
- struct asm_data_cmd_read_v2 read;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- struct audio_buffer *ab;
- int dsp_buf;
- struct audio_port_data *port;
- int rc;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->io_mode & SYNC_IO_MODE) {
- port = &ac->port[OUT];
- q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
- dsp_buf = port->dsp_buf;
- ab = &port->buf[dsp_buf];
- dev_vdbg(ac->dev, "%s: session[%d]dsp-buf[%d][%pK]cpu_buf[%d][%pK]\n",
- __func__,
- ac->session,
- dsp_buf,
- port->buf[dsp_buf].data,
- port->cpu_buf,
- &port->buf[port->cpu_buf].phys);
- read.hdr.opcode = ASM_DATA_CMD_READ_V2;
- read.buf_addr_lsw = lower_32_bits(ab->phys);
- read.buf_addr_msw = msm_audio_populate_upper_32_bits(ab->phys);
- read.buf_size = ab->size;
- read.seq_id = port->dsp_buf;
- q6asm_update_token(&read.hdr.token,
- 0, /* Session ID is NA */
- 0, /* Stream ID is NA */
- port->dsp_buf,
- 0, /* Direction flag is NA */
- WAIT_CMD);
- list_for_each_safe(ptr, next, &ac->port[OUT].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == ab->phys) {
- read.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- port->dsp_buf = q6asm_get_next_buf(ac, port->dsp_buf,
- port->max_buf_cnt);
- dev_vdbg(ac->dev, "%s: buf add[%pK] token[0x%x] uid[%d]\n",
- __func__, &ab->phys, read.hdr.token,
- read.seq_id);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
- if (rc < 0) {
- pr_err("%s: read op[0x%x]rc[%d]\n",
- __func__, read.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- }
- fail_cmd:
- return -EINVAL;
- }
- EXPORT_SYMBOL(q6asm_read_nolock);
- /**
- * q6asm_async_write -
- * command to write DSP buffer
- *
- * @ac: Audio client handle
- * @param: params for async write
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_async_write(struct audio_client *ac,
- struct audio_aio_write_param *param)
- {
- int rc = 0;
- struct asm_data_cmd_write_v2 write;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- struct audio_buffer *ab;
- struct audio_port_data *port;
- phys_addr_t lbuf_phys_addr;
- u32 liomode;
- u32 io_compressed;
- u32 io_compressed_stream;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err_ratelimited("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_stream_add_hdr_async(
- ac, &write.hdr, sizeof(write), TRUE, ac->stream_id);
- port = &ac->port[IN];
- ab = &port->buf[port->dsp_buf];
- /* Pass session id as token for AIO scheme */
- write.hdr.token = param->uid;
- write.hdr.opcode = ASM_DATA_CMD_WRITE_V2;
- write.buf_addr_lsw = lower_32_bits(param->paddr);
- write.buf_addr_msw = msm_audio_populate_upper_32_bits(param->paddr);
- write.buf_size = param->len;
- write.timestamp_msw = param->msw_ts;
- write.timestamp_lsw = param->lsw_ts;
- liomode = (ASYNC_IO_MODE | NT_MODE);
- io_compressed = (ASYNC_IO_MODE | COMPRESSED_IO);
- io_compressed_stream = (ASYNC_IO_MODE | COMPRESSED_STREAM_IO);
- if (ac->io_mode == liomode)
- lbuf_phys_addr = (param->paddr - 32);
- else if (ac->io_mode == io_compressed ||
- ac->io_mode == io_compressed_stream)
- lbuf_phys_addr = (param->paddr - param->metadata_len);
- else {
- if (param->flags & SET_TIMESTAMP)
- lbuf_phys_addr = param->paddr -
- sizeof(struct snd_codec_metadata);
- else
- lbuf_phys_addr = param->paddr;
- }
- dev_vdbg(ac->dev, "%s: token[0x%x], buf_addr[%pK], buf_size[0x%x], ts_msw[0x%x], ts_lsw[0x%x], lbuf_phys_addr: 0x[%pK]\n",
- __func__,
- write.hdr.token, ¶m->paddr,
- write.buf_size, write.timestamp_msw,
- write.timestamp_lsw, &lbuf_phys_addr);
- /* Use 0xFF00 for disabling timestamps */
- if (param->flags == 0xFF00)
- write.flags = (0x00000000 | (param->flags & 0x800000FF));
- else
- write.flags = (0x80000000 | param->flags);
- write.flags |= param->last_buffer << ASM_SHIFT_LAST_BUFFER_FLAG;
- write.seq_id = param->uid;
- list_for_each_safe(ptr, next, &ac->port[IN].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == lbuf_phys_addr) {
- write.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
- if (rc < 0) {
- pr_err("%s: write op[0x%x]rc[%d]\n", __func__,
- write.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- EXPORT_SYMBOL(q6asm_async_write);
- /**
- * q6asm_async_read -
- * command to read DSP buffer
- *
- * @ac: Audio client handle
- * @param: params for async read
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_async_read(struct audio_client *ac,
- struct audio_aio_read_param *param)
- {
- int rc = 0;
- struct asm_data_cmd_read_v2 read;
- struct asm_buffer_node *buf_node = NULL;
- struct list_head *ptr, *next;
- phys_addr_t lbuf_phys_addr;
- u32 liomode;
- u32 io_compressed;
- int dir = 0;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err_ratelimited("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_add_hdr_async(ac, &read.hdr, sizeof(read), FALSE);
- /* Pass session id as token for AIO scheme */
- read.hdr.token = param->uid;
- read.hdr.opcode = ASM_DATA_CMD_READ_V2;
- read.buf_addr_lsw = lower_32_bits(param->paddr);
- read.buf_addr_msw = msm_audio_populate_upper_32_bits(param->paddr);
- read.buf_size = param->len;
- read.seq_id = param->uid;
- liomode = (NT_MODE | ASYNC_IO_MODE);
- io_compressed = (ASYNC_IO_MODE | COMPRESSED_IO);
- if (ac->io_mode == liomode) {
- lbuf_phys_addr = (param->paddr - 32);
- /*legacy wma driver case*/
- dir = IN;
- } else if (ac->io_mode == io_compressed) {
- lbuf_phys_addr = (param->paddr - 64);
- dir = OUT;
- } else {
- if (param->flags & COMPRESSED_TIMESTAMP_FLAG)
- lbuf_phys_addr = param->paddr -
- sizeof(struct snd_codec_metadata);
- else
- lbuf_phys_addr = param->paddr;
- dir = OUT;
- }
- list_for_each_safe(ptr, next, &ac->port[dir].mem_map_handle) {
- buf_node = list_entry(ptr, struct asm_buffer_node,
- list);
- if (buf_node->buf_phys_addr == lbuf_phys_addr) {
- read.mem_map_handle = buf_node->mmap_hdl;
- break;
- }
- }
- rc = apr_send_pkt(ac->apr, (uint32_t *) &read);
- if (rc < 0 && rc != -ENETRESET) {
- pr_err_ratelimited("%s: read op[0x%x]rc[%d]\n", __func__,
- read.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- EXPORT_SYMBOL(q6asm_async_read);
- /**
- * q6asm_write -
- * command to write buffer data to DSP
- *
- * @ac: Audio client handle
- * @len: buffer size
- * @msw_ts: upper 32bits of timestamp
- * @lsw_ts: lower 32bits of timestamp
- * @flags: Flags for timestamp mode
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_write(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
- uint32_t lsw_ts, uint32_t flags)
- {
- int rc = 0;
- struct asm_data_cmd_write_v2 write;
- struct asm_buffer_node *buf_node = NULL;
- struct audio_port_data *port;
- struct audio_buffer *ab;
- int dsp_buf = 0;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- dev_vdbg(ac->dev, "%s: session[%d] len=%d\n",
- __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];
- q6asm_update_token(&write.hdr.token,
- 0, /* Session ID is NA */
- 0, /* Stream ID is NA */
- port->dsp_buf,
- 0, /* Direction flag is NA */
- NO_WAIT_CMD);
- write.hdr.opcode = ASM_DATA_CMD_WRITE_V2;
- write.buf_addr_lsw = lower_32_bits(ab->phys);
- write.buf_addr_msw = msm_audio_populate_upper_32_bits(ab->phys);
- write.buf_size = len;
- write.seq_id = port->dsp_buf;
- write.timestamp_lsw = lsw_ts;
- write.timestamp_msw = msw_ts;
- /* Use 0xFF00 for disabling timestamps */
- if (flags == 0xFF00)
- write.flags = (0x00000000 | (flags & 0x800000FF));
- else
- write.flags = (0x80000000 | flags);
- port->dsp_buf = q6asm_get_next_buf(ac, port->dsp_buf,
- port->max_buf_cnt);
- buf_node = list_first_entry(&ac->port[IN].mem_map_handle,
- struct asm_buffer_node,
- list);
- write.mem_map_handle = buf_node->mmap_hdl;
- dev_vdbg(ac->dev, "%s: ab->phys[%pK]bufadd[0x%x] token[0x%x]buf_id[0x%x]buf_size[0x%x]mmaphdl[0x%x]"
- , __func__,
- &ab->phys,
- write.buf_addr_lsw,
- write.hdr.token,
- write.seq_id,
- write.buf_size,
- write.mem_map_handle);
- mutex_unlock(&port->lock);
- config_debug_fs_write(ab);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
- if (rc < 0) {
- pr_err("%s: write op[0x%x]rc[%d]\n",
- __func__, write.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- }
- fail_cmd:
- return -EINVAL;
- }
- EXPORT_SYMBOL(q6asm_write);
- /**
- * q6asm_write_nolock -
- * command to write buffer data to DSP
- * with no wait for ack.
- *
- * @ac: Audio client handle
- * @len: buffer size
- * @msw_ts: upper 32bits of timestamp
- * @lsw_ts: lower 32bits of timestamp
- * @flags: Flags for timestamp mode
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_write_nolock(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
- uint32_t lsw_ts, uint32_t flags)
- {
- int rc = 0;
- struct asm_data_cmd_write_v2 write;
- struct asm_buffer_node *buf_node = NULL;
- struct audio_port_data *port;
- struct audio_buffer *ab;
- int dsp_buf = 0;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- dev_vdbg(ac->dev, "%s: session[%d] len=%d\n",
- __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];
- q6asm_update_token(&write.hdr.token,
- 0, /* Session ID is NA */
- 0, /* Stream ID is NA */
- port->dsp_buf,
- 0, /* Direction flag is NA */
- NO_WAIT_CMD);
- write.hdr.opcode = ASM_DATA_CMD_WRITE_V2;
- write.buf_addr_lsw = lower_32_bits(ab->phys);
- write.buf_addr_msw = msm_audio_populate_upper_32_bits(ab->phys);
- write.buf_size = len;
- write.seq_id = port->dsp_buf;
- write.timestamp_lsw = lsw_ts;
- write.timestamp_msw = msw_ts;
- buf_node = list_first_entry(&ac->port[IN].mem_map_handle,
- struct asm_buffer_node,
- list);
- write.mem_map_handle = buf_node->mmap_hdl;
- /* Use 0xFF00 for disabling timestamps */
- if (flags == 0xFF00)
- write.flags = (0x00000000 | (flags & 0x800000FF));
- else
- write.flags = (0x80000000 | flags);
- port->dsp_buf = q6asm_get_next_buf(ac, port->dsp_buf,
- port->max_buf_cnt);
- dev_vdbg(ac->dev, "%s: ab->phys[%pK]bufadd[0x%x]token[0x%x] buf_id[0x%x]buf_size[0x%x]mmaphdl[0x%x]"
- , __func__,
- &ab->phys,
- write.buf_addr_lsw,
- write.hdr.token,
- write.seq_id,
- write.buf_size,
- write.mem_map_handle);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &write);
- if (rc < 0) {
- pr_err("%s: write op[0x%x]rc[%d]\n",
- __func__, write.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- }
- fail_cmd:
- return -EINVAL;
- }
- EXPORT_SYMBOL(q6asm_write_nolock);
- /**
- * q6asm_get_session_time_v2 -
- * command to retrieve timestamp info
- *
- * @ac: Audio client handle
- * @ses_time: pointer to fill with session timestamp info
- * @abs_time: pointer to fill with AVS timestamp info
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_get_session_time_v2(struct audio_client *ac, uint64_t *ses_time,
- uint64_t *abs_time)
- {
- struct asm_mtmx_strtr_get_params mtmx_params;
- int rc;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ses_time == NULL) {
- pr_err("%s: tstamp args are NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_add_hdr(ac, &mtmx_params.hdr, sizeof(mtmx_params), TRUE);
- mtmx_params.hdr.opcode = ASM_SESSION_CMD_GET_MTMX_STRTR_PARAMS_V2;
- mtmx_params.param_info.data_payload_addr_lsw = 0;
- mtmx_params.param_info.data_payload_addr_msw = 0;
- mtmx_params.param_info.mem_map_handle = 0;
- mtmx_params.param_info.direction = (ac->io_mode & TUN_READ_IO_MODE
- ? 1 : 0);
- mtmx_params.param_info.module_id =
- ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC;
- mtmx_params.param_info.param_id =
- ASM_SESSION_MTMX_STRTR_PARAM_SESSION_TIME_V3;
- mtmx_params.param_info.param_max_size =
- sizeof(struct param_hdr_v1) +
- sizeof(struct asm_session_mtmx_strtr_param_session_time_v3_t);
- atomic_set(&ac->time_flag, 1);
- dev_vdbg(ac->dev, "%s: session[%d]opcode[0x%x]\n", __func__,
- ac->session, mtmx_params.hdr.opcode);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &mtmx_params);
- if (rc < 0) {
- dev_err_ratelimited(ac->dev, "%s: Get Session Time failed %d\n",
- __func__, rc);
- return rc;
- }
- rc = wait_event_timeout(ac->time_wait,
- (atomic_read(&ac->time_flag) == 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout in getting session time from DSP\n",
- __func__);
- goto fail_cmd;
- }
- *ses_time = ac->dsp_ts.time_stamp;
- if (abs_time != NULL)
- *abs_time = ac->dsp_ts.abs_time_stamp;
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- EXPORT_SYMBOL(q6asm_get_session_time_v2);
- /**
- * q6asm_get_session_time -
- * command to retrieve timestamp info
- *
- * @ac: Audio client handle
- * @tstamp: pointer to fill with timestamp info
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_get_session_time(struct audio_client *ac, uint64_t *tstamp)
- {
- return q6asm_get_session_time_v2(ac, tstamp, NULL);
- }
- EXPORT_SYMBOL(q6asm_get_session_time);
- /**
- * q6asm_get_session_time_legacy -
- * command to retrieve timestamp info
- *
- * @ac: Audio client handle
- * @tstamp: pointer to fill with timestamp info
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_get_session_time_legacy(struct audio_client *ac, uint64_t *tstamp)
- {
- struct apr_hdr hdr;
- int rc;
- if (ac == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (tstamp == NULL) {
- pr_err("%s: tstamp NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
- hdr.opcode = ASM_SESSION_CMD_GET_SESSIONTIME_V3;
- atomic_set(&ac->time_flag, 1);
- dev_vdbg(ac->dev, "%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("%s: Commmand 0x%x failed %d\n",
- __func__, hdr.opcode, rc);
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->time_wait,
- (atomic_read(&ac->time_flag) == 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout in getting session time from DSP\n",
- __func__);
- goto fail_cmd;
- }
- *tstamp = ac->dsp_ts.time_stamp;
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- EXPORT_SYMBOL(q6asm_get_session_time_legacy);
- /**
- * q6asm_send_mtmx_strtr_window -
- * command to send matrix for window params
- *
- * @ac: Audio client handle
- * @window_param: window params
- * @param_id: param id for window
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_send_mtmx_strtr_window(struct audio_client *ac,
- struct asm_session_mtmx_strtr_param_window_v2_t *window_param,
- uint32_t param_id)
- {
- struct asm_mtmx_strtr_params matrix;
- int sz = 0;
- int rc = 0;
- pr_debug("%s: Window lsw is %d, window msw is %d\n", __func__,
- window_param->window_lsw, window_param->window_msw);
- if (!ac) {
- pr_err("%s: audio client handle is NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: ac->apr is NULL", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct asm_mtmx_strtr_params);
- q6asm_add_hdr(ac, &matrix.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- matrix.hdr.opcode = ASM_SESSION_CMD_SET_MTMX_STRTR_PARAMS_V2;
- matrix.param.data_payload_addr_lsw = 0;
- matrix.param.data_payload_addr_msw = 0;
- matrix.param.mem_map_handle = 0;
- matrix.param.data_payload_size =
- sizeof(struct param_hdr_v1) +
- sizeof(struct asm_session_mtmx_strtr_param_window_v2_t);
- matrix.param.direction = 0; /* RX */
- matrix.data.module_id = ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC;
- matrix.data.param_id = param_id;
- matrix.data.param_size =
- sizeof(struct asm_session_mtmx_strtr_param_window_v2_t);
- matrix.data.reserved = 0;
- memcpy(&(matrix.config.window_param),
- window_param,
- sizeof(struct asm_session_mtmx_strtr_param_window_v2_t));
- rc = apr_send_pkt(ac->apr, (uint32_t *) &matrix);
- if (rc < 0) {
- pr_err("%s: Render window start send failed paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout, Render window start paramid[0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_send_mtmx_strtr_window);
- /**
- * q6asm_send_mtmx_strtr_render_mode -
- * command to send matrix for render mode
- *
- * @ac: Audio client handle
- * @render_mode: rendering mode
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_send_mtmx_strtr_render_mode(struct audio_client *ac,
- uint32_t render_mode)
- {
- struct asm_mtmx_strtr_params matrix;
- struct asm_session_mtmx_strtr_param_render_mode_t render_param;
- int sz = 0;
- int rc = 0;
- pr_debug("%s: render mode is %d\n", __func__, render_mode);
- if (!ac) {
- pr_err("%s: audio client handle is NULL\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- if (ac->apr == NULL) {
- pr_err("%s: ac->apr is NULL\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- if ((render_mode != ASM_SESSION_MTMX_STRTR_PARAM_RENDER_DEFAULT) &&
- (render_mode != ASM_SESSION_MTMX_STRTR_PARAM_RENDER_LOCAL_STC)) {
- pr_err("%s: Invalid render mode %d\n", __func__, render_mode);
- rc = -EINVAL;
- goto exit;
- }
- memset(&render_param, 0,
- sizeof(struct asm_session_mtmx_strtr_param_render_mode_t));
- render_param.flags = render_mode;
- memset(&matrix, 0, sizeof(struct asm_mtmx_strtr_params));
- sz = sizeof(struct asm_mtmx_strtr_params);
- q6asm_add_hdr(ac, &matrix.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- matrix.hdr.opcode = ASM_SESSION_CMD_SET_MTMX_STRTR_PARAMS_V2;
- matrix.param.data_payload_addr_lsw = 0;
- matrix.param.data_payload_addr_msw = 0;
- matrix.param.mem_map_handle = 0;
- matrix.param.data_payload_size =
- sizeof(struct param_hdr_v1) +
- sizeof(struct asm_session_mtmx_strtr_param_render_mode_t);
- matrix.param.direction = 0; /* RX */
- matrix.data.module_id = ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC;
- matrix.data.param_id = ASM_SESSION_MTMX_STRTR_PARAM_RENDER_MODE_CMD;
- matrix.data.param_size =
- sizeof(struct asm_session_mtmx_strtr_param_render_mode_t);
- matrix.data.reserved = 0;
- memcpy(&(matrix.config.render_param),
- &render_param,
- sizeof(struct asm_session_mtmx_strtr_param_render_mode_t));
- rc = apr_send_pkt(ac->apr, (uint32_t *) &matrix);
- if (rc < 0) {
- pr_err("%s: Render mode send failed paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -EINVAL;
- goto exit;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout, Render mode send paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -ETIMEDOUT;
- goto exit;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto exit;
- }
- rc = 0;
- exit:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_send_mtmx_strtr_render_mode);
- /**
- * q6asm_send_mtmx_strtr_clk_rec_mode -
- * command to send matrix for clock rec
- *
- * @ac: Audio client handle
- * @clk_rec_mode: mode for clock rec
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_send_mtmx_strtr_clk_rec_mode(struct audio_client *ac,
- uint32_t clk_rec_mode)
- {
- struct asm_mtmx_strtr_params matrix;
- struct asm_session_mtmx_strtr_param_clk_rec_t clk_rec_param;
- int sz = 0;
- int rc = 0;
- pr_debug("%s: clk rec mode is %d\n", __func__, clk_rec_mode);
- if (!ac) {
- pr_err("%s: audio client handle is NULL\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- if (ac->apr == NULL) {
- pr_err("%s: ac->apr is NULL\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- if ((clk_rec_mode != ASM_SESSION_MTMX_STRTR_PARAM_CLK_REC_NONE) &&
- (clk_rec_mode != ASM_SESSION_MTMX_STRTR_PARAM_CLK_REC_AUTO)) {
- pr_err("%s: Invalid clk rec mode %d\n", __func__, clk_rec_mode);
- rc = -EINVAL;
- goto exit;
- }
- memset(&clk_rec_param, 0,
- sizeof(struct asm_session_mtmx_strtr_param_clk_rec_t));
- clk_rec_param.flags = clk_rec_mode;
- memset(&matrix, 0, sizeof(struct asm_mtmx_strtr_params));
- sz = sizeof(struct asm_mtmx_strtr_params);
- q6asm_add_hdr(ac, &matrix.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- matrix.hdr.opcode = ASM_SESSION_CMD_SET_MTMX_STRTR_PARAMS_V2;
- matrix.param.data_payload_addr_lsw = 0;
- matrix.param.data_payload_addr_msw = 0;
- matrix.param.mem_map_handle = 0;
- matrix.param.data_payload_size =
- sizeof(struct param_hdr_v1) +
- sizeof(struct asm_session_mtmx_strtr_param_clk_rec_t);
- matrix.param.direction = 0; /* RX */
- matrix.data.module_id = ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC;
- matrix.data.param_id = ASM_SESSION_MTMX_STRTR_PARAM_CLK_REC_CMD;
- matrix.data.param_size =
- sizeof(struct asm_session_mtmx_strtr_param_clk_rec_t);
- matrix.data.reserved = 0;
- memcpy(&(matrix.config.clk_rec_param),
- &clk_rec_param,
- sizeof(struct asm_session_mtmx_strtr_param_clk_rec_t));
- rc = apr_send_pkt(ac->apr, (uint32_t *) &matrix);
- if (rc < 0) {
- pr_err("%s: clk rec mode send failed paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -EINVAL;
- goto exit;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout, clk rec mode send paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -ETIMEDOUT;
- goto exit;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto exit;
- }
- rc = 0;
- exit:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_send_mtmx_strtr_clk_rec_mode);
- /**
- * q6asm_send_mtmx_strtr_enable_adjust_session_clock -
- * command to send matrix for adjust time
- *
- * @ac: Audio client handle
- * @enable: flag to adjust time or not
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_send_mtmx_strtr_enable_adjust_session_clock(struct audio_client *ac,
- bool enable)
- {
- struct asm_mtmx_strtr_params matrix;
- struct asm_session_mtmx_param_adjust_session_time_ctl_t adjust_time;
- int sz = 0;
- int rc = 0;
- pr_debug("%s: adjust session enable %d\n", __func__, enable);
- if (!ac) {
- pr_err("%s: audio client handle is NULL\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- if (ac->apr == NULL) {
- pr_err("%s: ac->apr is NULL\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- adjust_time.enable = enable;
- memset(&matrix, 0, sizeof(struct asm_mtmx_strtr_params));
- sz = sizeof(struct asm_mtmx_strtr_params);
- q6asm_add_hdr(ac, &matrix.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- matrix.hdr.opcode = ASM_SESSION_CMD_SET_MTMX_STRTR_PARAMS_V2;
- matrix.param.data_payload_addr_lsw = 0;
- matrix.param.data_payload_addr_msw = 0;
- matrix.param.mem_map_handle = 0;
- matrix.param.data_payload_size =
- sizeof(struct param_hdr_v1) +
- sizeof(struct asm_session_mtmx_param_adjust_session_time_ctl_t);
- matrix.param.direction = 0; /* RX */
- matrix.data.module_id = ASM_SESSION_MTMX_STRTR_MODULE_ID_AVSYNC;
- matrix.data.param_id = ASM_SESSION_MTMX_PARAM_ADJUST_SESSION_TIME_CTL;
- matrix.data.param_size =
- sizeof(struct asm_session_mtmx_param_adjust_session_time_ctl_t);
- matrix.data.reserved = 0;
- matrix.config.adj_time_param.enable = adjust_time.enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &matrix);
- if (rc < 0) {
- pr_err("%s: enable adjust session failed failed paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -EINVAL;
- goto exit;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: enable adjust session failed failed paramid [0x%x]\n",
- __func__, matrix.data.param_id);
- rc = -ETIMEDOUT;
- goto exit;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto exit;
- }
- rc = 0;
- exit:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_send_mtmx_strtr_enable_adjust_session_clock);
- static int __q6asm_cmd(struct audio_client *ac, int cmd, uint32_t stream_id)
- {
- struct apr_hdr hdr;
- int rc;
- atomic_t *state;
- int cnt = 0;
- if (!ac) {
- pr_err_ratelimited("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err_ratelimited("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_stream_add_hdr(ac, &hdr, sizeof(hdr), TRUE, stream_id);
- atomic_set(&ac->cmd_state, -1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- WAIT_CMD);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, hdr.token, stream_id, ac->session);
- switch (cmd) {
- case CMD_PAUSE:
- pr_debug("%s: CMD_PAUSE\n", __func__);
- hdr.opcode = ASM_SESSION_CMD_PAUSE;
- state = &ac->cmd_state;
- break;
- case CMD_SUSPEND:
- pr_debug("%s: CMD_SUSPEND\n", __func__);
- hdr.opcode = ASM_SESSION_CMD_SUSPEND;
- state = &ac->cmd_state;
- break;
- case CMD_FLUSH:
- pr_debug("%s: CMD_FLUSH\n", __func__);
- hdr.opcode = ASM_STREAM_CMD_FLUSH;
- state = &ac->cmd_state;
- break;
- case CMD_OUT_FLUSH:
- pr_debug("%s: CMD_OUT_FLUSH\n", __func__);
- hdr.opcode = ASM_STREAM_CMD_FLUSH_READBUFS;
- state = &ac->cmd_state;
- break;
- case CMD_EOS:
- pr_debug("%s: CMD_EOS\n", __func__);
- hdr.opcode = ASM_DATA_CMD_EOS;
- atomic_set(&ac->cmd_state, 0);
- state = &ac->cmd_state;
- break;
- case CMD_CLOSE:
- pr_debug("%s: CMD_CLOSE\n", __func__);
- hdr.opcode = ASM_STREAM_CMD_CLOSE;
- state = &ac->cmd_state;
- break;
- default:
- pr_err("%s: Invalid format[%d]\n", __func__, cmd);
- rc = -EINVAL;
- goto fail_cmd;
- }
- 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("%s: Commmand 0x%x failed %d\n",
- __func__, hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait, (atomic_read(state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for response opcode[0x%x]\n",
- __func__, hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(state) > 0) {
- pr_err("%s: DSP returned error[%s] opcode %d\n",
- __func__, adsp_err_get_err_str(
- atomic_read(state)),
- hdr.opcode);
- rc = adsp_err_get_lnx_err_code(atomic_read(state));
- 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) {
- dev_vdbg(ac->dev, "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) {
- dev_vdbg(ac->dev, "Read Buf[%d] not returned\n",
- cnt);
- }
- }
- }
- }
- return 0;
- fail_cmd:
- return rc;
- }
- /**
- * q6asm_cmd -
- * Function used to send commands for
- * ASM with wait for ack.
- *
- * @ac: Audio client handle
- * @cmd: command to send
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_cmd(struct audio_client *ac, int cmd)
- {
- return __q6asm_cmd(ac, cmd, ac->stream_id);
- }
- EXPORT_SYMBOL(q6asm_cmd);
- /**
- * q6asm_stream_cmd -
- * Function used to send commands for
- * ASM stream with wait for ack.
- *
- * @ac: Audio client handle
- * @cmd: command to send
- * @stream_id: Stream ID
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_stream_cmd(struct audio_client *ac, int cmd, uint32_t stream_id)
- {
- return __q6asm_cmd(ac, cmd, stream_id);
- }
- EXPORT_SYMBOL(q6asm_stream_cmd);
- /**
- * q6asm_cmd_nowait -
- * Function used to send commands for
- * ASM stream without wait for ack.
- *
- * @ac: Audio client handle
- * @cmd: command to send
- * @stream_id: Stream ID
- *
- * Returns 0 on success or error on failure
- */
- static int __q6asm_cmd_nowait(struct audio_client *ac, int cmd,
- uint32_t stream_id)
- {
- struct apr_hdr hdr;
- int rc;
- if (!ac) {
- pr_err_ratelimited("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err_ratelimited("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- q6asm_stream_add_hdr_async(ac, &hdr, sizeof(hdr), TRUE, stream_id);
- atomic_set(&ac->cmd_state, 1);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- NO_WAIT_CMD);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, hdr.token, stream_id, ac->session);
- switch (cmd) {
- case CMD_PAUSE:
- pr_debug("%s: CMD_PAUSE\n", __func__);
- hdr.opcode = ASM_SESSION_CMD_PAUSE;
- break;
- case CMD_EOS:
- pr_debug("%s: CMD_EOS\n", __func__);
- hdr.opcode = ASM_DATA_CMD_EOS;
- break;
- case CMD_CLOSE:
- pr_debug("%s: CMD_CLOSE\n", __func__);
- hdr.opcode = ASM_STREAM_CMD_CLOSE;
- break;
- default:
- pr_err("%s: Invalid format[%d]\n", __func__, cmd);
- goto fail_cmd;
- }
- pr_debug("%s: session[%d]opcode[0x%x]\n", __func__,
- ac->session,
- hdr.opcode);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
- if (rc < 0) {
- pr_err("%s: Commmand 0x%x failed %d\n",
- __func__, hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- int q6asm_cmd_nowait(struct audio_client *ac, int cmd)
- {
- pr_debug("%s: stream_id: %d\n", __func__, ac->stream_id);
- return __q6asm_cmd_nowait(ac, cmd, ac->stream_id);
- }
- EXPORT_SYMBOL(q6asm_cmd_nowait);
- /**
- * q6asm_stream_cmd_nowait -
- * Function used to send commands for
- * ASM stream without wait for ack.
- *
- * @ac: Audio client handle
- * @cmd: command to send
- * @stream_id: Stream ID
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_stream_cmd_nowait(struct audio_client *ac, int cmd,
- uint32_t stream_id)
- {
- pr_debug("%s: stream_id: %d\n", __func__, stream_id);
- return __q6asm_cmd_nowait(ac, cmd, stream_id);
- }
- EXPORT_SYMBOL(q6asm_stream_cmd_nowait);
- int __q6asm_send_meta_data(struct audio_client *ac, uint32_t stream_id,
- uint32_t initial_samples, uint32_t trailing_samples)
- {
- struct asm_data_cmd_remove_silence silence;
- int rc = 0;
- if (!ac) {
- pr_err_ratelimited("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err_ratelimited("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]\n", __func__, ac->session);
- q6asm_stream_add_hdr_async(ac, &silence.hdr, sizeof(silence), TRUE,
- stream_id);
- /*
- * Updated the token field with stream/session for compressed playback
- * Platform driver must know the the stream with which the command is
- * associated
- */
- if (ac->io_mode & COMPRESSED_STREAM_IO)
- q6asm_update_token(&silence.hdr.token,
- ac->session,
- stream_id,
- 0, /* Buffer index is NA */
- 0, /* Direction flag is NA */
- NO_WAIT_CMD);
- pr_debug("%s: token = 0x%x, stream_id %d, session 0x%x\n",
- __func__, silence.hdr.token, stream_id, ac->session);
- silence.hdr.opcode = ASM_DATA_CMD_REMOVE_INITIAL_SILENCE;
- silence.num_samples_to_remove = initial_samples;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &silence);
- if (rc < 0) {
- pr_err("%s: Commmand silence failed[%d]", __func__, rc);
- goto fail_cmd;
- }
- silence.hdr.opcode = ASM_DATA_CMD_REMOVE_TRAILING_SILENCE;
- silence.num_samples_to_remove = trailing_samples;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &silence);
- if (rc < 0) {
- pr_err("%s: Commmand silence failed[%d]", __func__, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- /**
- * q6asm_stream_send_meta_data -
- * command to send meta data for stream
- *
- * @ac: Audio client handle
- * @stream_id: Stream ID
- * @initial_samples: Initial samples of stream
- * @trailing_samples: Trailing samples of stream
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_stream_send_meta_data(struct audio_client *ac, uint32_t stream_id,
- uint32_t initial_samples, uint32_t trailing_samples)
- {
- return __q6asm_send_meta_data(ac, stream_id, initial_samples,
- trailing_samples);
- }
- EXPORT_SYMBOL(q6asm_stream_send_meta_data);
- int q6asm_send_meta_data(struct audio_client *ac, uint32_t initial_samples,
- uint32_t trailing_samples)
- {
- return __q6asm_send_meta_data(ac, ac->stream_id, initial_samples,
- trailing_samples);
- }
- static void q6asm_reset_buf_state(struct audio_client *ac)
- {
- int cnt = 0;
- int loopcnt = 0;
- int used;
- struct audio_port_data *port = NULL;
- if (ac->io_mode & SYNC_IO_MODE) {
- used = (ac->io_mode & TUN_WRITE_IO_MODE ? 1 : 0);
- mutex_lock(&ac->cmd_lock);
- for (loopcnt = 0; loopcnt <= OUT; loopcnt++) {
- port = &ac->port[loopcnt];
- cnt = port->max_buf_cnt - 1;
- port->dsp_buf = 0;
- port->cpu_buf = 0;
- while (cnt >= 0) {
- if (!port->buf)
- continue;
- port->buf[cnt].used = used;
- cnt--;
- }
- }
- mutex_unlock(&ac->cmd_lock);
- }
- }
- /**
- * q6asm_reg_tx_overflow -
- * command to register for TX overflow events
- *
- * @ac: Audio client handle
- * @enable: flag to enable or disable events
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_reg_tx_overflow(struct audio_client *ac, uint16_t enable)
- {
- struct asm_session_cmd_regx_overflow tx_overflow;
- int rc;
- if (!ac) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]enable[%d]\n", __func__,
- ac->session, enable);
- q6asm_add_hdr(ac, &tx_overflow.hdr, sizeof(tx_overflow), TRUE);
- atomic_set(&ac->cmd_state, -1);
- tx_overflow.hdr.opcode =
- ASM_SESSION_CMD_REGISTER_FORX_OVERFLOW_EVENTS;
- /* tx overflow event: enable */
- tx_overflow.enable_flag = enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &tx_overflow);
- if (rc < 0) {
- pr_err("%s: tx overflow op[0x%x]rc[%d]\n",
- __func__, tx_overflow.hdr.opcode, rc);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for tx overflow\n", __func__);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_reg_tx_overflow);
- int q6asm_reg_rx_underflow(struct audio_client *ac, uint16_t enable)
- {
- struct asm_session_cmd_rgstr_rx_underflow rx_underflow;
- int rc;
- if (!ac) {
- pr_err("%s: AC APR handle NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->apr == NULL) {
- pr_err("%s: APR handle NULL\n", __func__);
- return -EINVAL;
- }
- pr_debug("%s: session[%d]enable[%d]\n", __func__,
- ac->session, enable);
- q6asm_add_hdr_async(ac, &rx_underflow.hdr, sizeof(rx_underflow), FALSE);
- rx_underflow.hdr.opcode =
- ASM_SESSION_CMD_REGISTER_FOR_RX_UNDERFLOW_EVENTS;
- /* tx overflow event: enable */
- rx_underflow.enable_flag = enable;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &rx_underflow);
- if (rc < 0) {
- pr_err("%s: tx overflow op[0x%x]rc[%d]\n",
- __func__, rx_underflow.hdr.opcode, rc);
- goto fail_cmd;
- }
- return 0;
- fail_cmd:
- return -EINVAL;
- }
- /**
- * q6asm_adjust_session_clock -
- * command to adjust session clock
- *
- * @ac: Audio client handle
- * @adjust_time_lsw: lower 32bits
- * @adjust_time_msw: upper 32bits
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_adjust_session_clock(struct audio_client *ac,
- uint32_t adjust_time_lsw,
- uint32_t adjust_time_msw)
- {
- int rc = 0;
- int sz = 0;
- struct asm_session_cmd_adjust_session_clock_v2 adjust_clock;
- pr_debug("%s: adjust_time_lsw is %x, adjust_time_msw is %x\n", __func__,
- adjust_time_lsw, adjust_time_msw);
- if (!ac) {
- pr_err("%s: audio client handle is NULL\n", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- if (ac->apr == NULL) {
- pr_err("%s: ac->apr is NULL", __func__);
- rc = -EINVAL;
- goto fail_cmd;
- }
- sz = sizeof(struct asm_session_cmd_adjust_session_clock_v2);
- q6asm_add_hdr(ac, &adjust_clock.hdr, sz, TRUE);
- atomic_set(&ac->cmd_state, -1);
- adjust_clock.hdr.opcode = ASM_SESSION_CMD_ADJUST_SESSION_CLOCK_V2;
- adjust_clock.adjustime_lsw = adjust_time_lsw;
- adjust_clock.adjustime_msw = adjust_time_msw;
- rc = apr_send_pkt(ac->apr, (uint32_t *) &adjust_clock);
- if (rc < 0) {
- pr_err("%s: adjust_clock send failed paramid [0x%x]\n",
- __func__, adjust_clock.hdr.opcode);
- rc = -EINVAL;
- goto fail_cmd;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout, adjust_clock paramid[0x%x]\n",
- __func__, adjust_clock.hdr.opcode);
- rc = -ETIMEDOUT;
- goto fail_cmd;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- goto fail_cmd;
- }
- rc = 0;
- fail_cmd:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_adjust_session_clock);
- /*
- * q6asm_get_path_delay() - get the path delay for an audio session
- * @ac: audio client handle
- *
- * Retrieves the current audio DSP path delay for the given audio session.
- *
- * Return: 0 on success, error code otherwise
- */
- int q6asm_get_path_delay(struct audio_client *ac)
- {
- int rc = 0;
- struct apr_hdr hdr;
- if (!ac || ac->apr == NULL) {
- pr_err("%s: invalid audio client\n", __func__);
- return -EINVAL;
- }
- hdr.opcode = ASM_SESSION_CMD_GET_PATH_DELAY_V2;
- q6asm_add_hdr(ac, &hdr, sizeof(hdr), TRUE);
- atomic_set(&ac->cmd_state, -1);
- rc = apr_send_pkt(ac->apr, (uint32_t *) &hdr);
- if (rc < 0) {
- pr_err("%s: Commmand 0x%x failed %d\n", __func__,
- hdr.opcode, rc);
- return rc;
- }
- rc = wait_event_timeout(ac->cmd_wait,
- (atomic_read(&ac->cmd_state) >= 0),
- msecs_to_jiffies(TIMEOUT_MS));
- if (!rc) {
- pr_err("%s: timeout. waited for response opcode[0x%x]\n",
- __func__, hdr.opcode);
- return -ETIMEDOUT;
- }
- if (atomic_read(&ac->cmd_state) > 0) {
- pr_err("%s: DSP returned error[%s]\n",
- __func__, adsp_err_get_err_str(
- atomic_read(&ac->cmd_state)));
- rc = adsp_err_get_lnx_err_code(
- atomic_read(&ac->cmd_state));
- return rc;
- }
- return 0;
- }
- EXPORT_SYMBOL(q6asm_get_path_delay);
- int q6asm_get_apr_service_id(int session_id)
- {
- int service_id;
- pr_debug("%s:\n", __func__);
- if (session_id <= 0 || session_id > ASM_ACTIVE_STREAMS_ALLOWED) {
- pr_err("%s: invalid session_id = %d\n", __func__, session_id);
- return -EINVAL;
- }
- mutex_lock(&session[session_id].mutex_lock_per_session);
- if (session[session_id].ac != NULL)
- if ((session[session_id].ac)->apr != NULL) {
- service_id = ((struct apr_svc *)(session[session_id].ac)->apr)->id;
- mutex_unlock(&session[session_id].mutex_lock_per_session);
- return service_id;
- }
- mutex_unlock(&session[session_id].mutex_lock_per_session);
- return -EINVAL;
- }
- uint8_t q6asm_get_asm_stream_id(int session_id)
- {
- uint8_t stream_id = 1;
- pr_debug("%s:\n", __func__);
- if (session_id <= 0 || session_id > ASM_ACTIVE_STREAMS_ALLOWED) {
- pr_err("%s: invalid session_id = %d\n", __func__, session_id);
- goto done;
- }
- if (session[session_id].ac == NULL) {
- pr_err("%s: session not created for session id = %d\n",
- __func__, session_id);
- goto done;
- }
- stream_id = (session[session_id].ac)->stream_id;
- done:
- return stream_id;
- }
- int q6asm_get_asm_topology(int session_id)
- {
- int topology = -EINVAL;
- if (session_id <= 0 || session_id > ASM_ACTIVE_STREAMS_ALLOWED) {
- pr_err("%s: invalid session_id = %d\n", __func__, session_id);
- goto done;
- }
- if (session[session_id].ac == NULL) {
- pr_err("%s: session not created for session id = %d\n",
- __func__, session_id);
- goto done;
- }
- topology = (session[session_id].ac)->topology;
- done:
- return topology;
- }
- int q6asm_get_asm_app_type(int session_id)
- {
- int app_type = -EINVAL;
- if (session_id <= 0 || session_id > ASM_ACTIVE_STREAMS_ALLOWED) {
- pr_err("%s: invalid session_id = %d\n", __func__, session_id);
- goto done;
- }
- if (session[session_id].ac == NULL) {
- pr_err("%s: session not created for session id = %d\n",
- __func__, session_id);
- goto done;
- }
- app_type = (session[session_id].ac)->app_type;
- done:
- return app_type;
- }
- /*
- * Retrieving cal_block will mark cal_block as stale.
- * Hence it cannot be reused or resent unless the flag
- * is reset.
- */
- static int q6asm_get_asm_topology_apptype(struct q6asm_cal_info *cal_info)
- {
- struct cal_block_data *cal_block = NULL;
- cal_info->topology_id = DEFAULT_POPP_TOPOLOGY;
- cal_info->app_type = DEFAULT_APP_TYPE;
- if (cal_data[ASM_TOPOLOGY_CAL] == NULL)
- goto done;
- mutex_lock(&cal_data[ASM_TOPOLOGY_CAL]->lock);
- cal_block = cal_utils_get_only_cal_block(cal_data[ASM_TOPOLOGY_CAL]);
- if (cal_block == NULL || cal_utils_is_cal_stale(cal_block))
- goto unlock;
- cal_info->topology_id = ((struct audio_cal_info_asm_top *)
- cal_block->cal_info)->topology;
- cal_info->app_type = ((struct audio_cal_info_asm_top *)
- cal_block->cal_info)->app_type;
- cal_utils_mark_cal_used(cal_block);
- unlock:
- mutex_unlock(&cal_data[ASM_TOPOLOGY_CAL]->lock);
- done:
- pr_debug("%s: Using topology %d app_type %d\n", __func__,
- cal_info->topology_id, cal_info->app_type);
- return 0;
- }
- /**
- * q6asm_send_cal -
- * command to send ASM calibration
- *
- * @ac: Audio client handle
- *
- * Returns 0 on success or error on failure
- */
- int q6asm_send_cal(struct audio_client *ac)
- {
- struct cal_block_data *cal_block = NULL;
- struct mem_mapping_hdr mem_hdr;
- u32 payload_size = 0;
- int rc = -EINVAL;
- pr_debug("%s:\n", __func__);
- if (!ac) {
- pr_err("%s: Audio client is NULL\n", __func__);
- return -EINVAL;
- }
- if (ac->io_mode & NT_MODE) {
- pr_debug("%s: called for NT MODE, exiting\n", __func__);
- goto done;
- }
- if (cal_data[ASM_AUDSTRM_CAL] == NULL)
- goto done;
- if (ac->perf_mode == ULTRA_LOW_LATENCY_PCM_MODE) {
- rc = 0; /* no cal is required, not error case */
- goto done;
- }
- memset(&mem_hdr, 0, sizeof(mem_hdr));
- mutex_lock(&cal_data[ASM_AUDSTRM_CAL]->lock);
- cal_block = cal_utils_get_only_cal_block(cal_data[ASM_AUDSTRM_CAL]);
- if (cal_block == NULL) {
- pr_err("%s: cal_block is NULL\n",
- __func__);
- goto unlock;
- }
- if (cal_utils_is_cal_stale(cal_block)) {
- rc = 0; /* not error case */
- pr_debug("%s: cal_block is stale\n",
- __func__);
- goto unlock;
- }
- if (cal_block->cal_data.size == 0) {
- rc = 0; /* not error case */
- pr_debug("%s: cal_data.size is 0, don't send cal data\n",
- __func__);
- goto unlock;
- }
- rc = remap_cal_data(ASM_AUDSTRM_CAL_TYPE, cal_block);
- if (rc) {
- pr_err("%s: Remap_cal_data failed for cal %d!\n",
- __func__, ASM_AUDSTRM_CAL);
- goto unlock;
- }
- mem_hdr.data_payload_addr_lsw =
- lower_32_bits(cal_block->cal_data.paddr);
- mem_hdr.data_payload_addr_msw =
- msm_audio_populate_upper_32_bits(cal_block->cal_data.paddr);
- mem_hdr.mem_map_handle = cal_block->map_data.q6map_handle;
- payload_size = cal_block->cal_data.size;
- pr_debug("%s: phyaddr lsw = %x msw = %x, maphdl = %x calsize = %d\n",
- __func__, mem_hdr.data_payload_addr_lsw,
- mem_hdr.data_payload_addr_msw, mem_hdr.mem_map_handle,
- payload_size);
- rc = q6asm_set_pp_params(ac, &mem_hdr, NULL, payload_size);
- if (rc) {
- pr_err("%s: audio audstrm cal send failed\n", __func__);
- goto unlock;
- }
- if (cal_block)
- cal_utils_mark_cal_used(cal_block);
- rc = 0;
- unlock:
- mutex_unlock(&cal_data[ASM_AUDSTRM_CAL]->lock);
- done:
- return rc;
- }
- EXPORT_SYMBOL(q6asm_send_cal);
- static int get_cal_type_index(int32_t cal_type)
- {
- int ret = -EINVAL;
- switch (cal_type) {
- case ASM_TOPOLOGY_CAL_TYPE:
- ret = ASM_TOPOLOGY_CAL;
- break;
- case ASM_CUST_TOPOLOGY_CAL_TYPE:
- ret = ASM_CUSTOM_TOP_CAL;
- break;
- case ASM_AUDSTRM_CAL_TYPE:
- ret = ASM_AUDSTRM_CAL;
- break;
- case ASM_RTAC_APR_CAL_TYPE:
- ret = ASM_RTAC_APR_CAL;
- break;
- default:
- pr_err("%s: invalid cal type %d!\n", __func__, cal_type);
- }
- return ret;
- }
- static int q6asm_alloc_cal(int32_t cal_type,
- size_t data_size, void *data)
- {
- int ret = 0;
- int cal_index;
- pr_debug("%s:\n", __func__);
- cal_index = get_cal_type_index(cal_type);
- if (cal_index < 0) {
- pr_err("%s: could not get cal index %d!\n",
- __func__, cal_index);
- ret = -EINVAL;
- goto done;
- }
- ret = cal_utils_alloc_cal(data_size, data,
- cal_data[cal_index], 0, NULL);
- if (ret < 0) {
- pr_err("%s: cal_utils_alloc_block failed, ret = %d, cal type = %d!\n",
- __func__, ret, cal_type);
- ret = -EINVAL;
- goto done;
- }
- done:
- return ret;
- }
- static int q6asm_dealloc_cal(int32_t cal_type,
- size_t data_size, void *data)
- {
- int ret = 0;
- int cal_index;
- pr_debug("%s:\n", __func__);
- cal_index = get_cal_type_index(cal_type);
- if (cal_index < 0) {
- pr_err("%s: could not get cal index %d!\n",
- __func__, cal_index);
- ret = -EINVAL;
- goto done;
- }
- ret = cal_utils_dealloc_cal(data_size, data,
- cal_data[cal_index]);
- if (ret < 0) {
- pr_err("%s: cal_utils_dealloc_block failed, ret = %d, cal type = %d!\n",
- __func__, ret, cal_type);
- ret = -EINVAL;
- goto done;
- }
- done:
- return ret;
- }
- static int q6asm_set_cal(int32_t cal_type,
- size_t data_size, void *data)
- {
- int ret = 0;
- int cal_index;
- pr_debug("%s:\n", __func__);
- cal_index = get_cal_type_index(cal_type);
- if (cal_index < 0) {
- pr_err("%s: could not get cal index %d!\n",
- __func__, cal_index);
- ret = -EINVAL;
- goto done;
- }
- ret = cal_utils_set_cal(data_size, data,
- cal_data[cal_index], 0, NULL);
- if (ret < 0) {
- pr_err("%s: cal_utils_set_cal failed, ret = %d, cal type = %d!\n",
- __func__, ret, cal_type);
- ret = -EINVAL;
- goto done;
- }
- if (cal_index == ASM_CUSTOM_TOP_CAL) {
- mutex_lock(&cal_data[ASM_CUSTOM_TOP_CAL]->lock);
- set_custom_topology = 1;
- mutex_unlock(&cal_data[ASM_CUSTOM_TOP_CAL]->lock);
- }
- done:
- return ret;
- }
- static void q6asm_delete_cal_data(void)
- {
- pr_debug("%s:\n", __func__);
- cal_utils_destroy_cal_types(ASM_MAX_CAL_TYPES, cal_data);
- }
- static int q6asm_init_cal_data(void)
- {
- int ret = 0;
- struct cal_type_info cal_type_info[] = {
- {{ASM_TOPOLOGY_CAL_TYPE,
- {NULL, NULL, NULL,
- q6asm_set_cal, NULL, NULL} },
- {NULL, NULL, cal_utils_match_buf_num} },
- {{ASM_CUST_TOPOLOGY_CAL_TYPE,
- {q6asm_alloc_cal, q6asm_dealloc_cal, NULL,
- q6asm_set_cal, NULL, NULL} },
- {NULL, q6asm_unmap_cal_memory, cal_utils_match_buf_num} },
- {{ASM_AUDSTRM_CAL_TYPE,
- {q6asm_alloc_cal, q6asm_dealloc_cal, NULL,
- q6asm_set_cal, NULL, NULL} },
- {NULL, q6asm_unmap_cal_memory, cal_utils_match_buf_num} },
- {{ASM_RTAC_APR_CAL_TYPE,
- {NULL, NULL, NULL, NULL, NULL, NULL} },
- {NULL, NULL, cal_utils_match_buf_num} }
- };
- pr_debug("%s\n", __func__);
- ret = cal_utils_create_cal_types(ASM_MAX_CAL_TYPES, cal_data,
- cal_type_info);
- if (ret < 0) {
- pr_err("%s: could not create cal type! %d\n",
- __func__, ret);
- ret = -EINVAL;
- goto err;
- }
- return ret;
- err:
- q6asm_delete_cal_data();
- return ret;
- }
- static int q6asm_is_valid_session(struct apr_client_data *data, void *priv)
- {
- struct audio_client *ac = (struct audio_client *)priv;
- union asm_token_struct asm_token;
- asm_token.token = data->token;
- if (asm_token._token.session_id != ac->session) {
- pr_err("%s: Invalid session[%d] rxed expected[%d]",
- __func__, asm_token._token.session_id, ac->session);
- return -EINVAL;
- }
- return 0;
- }
- int __init q6asm_init(void)
- {
- int lcnt, ret;
- pr_debug("%s:\n", __func__);
- memset(session, 0, sizeof(struct audio_session) *
- (ASM_ACTIVE_STREAMS_ALLOWED + 1));
- for (lcnt = 0; lcnt <= ASM_ACTIVE_STREAMS_ALLOWED; lcnt++) {
- spin_lock_init(&(session[lcnt].session_lock));
- mutex_init(&(session[lcnt].mutex_lock_per_session));
- }
- set_custom_topology = 1;
- /*setup common client used for cal mem map */
- common_client.session = ASM_CONTROL_SESSION;
- common_client.port[0].buf = &common_buf[0];
- common_client.port[1].buf = &common_buf[1];
- init_waitqueue_head(&common_client.cmd_wait);
- init_waitqueue_head(&common_client.time_wait);
- init_waitqueue_head(&common_client.mem_wait);
- atomic_set(&common_client.time_flag, 1);
- INIT_LIST_HEAD(&common_client.port[0].mem_map_handle);
- INIT_LIST_HEAD(&common_client.port[1].mem_map_handle);
- mutex_init(&common_client.cmd_lock);
- for (lcnt = 0; lcnt <= OUT; lcnt++) {
- mutex_init(&common_client.port[lcnt].lock);
- spin_lock_init(&common_client.port[lcnt].dsp_lock);
- }
- atomic_set(&common_client.cmd_state, 0);
- atomic_set(&common_client.mem_state, 0);
- ret = q6asm_init_cal_data();
- if (ret)
- pr_err("%s: could not init cal data! ret %d\n",
- __func__, ret);
- config_debug_fs_init();
- return 0;
- }
- void q6asm_exit(void)
- {
- q6asm_delete_cal_data();
- }
|