123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603 |
- /* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only version 2 as published by the Free Software Foundation.
- *
- * 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.
- *
- */
- #define pr_fmt(fmt) "%s: " fmt, __func__
- #include <linux/dma-buf.h>
- #include <linux/dma-mapping.h>
- #include <linux/errno.h>
- #include <linux/kernel.h>
- #include <linux/major.h>
- #include <linux/module.h>
- #include <linux/pm_runtime.h>
- #include <linux/uaccess.h>
- #include <linux/delay.h>
- #include <linux/msm_mdp.h>
- #include <linux/memblock.h>
- #include <linux/sw_sync.h>
- #include <mach/iommu_domains.h>
- #include <mach/event_timer.h>
- #include <mach/msm_bus.h>
- #include <mach/scm.h>
- #include "mdss.h"
- #include "mdss_debug.h"
- #include "mdss_fb.h"
- #include "mdss_mdp.h"
- #include "mdss_mdp_rotator.h"
- #define VSYNC_PERIOD 16
- #define BORDERFILL_NDX 0x0BF000BF
- #define CHECK_BOUNDS(offset, size, max_size) \
- (((size) > (max_size)) || ((offset) > ((max_size) - (size))))
- #define IS_RIGHT_MIXER_OV(flags, dst_x, left_lm_w) \
- ((flags & MDSS_MDP_RIGHT_MIXER) || (dst_x >= left_lm_w))
- #define PP_CLK_CFG_OFF 0
- #define PP_CLK_CFG_ON 1
- #ifdef __MDSS_DEBUG__
- #define ID_PRINTK(mdss_id, fmt, args...) if(mfd->index == mdss_id) printk(fmt, ##args);
- #else
- #define ID_PRINTK(mdss_id, fmt, args...)
- #endif
- enum mdss_id_state {
- ID_LCD = 0,
- ID_HDMI = 1
- };
- int get_lcd_attached(void);
- #define OVERLAY_MAX 10
- #if defined (CONFIG_FB_MSM_MDSS_DBG_SEQ_TICK)
- static struct mdss_tick_debug mdss_dbg_tick;
- #endif
- struct list_head *pipes_used_dbg;
- DEFINE_MUTEX(free_list_purge_mutex);
- static atomic_t ov_active_panels = ATOMIC_INIT(0);
- static int mdss_mdp_overlay_free_fb_pipe(struct msm_fb_data_type *mfd);
- static int mdss_mdp_overlay_fb_parse_dt(struct msm_fb_data_type *mfd);
- static int mdss_mdp_overlay_off(struct msm_fb_data_type *mfd);
- static void __overlay_kickoff_requeue(struct msm_fb_data_type *mfd);
- static void __vsync_retire_signal(struct msm_fb_data_type *mfd, int val);
- #if defined(CONFIG_FB_MSM_MDSS_S6E8AA0A_HD_PANEL)
- extern int err_fg_working;
- extern int lcd_connected_status;
- #endif
- static inline u32 left_lm_w_from_mfd(struct msm_fb_data_type *mfd)
- {
- struct mdss_mdp_ctl *ctl = mfd_to_ctl(mfd);
- return ctl->mixer_left->width;
- }
- static int mdss_mdp_overlay_get(struct msm_fb_data_type *mfd,
- struct mdp_overlay *req)
- {
- struct mdss_mdp_pipe *pipe;
- struct mdss_data_type *mdata = mfd_to_mdata(mfd);
- pipe = mdss_mdp_pipe_get(mdata, req->id);
- if (IS_ERR_OR_NULL(pipe)) {
- pr_err("invalid pipe ndx=%x\n", req->id);
- return pipe ? PTR_ERR(pipe) : -ENODEV;
- }
- *req = pipe->req_data;
- mdss_mdp_pipe_unmap(pipe);
- return 0;
- }
- /*
- * This function is modified from mainline version. Source-split
- * change is too large to port over onto certain code bases.
- * Source-split patch added a new way to determine if layer
- * is intended for right panel, by using x offset >= left LM
- * This function corrects the x offset.
- * Additionally, patches that fix other issues assumes that checks
- * and corrections in this function are in place.
- */
- static int mdss_mdp_ov_xres_check(struct msm_fb_data_type *mfd,
- struct mdp_overlay *req)
- {
- u32 xres = 0;
- u32 left_lm_w = left_lm_w_from_mfd(mfd);
- struct mdss_mdp_ctl *ctl = mfd_to_ctl(mfd);
- if (IS_RIGHT_MIXER_OV(req->flags, req->dst_rect.x, left_lm_w)) {
- if (req->dst_rect.x >= left_lm_w) {
- /*
- * this is a step towards removing a reliance on
- * MDSS_MDP_RIGHT_MIXER flags. With the new src split
- * code, some clients of non-src-split chipsets have
- * stopped sending MDSS_MDP_RIGHT_MIXER flag and
- * modified their xres relative to full panel
- * dimensions. In such cases, we need to deduct left
- * layer mixer width before we programm this HW.
- */
- req->dst_rect.x -= left_lm_w;
- req->flags |= MDSS_MDP_RIGHT_MIXER;
- }
- if (ctl->mixer_right) {
- xres += ctl->mixer_right->width;
- } else {
- pr_err("ov cannot be placed on right mixer\n");
- return -EPERM;
- }
- } else {
- if (ctl->mixer_left) {
- xres = ctl->mixer_left->width;
- } else {
- pr_err("ov cannot be placed on left mixer\n");
- return -EPERM;
- }
- }
- if (CHECK_BOUNDS(req->dst_rect.x, req->dst_rect.w, xres)) {
- pr_err("dst_xres is invalid. dst_x:%d, dst_w:%d, xres:%d\n",
- req->dst_rect.x, req->dst_rect.w, xres);
- return -EOVERFLOW;
- }
- return 0;
- }
- int mdss_mdp_overlay_req_check(struct msm_fb_data_type *mfd,
- struct mdp_overlay *req,
- struct mdss_mdp_format_params *fmt)
- {
- u32 yres;
- u32 min_src_size, min_dst_size;
- int content_secure;
- struct mdss_data_type *mdata = mfd_to_mdata(mfd);
- struct mdss_mdp_ctl *ctl = mfd_to_ctl(mfd);
- yres = mfd->fbi->var.yres;
- content_secure = (req->flags & MDP_SECURE_OVERLAY_SESSION);
- if (!ctl->is_secure && content_secure &&
- (mfd->panel.type == WRITEBACK_PANEL)) {
- pr_debug("return due to security concerns\n");
- return -EPERM;
- }
- if (mdata->mdp_rev >= MDSS_MDP_HW_REV_102) {
- min_src_size = fmt->is_yuv ? 2 : 1;
- min_dst_size = 1;
- } else {
- min_src_size = fmt->is_yuv ? 10 : 5;
- min_dst_size = 2;
- }
- if (req->z_order >= MDSS_MDP_MAX_STAGE) {
- pr_err("zorder %d out of range\n", req->z_order);
- return -ERANGE;
- }
- if (req->src.width > MAX_IMG_WIDTH ||
- req->src.height > MAX_IMG_HEIGHT ||
- req->src_rect.w < min_src_size || req->src_rect.h < min_src_size ||
- CHECK_BOUNDS(req->src_rect.x, req->src_rect.w, req->src.width) ||
- CHECK_BOUNDS(req->src_rect.y, req->src_rect.h, req->src.height)) {
- pr_err("invalid source image img wh=%dx%d rect=%d,%d,%d,%d\n",
- req->src.width, req->src.height,
- req->src_rect.x, req->src_rect.y,
- req->src_rect.w, req->src_rect.h);
- return -EOVERFLOW;
- }
- if (req->dst_rect.w < min_dst_size || req->dst_rect.h < min_dst_size) {
- pr_err("invalid destination resolution (%dx%d)",
- req->dst_rect.w, req->dst_rect.h);
- return -EOVERFLOW;
- }
- if (req->horz_deci || req->vert_deci) {
- if (!mdata->has_decimation) {
- pr_err("No Decimation in MDP V=%x\n", mdata->mdp_rev);
- return -EINVAL;
- } else if ((req->horz_deci > MAX_DECIMATION) ||
- (req->vert_deci > MAX_DECIMATION)) {
- pr_err("Invalid decimation factors horz=%d vert=%d\n",
- req->horz_deci, req->vert_deci);
- return -EINVAL;
- } else if (req->flags & MDP_BWC_EN) {
- pr_err("Decimation can't be enabled with BWC\n");
- return -EINVAL;
- } else if (fmt->tile) {
- pr_err("Decimation can't be enabled with MacroTile format\n");
- return -EINVAL;
- }
- }
- if (!(req->flags & MDSS_MDP_ROT_ONLY)) {
- u32 src_w, src_h, dst_w, dst_h;
- if (CHECK_BOUNDS(req->dst_rect.y, req->dst_rect.h, yres)) {
- pr_err("invalid destination rect=%d,%d,%d,%d\n",
- req->dst_rect.x, req->dst_rect.y,
- req->dst_rect.w, req->dst_rect.h);
- return -EOVERFLOW;
- }
- if (req->flags & MDP_ROT_90) {
- dst_h = req->dst_rect.w;
- dst_w = req->dst_rect.h;
- } else {
- dst_w = req->dst_rect.w;
- dst_h = req->dst_rect.h;
- }
- src_w = DECIMATED_DIMENSION(req->src_rect.w, req->horz_deci);
- src_h = DECIMATED_DIMENSION(req->src_rect.h, req->vert_deci);
- if (src_w > MAX_MIXER_WIDTH) {
- pr_err("invalid source width=%d HDec=%d\n",
- req->src_rect.w, req->horz_deci);
- return -EINVAL;
- }
- if ((src_w * MAX_UPSCALE_RATIO) < dst_w) {
- pr_err("too much upscaling Width %d->%d\n",
- req->src_rect.w, req->dst_rect.w);
- return -EINVAL;
- }
- if ((src_h * MAX_UPSCALE_RATIO) < dst_h) {
- pr_err("too much upscaling. Height %d->%d\n",
- req->src_rect.h, req->dst_rect.h);
- return -EINVAL;
- }
- if (src_w > (dst_w * MAX_DOWNSCALE_RATIO)) {
- pr_err("too much downscaling. Width %d->%d H Dec=%d\n",
- src_w, req->dst_rect.w, req->horz_deci);
- return -EINVAL;
- }
- if (src_h > (dst_h * MAX_DOWNSCALE_RATIO)) {
- pr_err("too much downscaling. Height %d->%d V Dec=%d\n",
- src_h, req->dst_rect.h, req->vert_deci);
- return -EINVAL;
- }
- if (req->flags & MDP_BWC_EN) {
- if ((req->src.width != req->src_rect.w) ||
- (req->src.height != req->src_rect.h)) {
- pr_err("BWC: unequal src img and rect w,h\n");
- return -EINVAL;
- }
- if (req->flags & MDP_DECIMATION_EN) {
- pr_err("Can't enable BWC decode && decimate\n");
- return -EINVAL;
- }
- }
- if ((req->flags & MDP_DEINTERLACE) &&
- !req->scale.enable_pxl_ext) {
- if (req->flags & MDP_SOURCE_ROTATED_90) {
- if ((req->src_rect.w % 4) != 0) {
- pr_err("interlaced rect not h/4\n");
- return -EINVAL;
- }
- } else if ((req->src_rect.h % 4) != 0) {
- pr_err("interlaced rect not h/4\n");
- return -EINVAL;
- }
- }
- } else {
- if (req->flags & MDP_DEINTERLACE) {
- if ((req->src_rect.h % 4) != 0) {
- pr_err("interlaced rect h not multiple of 4\n");
- return -EINVAL;
- }
- }
- }
- if (fmt->is_yuv) {
- if ((req->src_rect.x & 0x1) || (req->src_rect.y & 0x1) ||
- (req->src_rect.w & 0x1) || (req->src_rect.h & 0x1)) {
- pr_err("invalid odd src resolution or coordinates\n");
- return -EINVAL;
- }
- }
- return 0;
- }
- static int __mdp_pipe_tune_perf(struct mdss_mdp_pipe *pipe)
- {
- struct mdss_data_type *mdata = pipe->mixer->ctl->mdata;
- struct mdss_mdp_perf_params perf;
- int rc;
- for (;;) {
- rc = mdss_mdp_perf_calc_pipe(pipe, &perf, NULL, true);
- if (!rc && (perf.mdp_clk_rate <= mdata->max_mdp_clk_rate))
- break;
- /*
- * if decimation is available try to reduce minimum clock rate
- * requirement by applying vertical decimation and reduce
- * mdp clock requirement
- */
- if (mdata->has_decimation && (pipe->vert_deci < MAX_DECIMATION)
- && !pipe->bwc_mode && !pipe->src_fmt->tile &&
- !pipe->scale.enable_pxl_ext)
- pipe->vert_deci++;
- else
- return -EPERM;
- }
- return 0;
- }
- static int __mdss_mdp_validate_pxl_extn(struct mdss_mdp_pipe *pipe)
- {
- int plane;
- for (plane = 0; plane < MAX_PLANES; plane++) {
- u32 hor_req_pixels, hor_fetch_pixels;
- u32 hor_ov_fetch, vert_ov_fetch;
- u32 vert_req_pixels, vert_fetch_pixels;
- u32 src_w = DECIMATED_DIMENSION(pipe->src.w, pipe->horz_deci);
- u32 src_h = DECIMATED_DIMENSION(pipe->src.h, pipe->vert_deci);
- /*
- * plane 1 and 2 are for chroma and are same. While configuring
- * HW, programming only one of the chroma components is
- * sufficient.
- */
- if (plane == 2)
- continue;
- /*
- * For chroma plane, width is half for the following sub sampled
- * formats. Except in case of decimation, where hardware avoids
- * 1 line of decimation instead of downsampling.
- */
- if (plane == 1 && !pipe->horz_deci &&
- ((pipe->src_fmt->chroma_sample == MDSS_MDP_CHROMA_420) ||
- (pipe->src_fmt->chroma_sample == MDSS_MDP_CHROMA_H2V1))) {
- src_w >>= 1;
- }
- if (plane == 1 && !pipe->vert_deci &&
- ((pipe->src_fmt->chroma_sample == MDSS_MDP_CHROMA_420) ||
- (pipe->src_fmt->chroma_sample == MDSS_MDP_CHROMA_H1V2)))
- src_h >>= 1;
- hor_req_pixels = pipe->scale.roi_w[plane] +
- pipe->scale.num_ext_pxls_left[plane] +
- pipe->scale.num_ext_pxls_right[plane];
- hor_fetch_pixels = src_w +
- (pipe->scale.left_ftch[plane] >> pipe->horz_deci) +
- pipe->scale.left_rpt[plane] +
- (pipe->scale.right_ftch[plane] >> pipe->horz_deci) +
- pipe->scale.right_rpt[plane];
- hor_ov_fetch = src_w +
- (pipe->scale.left_ftch[plane] >> pipe->horz_deci)+
- (pipe->scale.right_ftch[plane] >> pipe->horz_deci);
- vert_req_pixels = pipe->scale.num_ext_pxls_top[plane] +
- pipe->scale.num_ext_pxls_btm[plane];
- vert_fetch_pixels =
- (pipe->scale.top_ftch[plane] >> pipe->vert_deci) +
- pipe->scale.top_rpt[plane] +
- (pipe->scale.btm_ftch[plane] >> pipe->vert_deci)+
- pipe->scale.btm_rpt[plane];
- vert_ov_fetch = src_h +
- (pipe->scale.top_ftch[plane] >> pipe->vert_deci)+
- (pipe->scale.btm_ftch[plane] >> pipe->vert_deci);
- if ((hor_req_pixels != hor_fetch_pixels) ||
- (hor_ov_fetch > pipe->img_width) ||
- (vert_req_pixels != vert_fetch_pixels) ||
- (vert_ov_fetch > pipe->img_height)) {
- pr_err("err: plane=%d h_req:%d h_fetch:%d v_req:%d v_fetch:%d\n",
- plane,
- hor_req_pixels, hor_fetch_pixels,
- vert_req_pixels, vert_fetch_pixels);
- pr_err("roi_w[%d]=%d, src_img:[%d, %d]\n",
- plane, pipe->scale.roi_w[plane],
- pipe->img_width, pipe->img_height);
- pipe->scale.enable_pxl_ext = 0;
- return -EINVAL;
- }
- }
- return 0;
- }
- static int __mdss_mdp_overlay_setup_scaling(struct mdss_mdp_pipe *pipe)
- {
- u32 src;
- int rc;
- src = DECIMATED_DIMENSION(pipe->src.w, pipe->horz_deci);
- if (pipe->scale.enable_pxl_ext) {
- rc = __mdss_mdp_validate_pxl_extn(pipe);
- return rc;
- }
- memset(&pipe->scale, 0, sizeof(struct mdp_scale_data));
- rc = mdss_mdp_calc_phase_step(src, pipe->dst.w,
- &pipe->scale.phase_step_x[0]);
- if (rc == -EOVERFLOW) {
- /* overflow on horizontal direction is acceptable */
- rc = 0;
- } else if (rc) {
- pr_err("Horizontal scaling calculation failed=%d! %d->%d\n",
- rc, src, pipe->dst.w);
- return rc;
- }
- src = DECIMATED_DIMENSION(pipe->src.h, pipe->vert_deci);
- rc = mdss_mdp_calc_phase_step(src, pipe->dst.h,
- &pipe->scale.phase_step_y[0]);
- if ((rc == -EOVERFLOW) && (pipe->type == MDSS_MDP_PIPE_TYPE_VIG)) {
- /* overflow on Qseed2 scaler is acceptable */
- rc = 0;
- } else if (rc) {
- pr_err("Vertical scaling calculation failed=%d! %d->%d\n",
- rc, src, pipe->dst.h);
- return rc;
- }
- return rc;
- }
- static inline void __mdss_mdp_overlay_set_chroma_sample(
- struct mdss_mdp_pipe *pipe)
- {
- pipe->chroma_sample_v = pipe->chroma_sample_h = 0;
- switch (pipe->src_fmt->chroma_sample) {
- case MDSS_MDP_CHROMA_H1V2:
- pipe->chroma_sample_v = 1;
- break;
- case MDSS_MDP_CHROMA_H2V1:
- pipe->chroma_sample_h = 1;
- break;
- case MDSS_MDP_CHROMA_420:
- pipe->chroma_sample_v = 1;
- pipe->chroma_sample_h = 1;
- break;
- }
- if (pipe->horz_deci)
- pipe->chroma_sample_h = 0;
- if (pipe->vert_deci)
- pipe->chroma_sample_v = 0;
- }
- int mdss_mdp_overlay_pipe_setup(struct msm_fb_data_type *mfd,
- struct mdp_overlay *req,
- struct mdss_mdp_pipe **ppipe)
- {
- struct mdss_mdp_format_params *fmt;
- struct mdss_mdp_pipe *pipe;
- struct mdss_mdp_mixer *mixer = NULL;
- u32 pipe_type, mixer_mux, len;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- struct mdp_histogram_start_req hist;
- int ret;
- u32 bwc_enabled;
- u32 left_lm_w = left_lm_w_from_mfd(mfd);
- if (mdp5_data->ctl == NULL)
- return -ENODEV;
- if (req->flags & MDP_ROT_90) {
- pr_err("unsupported inline rotation\n");
- return -EOPNOTSUPP;
- }
- #if defined(CONFIG_MDSS_UD_FLIP)
- if (req->flags & MDP_FLIP_UD)
- req->flags &= ~MDP_FLIP_UD;
- else
- req->flags |= MDP_FLIP_UD;
- #endif
- if ((req->dst_rect.w > MAX_DST_W) || (req->dst_rect.h > MAX_DST_H)) {
- pr_err("exceeded max mixer supported resolution %dx%d\n",
- req->dst_rect.w, req->dst_rect.h);
- return -EOVERFLOW;
- }
- if (IS_RIGHT_MIXER_OV(req->flags, req->dst_rect.x, left_lm_w))
- mixer_mux = MDSS_MDP_MIXER_MUX_RIGHT;
- else
- mixer_mux = MDSS_MDP_MIXER_MUX_LEFT;
- pr_debug("pipe ctl=%u req id=%x mux=%d\n", mdp5_data->ctl->num, req->id,
- mixer_mux);
- if (req->flags & (MDP_SOURCE_ROTATED_90 | MDP_BWC_EN))
- req->src.format =
- mdss_mdp_get_rotator_dst_format(req->src.format, 1);
- fmt = mdss_mdp_get_format_params(req->src.format);
- if (!fmt) {
- pr_err("invalid pipe format %d\n", req->src.format);
- return -EINVAL;
- }
- ret = mdss_mdp_ov_xres_check(mfd, req);
- if (ret)
- return ret;
- ret = mdss_mdp_overlay_req_check(mfd, req, fmt);
- if (ret)
- return ret;
- pipe = mdss_mdp_mixer_stage_pipe(mdp5_data->ctl, mixer_mux,
- req->z_order);
- if (pipe && pipe->ndx != req->id) {
- pr_debug("replacing pnum=%d at stage=%d mux=%d\n",
- pipe->num, req->z_order, mixer_mux);
- mdss_mdp_mixer_pipe_unstage(pipe);
- }
- mixer = mdss_mdp_mixer_get(mdp5_data->ctl, mixer_mux);
- if (!mixer) {
- pr_err("unable to get mixer\n");
- return -ENODEV;
- }
- if (req->id == MSMFB_NEW_REQUEST) {
- switch (req->pipe_type) {
- case PIPE_TYPE_VIG:
- pipe_type = MDSS_MDP_PIPE_TYPE_VIG;
- break;
- case PIPE_TYPE_RGB:
- pipe_type = MDSS_MDP_PIPE_TYPE_RGB;
- break;
- case PIPE_TYPE_DMA:
- pipe_type = MDSS_MDP_PIPE_TYPE_DMA;
- break;
- case PIPE_TYPE_AUTO:
- default:
- if (req->flags & MDP_OV_PIPE_FORCE_DMA)
- pipe_type = MDSS_MDP_PIPE_TYPE_DMA;
- else if (fmt->is_yuv ||
- (req->flags & MDP_OV_PIPE_SHARE))
- pipe_type = MDSS_MDP_PIPE_TYPE_VIG;
- else
- pipe_type = MDSS_MDP_PIPE_TYPE_RGB;
- break;
- }
- pipe = mdss_mdp_pipe_alloc(mixer, pipe_type);
- /* VIG pipes can also support RGB format */
- if ((req->pipe_type == PIPE_TYPE_AUTO) && !pipe &&
- (pipe_type == MDSS_MDP_PIPE_TYPE_RGB)) {
- pipe_type = MDSS_MDP_PIPE_TYPE_VIG;
- pipe = mdss_mdp_pipe_alloc(mixer, pipe_type);
- }
- if (pipe == NULL) {
- pr_err("error allocating pipe\n");
- return -ENODEV;
- }
- ret = mdss_mdp_pipe_map(pipe);
- if (ret) {
- pr_err("unable to map pipe=%d\n", pipe->num);
- return ret;
- }
- mutex_lock(&mdp5_data->list_lock);
- list_add(&pipe->list, &mdp5_data->pipes_used);
- mutex_unlock(&mdp5_data->list_lock);
- pipe->mixer = mixer;
- pipe->mfd = mfd;
- pipe->pid = current->tgid;
- pipe->play_cnt = 0;
- } else {
- pipe = mdss_mdp_pipe_get(mdp5_data->mdata, req->id);
- if (IS_ERR_OR_NULL(pipe)) {
- pr_err("invalid pipe ndx=%x\n", req->id);
- return pipe ? PTR_ERR(pipe) : -ENODEV;
- }
- if (pipe->mixer != mixer) {
- if (!mixer->ctl || (mixer->ctl->mfd != mfd)) {
- pr_err("Can't switch mixer %d->%d pnum %d!\n",
- pipe->mixer->num, mixer->num,
- pipe->num);
- ret = -EINVAL;
- goto exit_fail;
- }
- pr_debug("switching pipe mixer %d->%d pnum %d\n",
- pipe->mixer->num, mixer->num,
- pipe->num);
- mdss_mdp_mixer_pipe_unstage(pipe);
- pipe->mixer = mixer;
- }
- }
- pipe->flags = req->flags;
- bwc_enabled = req->flags & MDP_BWC_EN;
- if (bwc_enabled && !mdp5_data->mdata->has_bwc) {
- pr_err("BWC is not supported in MDP version %x\n",
- mdp5_data->mdata->mdp_rev);
- pipe->bwc_mode = 0;
- } else {
- pipe->bwc_mode = pipe->mixer->rotator_mode ?
- 0 : (bwc_enabled ? 1 : 0) ;
- }
- pipe->img_width = req->src.width & 0x3fff;
- pipe->img_height = req->src.height & 0x3fff;
- pipe->src.x = req->src_rect.x;
- pipe->src.y = req->src_rect.y;
- pipe->src.w = req->src_rect.w;
- pipe->src.h = req->src_rect.h;
- pipe->dst.x = req->dst_rect.x;
- pipe->dst.y = req->dst_rect.y;
- pipe->dst.w = req->dst_rect.w;
- pipe->dst.h = req->dst_rect.h;
- pipe->horz_deci = req->horz_deci;
- pipe->vert_deci = req->vert_deci;
- memcpy(&pipe->scale, &req->scale, sizeof(struct mdp_scale_data));
- pipe->src_fmt = fmt;
- __mdss_mdp_overlay_set_chroma_sample(pipe);
- pipe->mixer_stage = req->z_order;
- pipe->is_fg = req->is_fg;
- pipe->alpha = req->alpha;
- pipe->transp = req->transp_mask;
- pipe->blend_op = req->blend_op;
- if (pipe->blend_op == BLEND_OP_NOT_DEFINED)
- pipe->blend_op = fmt->alpha_enable ?
- BLEND_OP_PREMULTIPLIED :
- BLEND_OP_OPAQUE;
- if (!fmt->alpha_enable && (pipe->blend_op != BLEND_OP_OPAQUE))
- pr_debug("Unintended blend_op %d on layer with no alpha plane\n",
- pipe->blend_op);
- if (fmt->is_yuv && !(pipe->flags & MDP_SOURCE_ROTATED_90) &&
- !pipe->scale.enable_pxl_ext) {
- pipe->overfetch_disable = OVERFETCH_DISABLE_BOTTOM;
- if (!(pipe->flags & MDSS_MDP_DUAL_PIPE) ||
- IS_RIGHT_MIXER_OV(req->flags,
- req->dst_rect.x, left_lm_w))
- pipe->overfetch_disable |= OVERFETCH_DISABLE_RIGHT;
- pr_debug("overfetch flags=%x\n", pipe->overfetch_disable);
- } else {
- pipe->overfetch_disable = 0;
- }
- pipe->bg_color = req->bg_color;
- req->id = pipe->ndx;
- pipe->req_data = *req;
- if (pipe->flags & MDP_OVERLAY_PP_CFG_EN) {
- memcpy(&pipe->pp_cfg, &req->overlay_pp_cfg,
- sizeof(struct mdp_overlay_pp_params));
- len = pipe->pp_cfg.igc_cfg.len;
- if ((pipe->pp_cfg.config_ops & MDP_OVERLAY_PP_IGC_CFG) &&
- (len == IGC_LUT_ENTRIES)) {
- ret = copy_from_user(pipe->pp_res.igc_c0_c1,
- pipe->pp_cfg.igc_cfg.c0_c1_data,
- sizeof(uint32_t) * len);
- if (ret) {
- pr_err("pp_cfg1 get from user was NULL \n");
- ret = -ENOMEM;
- goto exit_fail;
- }
- ret = copy_from_user(pipe->pp_res.igc_c2,
- pipe->pp_cfg.igc_cfg.c2_data,
- sizeof(uint32_t) * len);
- if (ret) {
- pr_err("pp_cfg2 get from user was NULL \n");
- ret = -ENOMEM;
- goto exit_fail;
- }
- pipe->pp_cfg.igc_cfg.c0_c1_data =
- pipe->pp_res.igc_c0_c1;
- pipe->pp_cfg.igc_cfg.c2_data = pipe->pp_res.igc_c2;
- }
- if (pipe->pp_cfg.config_ops & MDP_OVERLAY_PP_HIST_CFG) {
- if (pipe->pp_cfg.hist_cfg.ops & MDP_PP_OPS_ENABLE) {
- hist.block = pipe->pp_cfg.hist_cfg.block;
- hist.frame_cnt =
- pipe->pp_cfg.hist_cfg.frame_cnt;
- hist.bit_mask = pipe->pp_cfg.hist_cfg.bit_mask;
- hist.num_bins = pipe->pp_cfg.hist_cfg.num_bins;
- mdss_mdp_hist_start(&hist);
- } else if (pipe->pp_cfg.hist_cfg.ops &
- MDP_PP_OPS_DISABLE) {
- mdss_mdp_hist_stop(pipe->pp_cfg.hist_cfg.block);
- }
- }
- len = pipe->pp_cfg.hist_lut_cfg.len;
- if ((pipe->pp_cfg.config_ops & MDP_OVERLAY_PP_HIST_LUT_CFG) &&
- (len == ENHIST_LUT_ENTRIES)) {
- ret = copy_from_user(pipe->pp_res.hist_lut,
- pipe->pp_cfg.hist_lut_cfg.data,
- sizeof(uint32_t) * len);
- if (ret) {
- pr_err("lut get from user was NULL \n");
- ret = -ENOMEM;
- goto exit_fail;
- }
- pipe->pp_cfg.hist_lut_cfg.data = pipe->pp_res.hist_lut;
- }
- }
- /*
- * When scaling is enabled src crop and image
- * width and height is modified by user
- */
- if ((pipe->flags & MDP_DEINTERLACE) && !pipe->scale.enable_pxl_ext) {
- if (pipe->flags & MDP_SOURCE_ROTATED_90) {
- pipe->src.x = DIV_ROUND_UP(pipe->src.x, 2);
- pipe->src.x &= ~1;
- pipe->src.w /= 2;
- pipe->img_width /= 2;
- } else {
- pipe->src.h /= 2;
- pipe->src.y = DIV_ROUND_UP(pipe->src.y, 2);
- pipe->src.y &= ~1;
- }
- }
- ret = __mdp_pipe_tune_perf(pipe);
- if (ret) {
- pr_debug("unable to satisfy performance. ret=%d\n", ret);
- goto exit_fail;
- }
- ret = __mdss_mdp_overlay_setup_scaling(pipe);
- if (ret)
- goto exit_fail;
- if ((mixer->type == MDSS_MDP_MIXER_TYPE_WRITEBACK) &&
- !mdp5_data->mdata->has_wfd_blk)
- mdss_mdp_smp_release(pipe);
- ret = mdss_mdp_smp_reserve(pipe);
- if (ret) {
- pr_debug("mdss_mdp_smp_reserve failed. ret=%d\n", ret);
- goto exit_fail;
- }
- pipe->params_changed++;
- req->vert_deci = pipe->vert_deci;
- *ppipe = pipe;
- mdss_mdp_pipe_unmap(pipe);
- return ret;
- exit_fail:
- mdss_mdp_pipe_unmap(pipe);
- mutex_lock(&mdp5_data->list_lock);
- if (pipe->play_cnt == 0) {
- pr_debug("failed for pipe %d\n", pipe->num);
- if (!list_empty(&pipe->list))
- list_del_init(&pipe->list);
- mdss_mdp_pipe_destroy(pipe);
- }
- /* invalidate any overlays in this framebuffer after failure */
- list_for_each_entry(pipe, &mdp5_data->pipes_used, list) {
- pr_debug("freeing allocations for pipe %d\n", pipe->num);
- mdss_mdp_smp_unreserve(pipe);
- pipe->params_changed = 0;
- }
- mutex_unlock(&mdp5_data->list_lock);
- return ret;
- }
- static int mdss_mdp_overlay_set(struct msm_fb_data_type *mfd,
- struct mdp_overlay *req)
- {
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- int ret;
- ret = mutex_lock_interruptible(&mdp5_data->ov_lock);
- if (ret)
- return ret;
- if (!mfd->panel_power_on) {
- mutex_unlock(&mdp5_data->ov_lock);
- return -EPERM;
- }
- if (req->flags & MDSS_MDP_ROT_ONLY) {
- #if defined(CONFIG_MDSS_UD_FLIP)
- if (req->flags & MDP_BWC_EN) {
- if (req->flags & MDP_FLIP_LR)
- req->flags &= ~MDP_FLIP_LR;
- else
- req->flags |= MDP_FLIP_LR;
- }
- #endif
- ret = mdss_mdp_rotator_setup(mfd, req);
- } else if (req->src.format == MDP_RGB_BORDERFILL) {
- req->id = BORDERFILL_NDX;
- } else {
- struct mdss_mdp_pipe *pipe;
- /* userspace zorder start with stage 0 */
- req->z_order += MDSS_MDP_STAGE_0;
- ret = mdss_mdp_overlay_pipe_setup(mfd, req, &pipe);
- req->z_order -= MDSS_MDP_STAGE_0;
- }
- mutex_unlock(&mdp5_data->ov_lock);
- return ret;
- }
- int mdss_mdp_overlay_get_buf(struct msm_fb_data_type *mfd,
- struct mdss_mdp_data *data,
- struct msmfb_data *planes,
- int num_planes,
- u32 flags)
- {
- int i, rc = 0;
- if ((num_planes <= 0) || (num_planes > MAX_PLANES))
- return -EINVAL;
- rc = mdss_iommu_ctrl(1);
- if (IS_ERR_VALUE(rc)) {
- pr_err("Iommu attach failed");
- goto end;
- }
- memset(data, 0, sizeof(*data));
- for (i = 0; i < num_planes; i++) {
- data->p[i].flags = flags;
- rc = mdss_mdp_get_img(&planes[i], &data->p[i]);
- if (rc) {
- pr_err("failed to map buf p=%d flags=%x\n", i, flags);
- while (i > 0) {
- i--;
- mdss_mdp_put_img(&data->p[i]);
- }
- break;
- }
- }
- mdss_iommu_ctrl(0);
- data->num_planes = i;
- end:
- return rc;
- }
- int mdss_mdp_overlay_free_buf(struct mdss_mdp_data *data)
- {
- int i, rc;
- rc = mdss_iommu_ctrl(1);
- if (IS_ERR_VALUE(rc)) {
- pr_err("Iommu attach failed");
- return rc;
- }
- for (i = 0; i < data->num_planes && data->p[i].len; i++)
- mdss_mdp_put_img(&data->p[i]);
- mdss_iommu_ctrl(0);
- data->num_planes = 0;
- return 0;
- }
- /**
- * __mdss_mdp_overlay_free_list_purge() - clear free list of buffers
- * @mfd: Msm frame buffer data structure for the associated fb
- *
- * Frees memory and clears current list of buffers which are pending free
- */
- static void __mdss_mdp_overlay_free_list_purge(struct msm_fb_data_type *mfd)
- {
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- int i;
- mutex_lock(&free_list_purge_mutex);
- pr_debug("purging fb%d free list\n", mfd->index);
- for (i = 0; i < mdp5_data->free_list_size; i++)
- mdss_mdp_overlay_free_buf(&mdp5_data->free_list[i]);
- mdp5_data->free_list_size = 0;
- mutex_unlock(&free_list_purge_mutex);
- }
- /**
- * __mdss_mdp_overlay_free_list_add() - add a buffer to free list
- * @mfd: Msm frame buffer data structure for the associated fb
- */
- static void __mdss_mdp_overlay_free_list_add(struct msm_fb_data_type *mfd,
- struct mdss_mdp_data *buf)
- {
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- int i;
- /* if holding too many buffers free current list */
- if (mdp5_data->free_list_size >= MAX_FREE_LIST_SIZE) {
- pr_warn("max free list size for fb%d, purging\n", mfd->index);
- __mdss_mdp_overlay_free_list_purge(mfd);
- }
- BUG_ON(mdp5_data->free_list_size >= MAX_FREE_LIST_SIZE);
- i = mdp5_data->free_list_size++;
- mdp5_data->free_list[i] = *buf;
- memset(buf, 0, sizeof(*buf));
- }
- /**
- * mdss_mdp_overlay_cleanup() - handles cleanup after frame commit
- * @mfd: Msm frame buffer data structure for the associated fb
- * @destroy_pipes: list of pipes that should be destroyed as part of cleanup
- *
- * Goes through destroy_pipes list and ensures they are ready to be destroyed
- * and cleaned up. Also cleanup of any pipe buffers after flip.
- */
- static void mdss_mdp_overlay_cleanup(struct msm_fb_data_type *mfd,
- struct list_head *destroy_pipes)
- {
- struct mdss_mdp_pipe *pipe, *tmp;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- struct mdss_mdp_ctl *ctl = mfd_to_ctl(mfd);
- bool recovery_mode = false;
- mutex_lock(&mdp5_data->list_lock);
- list_for_each_entry(pipe, destroy_pipes, list) {
- /* make sure pipe fetch has been halted before freeing buffer */
- if (mdss_mdp_pipe_fetch_halt(pipe)) {
- /*
- * if pipe is not able to halt. Enter recovery mode,
- * by un-staging any pipes that are attached to mixer
- * so that any freed pipes that are not able to halt
- * can be staged in solid fill mode and be reset
- * with next vsync
- */
- if (!recovery_mode) {
- recovery_mode = true;
- mdss_mdp_mixer_unstage_all(ctl->mixer_left);
- mdss_mdp_mixer_unstage_all(ctl->mixer_right);
- }
- pipe->params_changed++;
- mdss_mdp_pipe_queue_data(pipe, NULL);
- }
- }
- if (recovery_mode) {
- pr_warn("performing recovery sequence for fb%d\n", mfd->index);
- __overlay_kickoff_requeue(mfd);
- }
- __mdss_mdp_overlay_free_list_purge(mfd);
- list_for_each_entry(pipe, &mdp5_data->pipes_used, list) {
- if (pipe->back_buf.num_planes) {
- /* make back buffer active */
- __mdss_mdp_overlay_free_list_add(mfd, &pipe->front_buf);
- swap(pipe->back_buf, pipe->front_buf);
- }
- }
- list_for_each_entry_safe(pipe, tmp, destroy_pipes, list) {
- /*
- * in case of secure UI, the buffer needs to be released as
- * soon as session is closed.
- */
- if (pipe->flags & MDP_SECURE_DISPLAY_OVERLAY_SESSION)
- mdss_mdp_overlay_free_buf(&pipe->front_buf);
- else
- __mdss_mdp_overlay_free_list_add(mfd, &pipe->front_buf);
- mdss_mdp_overlay_free_buf(&pipe->back_buf);
- list_del_init(&pipe->list);
- mdss_mdp_pipe_destroy(pipe);
- }
- mutex_unlock(&mdp5_data->list_lock);
- }
- void mdss_mdp_handoff_cleanup_pipes(struct msm_fb_data_type *mfd,
- u32 type)
- {
- u32 i, npipes;
- struct mdss_mdp_pipe *pipes;
- struct mdss_mdp_pipe *pipe;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- struct mdss_data_type *mdata = mfd_to_mdata(mfd);
- switch (type) {
- case MDSS_MDP_PIPE_TYPE_VIG:
- pipes = mdata->vig_pipes;
- npipes = mdata->nvig_pipes;
- break;
- case MDSS_MDP_PIPE_TYPE_RGB:
- pipes = mdata->rgb_pipes;
- npipes = mdata->nrgb_pipes;
- break;
- case MDSS_MDP_PIPE_TYPE_DMA:
- pipes = mdata->dma_pipes;
- npipes = mdata->ndma_pipes;
- break;
- default:
- return;
- }
- for (i = 0; i < npipes; i++) {
- pipe = &pipes[i];
- if (pipe->is_handed_off) {
- pr_debug("Unmapping handed off pipe %d\n", pipe->num);
- list_add(&pipe->list, &mdp5_data->pipes_cleanup);
- mdss_mdp_mixer_pipe_unstage(pipe);
- pipe->is_handed_off = false;
- }
- }
- }
- /**
- * mdss_mdp_overlay_start() - Programs the MDP control data path to hardware
- * @mfd: Msm frame buffer structure associated with fb device.
- *
- * Program the MDP hardware with the control settings for the framebuffer
- * device. In addition to this, this function also handles the transition
- * from the the splash screen to the android boot animation when the
- * continuous splash screen feature is enabled.
- */
- int mdss_mdp_overlay_start(struct msm_fb_data_type *mfd)
- {
- int rc;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- struct mdss_mdp_ctl *ctl = mdp5_data->ctl;
- if (!ctl) {
- pr_err("%s unable to access ctrl\n", __func__);
- return -ENODEV;
- }
- if (ctl->power_on) {
- if (mdp5_data->mdata->idle_pc) {
- rc = mdss_mdp_footswitch_ctrl_idle_pc(1,
- &mfd->pdev->dev);
- if (rc) {
- pr_err("footswtich control power on failed rc=%d\n",
- rc);
- goto end;
- }
- mdss_mdp_ctl_restore(ctl);
- }
- if (!mdp5_data->mdata->batfet)
- mdss_mdp_batfet_ctrl(mdp5_data->mdata, true);
- mdss_mdp_release_splash_pipe(mfd);
- return 0;
- }
- pr_debug("starting fb%d overlay\n", mfd->index);
- rc = pm_runtime_get_sync(&mfd->pdev->dev);
- if (IS_ERR_VALUE(rc)) {
- pr_err("unable to resume with pm_runtime_get_sync rc=%d\n", rc);
- goto end;
- }
- /*
- * We need to do hw init before any hw programming.
- * Also, hw init involves programming the VBIF registers which
- * should be done only after attaching IOMMU which in turn would call
- * in to TZ to restore security configs on the VBIF registers.
- * This is not needed when continuous splash screen is enabled since
- * we would have called in to TZ to restore security configs from LK.
- */
- if (!is_mdss_iommu_attached()) {
- if (!mfd->panel_info->cont_splash_enabled) {
- rc = mdss_iommu_ctrl(1);
- if (IS_ERR_VALUE(rc)) {
- pr_err("iommu attach failed rc=%d\n", rc);
- goto pm_error;
- }
- mdss_hw_init(mdss_res);
- mdss_iommu_ctrl(0);
- }
- }
- rc = mdss_mdp_ctl_start(ctl, false);
- if (rc == 0) {
- atomic_inc(&ov_active_panels);
- mdss_mdp_ctl_notifier_register(mdp5_data->ctl,
- &mfd->mdp_sync_pt_data.notifier);
- } else {
- pr_err("mdp ctl start failed.\n");
- goto ctl_error;
- }
- rc = mdss_mdp_splash_cleanup(mfd, true);
- if (!rc)
- goto end;
- ctl_error:
- mdss_mdp_ctl_destroy(ctl);
- mdp5_data->ctl = NULL;
- pm_error:
- pm_runtime_put(&mfd->pdev->dev);
- end:
- return rc;
- }
- static void mdss_mdp_overlay_update_pm(struct mdss_overlay_private *mdp5_data)
- {
- ktime_t wakeup_time;
- if (!mdp5_data->cpu_pm_hdl)
- return;
- if (mdss_mdp_display_wakeup_time(mdp5_data->ctl, &wakeup_time))
- return;
- activate_event_timer(mdp5_data->cpu_pm_hdl, wakeup_time);
- }
- static int __overlay_queue_pipes(struct msm_fb_data_type *mfd)
- {
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- struct mdss_mdp_pipe *pipe;
- struct mdss_mdp_ctl *ctl = mfd_to_ctl(mfd);
- struct mdss_mdp_ctl *tmp;
- int ret = 0;
- /*
- * Setup pipe in solid fill before unstaging,
- * to ensure no fetches are happening after dettach or reattach.
- */
- list_for_each_entry(pipe, &mdp5_data->pipes_cleanup, list) {
- mdss_mdp_pipe_queue_data(pipe, NULL);
- mdss_mdp_mixer_pipe_unstage(pipe);
- }
- list_for_each_entry(pipe, &mdp5_data->pipes_used, list) {
- struct mdss_mdp_data *buf;
- /*
- * When secure display is enabled, if there is a non secure
- * display pipe, skip that
- */
- if (mdss_get_sd_client_cnt() &&
- !(pipe->flags & MDP_SECURE_DISPLAY_OVERLAY_SESSION)) {
- pr_warn("Non secure pipe during secure display: %u: %08X, skip\n",
- pipe->num, pipe->flags);
- continue;
- }
- /*
- * When external is connected and no dedicated wfd is present,
- * reprogram DMA pipe before kickoff to clear out any previous
- * block mode configuration.
- */
- if ((pipe->type == MDSS_MDP_PIPE_TYPE_DMA) &&
- (ctl->shared_lock && !ctl->mdata->has_wfd_blk)) {
- if (ctl->mdata->mixer_switched) {
- ret = mdss_mdp_overlay_pipe_setup(mfd,
- &pipe->req_data, &pipe);
- pr_debug("reseting DMA pipe for ctl=%d",
- ctl->num);
- }
- if (ret) {
- pr_err("can't reset DMA pipe ret=%d ctl=%d\n",
- ret, ctl->num);
- return ret;
- }
- tmp = mdss_mdp_ctl_mixer_switch(ctl,
- MDSS_MDP_WB_CTL_TYPE_LINE);
- if (!tmp)
- return -EINVAL;
- pipe->mixer = mdss_mdp_mixer_get(tmp,
- MDSS_MDP_MIXER_MUX_DEFAULT);
- }
- /* ensure pipes are always reconfigured after power off/on */
- if (ctl->play_cnt == 0)
- pipe->params_changed++;
- if (pipe->back_buf.num_planes) {
- buf = &pipe->back_buf;
- } else if (!pipe->params_changed) {
- continue;
- } else if (pipe->front_buf.num_planes) {
- buf = &pipe->front_buf;
- } else {
- pr_debug("no buf detected pnum=%d use solid fill\n",
- pipe->num);
- buf = NULL;
- }
- ret = mdss_mdp_pipe_queue_data(pipe, buf);
- if (IS_ERR_VALUE(ret)) {
- pr_warn("Unable to queue data for pnum=%d\n",
- pipe->num);
- mdss_mdp_mixer_pipe_unstage(pipe);
- }
- }
- return 0;
- }
- static void __overlay_kickoff_requeue(struct msm_fb_data_type *mfd)
- {
- struct mdss_mdp_ctl *ctl = mfd_to_ctl(mfd);
- mdss_mdp_display_commit(ctl, NULL);
- mdss_mdp_display_wait4comp(ctl);
- ATRACE_BEGIN("sspp_programming");
- __overlay_queue_pipes(mfd);
- ATRACE_END("sspp_programming");
- mdss_mdp_display_commit(ctl, NULL);
- mdss_mdp_display_wait4comp(ctl);
- }
- #if defined(CONFIG_MDNIE_LITE_TUNING)
- #if defined(CONFIG_FB_MSM_MIPI_SAMSUNG_OCTA_CMD_FULL_HD_PT_PANEL)
- static bool mdss_first_init = true;
- #endif
- #endif
- #if defined(CONFIG_FB_MSM_MIPI_SAMSUNG_OCTA_CMD_WQHD_PT_PANEL)
- int get_lcd_ldi_info(void);
- #endif
- int mdss_mdp_overlay_kickoff(struct msm_fb_data_type *mfd,
- struct mdp_display_commit *data)
- {
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- struct mdss_mdp_pipe *pipe, *tmp;
- struct mdss_mdp_ctl *ctl = mfd_to_ctl(mfd);
- int ret = 0;
- int sd_in_pipe = 0;
- bool need_cleanup = false;
- LIST_HEAD(destroy_pipes);
-
- #if defined(CONFIG_FB_MSM_MIPI_SAMSUNG_OCTA_CMD_WQHD_PT_PANEL)
- int te_ret = 0;
- #endif
- ATRACE_BEGIN(__func__);
- if (ctl->shared_lock) {
- mdss_mdp_ctl_notify(ctl, MDP_NOTIFY_FRAME_BEGIN);
- mdss_mdp_ctl_notify(ctl, MDP_NOTIFY_FRAME_READY);
- mutex_lock(ctl->shared_lock);
- mutex_lock(ctl->wb_lock);
- }
- mutex_lock(&mdp5_data->ov_lock);
- ctl->bw_pending = 0;
- if (mfd->panel_info->type == DTV_PANEL) {
- ret = mdss_mdp_overlay_start(mfd);
- if (ret) {
- pr_err("unable to start overlay %d (%d)\n",
- mfd->index, ret);
- mutex_unlock(&mdp5_data->ov_lock);
- if (ctl->shared_lock)
- mutex_unlock(ctl->shared_lock);
- return ret;
- }
- }
- mutex_lock(&mdp5_data->list_lock);
- /*
- * check if there is a secure display session
- */
- list_for_each_entry(pipe, &mdp5_data->pipes_used, list) {
- if (pipe->flags & MDP_SECURE_DISPLAY_OVERLAY_SESSION) {
- sd_in_pipe = 1;
- pr_debug("Secure pipe: %u : %08X\n",
- pipe->num, pipe->flags);
- }
- }
- /*
- * If there is no secure display session and sd_enabled, disable the
- * secure display session
- */
- if (!sd_in_pipe && mdp5_data->sd_enabled) {
- /* disable the secure display on last client */
- if (mdss_get_sd_client_cnt() == 1)
- ret = mdss_mdp_secure_display_ctrl(0);
- if (!ret) {
- mdss_update_sd_client(mdp5_data->mdata, false);
- mdp5_data->sd_enabled = 0;
- }
- }
- if (!ctl->shared_lock)
- mdss_mdp_ctl_notify(ctl, MDP_NOTIFY_FRAME_BEGIN);
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_ON, false);
- if (data)
- mdss_mdp_set_roi(ctl, data);
- /*
- * Setup pipe in solid fill before unstaging,
- * to ensure no fetches are happening after dettach or reattach.
- */
- list_for_each_entry_safe(pipe, tmp, &mdp5_data->pipes_cleanup, list) {
- mdss_mdp_pipe_queue_data(pipe, NULL);
- mdss_mdp_mixer_pipe_unstage(pipe);
- list_move(&pipe->list, &destroy_pipes);
- need_cleanup = true;
- }
- ATRACE_BEGIN("sspp_programming");
- ret = __overlay_queue_pipes(mfd);
- ATRACE_END("sspp_programming");
- mutex_unlock(&mdp5_data->list_lock);
- if (mfd->panel.type == WRITEBACK_PANEL) {
- ATRACE_BEGIN("wb_kickoff");
- ret = mdss_mdp_wb_kickoff(mfd);
- ATRACE_END("wb_kickoff");
- } else {
- ret = mdss_mdp_display_commit(mdp5_data->ctl, NULL);
- }
- if (!need_cleanup) {
- atomic_set(&mfd->kickoff_pending, 0);
- wake_up_all(&mfd->kickoff_wait_q);
- }
- if (IS_ERR_VALUE(ret))
- goto commit_fail;
- mutex_unlock(&mdp5_data->ov_lock);
- mdss_mdp_overlay_update_pm(mdp5_data);
- ATRACE_BEGIN("display_wait4comp");
- ret = mdss_mdp_display_wait4comp(mdp5_data->ctl);
- ATRACE_END("display_wait4comp");
- mutex_lock(&mdp5_data->ov_lock);
- if (ret == 0) {
- if (!mdp5_data->sd_enabled && sd_in_pipe) {
- if (!mdss_get_sd_client_cnt())
- ret = mdss_mdp_secure_display_ctrl(1);
- if (!ret) {
- mdp5_data->sd_enabled = 1;
- mdss_update_sd_client(mdp5_data->mdata, true);
- }
- }
- }
- mdss_fb_update_notify_update(mfd);
- #if defined(CONFIG_MDNIE_LITE_TUNING)
- #if defined(CONFIG_FB_MSM_MIPI_SAMSUNG_OCTA_CMD_FULL_HD_PT_PANEL) \
- || defined(CONFIG_FB_MSM_MIPI_SAMSUNG_YOUM_CMD_FULL_HD_PT_PANEL)
- if(mdss_first_init)
- {
- mdss_mdp_ctl_intf_event(mdp5_data->ctl, MDSS_EVENT_MDNIE_DEFAULT_UPDATE, NULL);
- mdss_first_init = false;
- }
- #endif
- #endif
- #if defined(CONFIG_FB_MSM_MIPI_SAMSUNG_OCTA_CMD_WQHD_PT_PANEL)
- if (get_lcd_ldi_info()) {
- te_ret = mdss_mdp_ctl_intf_event(mdp5_data->ctl, MDSS_EVENT_TE_UPDATE, NULL);
- if (te_ret < 0) {
- mdss_mdp_ctl_intf_event(mdp5_data->ctl, MDSS_EVENT_TE_RESTORE, NULL);
- }
- }
- #endif
- #if defined(CONFIG_FB_MSM_MIPI_SAMSUNG_OCTA_CMD_FULL_HD_PT_PANEL) || defined (CONFIG_FB_MSM_MIPI_SAMSUNG_OCTA_CMD_WQHD_PT_PANEL)\
- || defined(CONFIG_FB_MSM_MIPI_SAMSUNG_YOUM_CMD_FULL_HD_PT_PANEL) || defined(CONFIG_FB_MSM_MIPI_JDI_TFT_VIDEO_FULL_HD_PT_PANEL)\
- || defined (CONFIG_FB_MSM_MIPI_MAGNA_OCTA_CMD_HD_PT_PANEL) \
- || defined (CONFIG_FB_MSM_MIPI_SAMSUNG_OCTA_CMD_WQXGA_S6TNMR7_PT_PANEL) \
- || defined (CONFIG_FB_MSM_MIPI_SAMSUNG_OCTA_CMD_WQXGA_S6E3HA1_PT_PANEL)
- mdss_mdp_ctl_intf_event(mdp5_data->ctl, MDSS_EVENT_FRAME_UPDATE, NULL);
- #endif
- #if defined(CONFIG_FB_MSM_MDSS_SDC_WXGA_PANEL)
- mdss_mdp_ctl_intf_event(mdp5_data->ctl, MDSS_EVENT_BACKLIGHT_LATE_ON, NULL);
- #endif
- commit_fail:
- ATRACE_BEGIN("overlay_cleanup");
- mdss_mdp_overlay_cleanup(mfd, &destroy_pipes);
- ATRACE_END("overlay_cleanup");
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_OFF, false);
- mdss_mdp_ctl_notify(ctl, MDP_NOTIFY_FRAME_FLUSHED);
- if (need_cleanup) {
- atomic_set(&mfd->kickoff_pending, 0);
- wake_up_all(&mfd->kickoff_wait_q);
- }
- mutex_unlock(&mdp5_data->ov_lock);
- if (ctl->shared_lock) {
- mutex_unlock(ctl->wb_lock);
- mutex_unlock(ctl->shared_lock);
- }
- ATRACE_END(__func__);
- return ret;
- }
- int mdss_mdp_overlay_release(struct msm_fb_data_type *mfd, int ndx)
- {
- struct mdss_mdp_pipe *pipe, *tmp;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- u32 unset_ndx = 0;
- int destroy_pipe;
- mutex_lock(&mdp5_data->list_lock);
- list_for_each_entry_safe(pipe, tmp, &mdp5_data->pipes_used, list) {
- if (pipe->ndx & ndx) {
- if (mdss_mdp_pipe_map(pipe)) {
- pr_err("Unable to map used pipe%d ndx=%x\n",
- pipe->num, pipe->ndx);
- continue;
- }
- unset_ndx |= pipe->ndx;
- pipe->pid = 0;
- destroy_pipe = pipe->play_cnt == 0;
- if (destroy_pipe)
- list_del_init(&pipe->list);
- else
- list_move(&pipe->list,
- &mdp5_data->pipes_cleanup);
- mdss_mdp_pipe_unmap(pipe);
- if (destroy_pipe)
- mdss_mdp_pipe_destroy(pipe);
- if (unset_ndx == ndx)
- break;
- }
- }
- mutex_unlock(&mdp5_data->list_lock);
- if (unset_ndx != ndx) {
- pr_warn("Unable to unset pipe(s) ndx=0x%x unset=0x%x\n",
- ndx, unset_ndx);
- return -ENOENT;
- }
- return 0;
- }
- static int mdss_mdp_overlay_unset(struct msm_fb_data_type *mfd, int ndx)
- {
- int ret = 0;
- struct mdss_overlay_private *mdp5_data;
- if (!mfd)
- return -ENODEV;
- mdp5_data = mfd_to_mdp5_data(mfd);
- if (!mdp5_data || !mdp5_data->ctl)
- return -ENODEV;
- ret = mutex_lock_interruptible(&mdp5_data->ov_lock);
- if (ret)
- return ret;
- if (ndx == BORDERFILL_NDX) {
- pr_debug("borderfill disable\n");
- mdp5_data->borderfill_enable = false;
- ret = 0;
- goto done;
- }
- #if defined(CONFIG_FB_MSM_MDSS_S6E8AA0A_HD_PANEL)
- if(lcd_connected_status == 1){
- if (!mfd->panel_power_on && !err_fg_working) {
- ret = -EPERM;
- goto done;
- }
- }
- #else
- if (!mfd->panel_power_on) {
- ret = -EPERM;
- goto done;
- }
- #endif
- pr_debug("unset ndx=%x\n", ndx);
- if (ndx & MDSS_MDP_ROT_SESSION_MASK) {
- ret = mdss_mdp_rotator_unset(ndx);
- } else {
- ret = mdss_mdp_overlay_release(mfd, ndx);
- }
- done:
- mutex_unlock(&mdp5_data->ov_lock);
- return ret;
- }
- /**
- * mdss_mdp_overlay_release_all() - release any overlays associated with fb dev
- * @mfd: Msm frame buffer structure associated with fb device
- * @release_all: ignore pid and release all the pipes
- *
- * Release any resources allocated by calling process, this can be called
- * on fb_release to release any overlays/rotator sessions left open.
- */
- static int __mdss_mdp_overlay_release_all(struct msm_fb_data_type *mfd,
- bool release_all)
- {
- struct mdss_mdp_pipe *pipe;
- struct mdss_mdp_rotator_session *rot, *tmp;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- u32 unset_ndx = 0;
- int cnt = 0;
- int pid = current->tgid;
- pr_debug("releasing all resources for fb%d pid=%d\n", mfd->index, pid);
- mutex_lock(&mdp5_data->ov_lock);
- mutex_lock(&mdp5_data->list_lock);
- list_for_each_entry(pipe, &mdp5_data->pipes_used, list) {
- if (release_all || (pipe->pid == pid)) {
- unset_ndx |= pipe->ndx;
- cnt++;
- }
- }
- if (!mfd->ref_cnt && !list_empty(&mdp5_data->pipes_cleanup)) {
- pr_debug("fb%d:: free pipes present in cleanup list",
- mfd->index);
- cnt++;
- }
- pr_debug("release_all=%d mfd->ref_cnt=%d unset_ndx=0x%x cnt=%d\n",
- release_all, mfd->ref_cnt, unset_ndx, cnt);
- mutex_unlock(&mdp5_data->list_lock);
- if (unset_ndx) {
- pr_debug("%d pipes need cleanup (%x)\n", cnt, unset_ndx);
- mdss_mdp_overlay_release(mfd, unset_ndx);
- }
- mutex_unlock(&mdp5_data->ov_lock);
- if (cnt)
- mfd->mdp.kickoff_fnc(mfd, NULL);
- list_for_each_entry_safe(rot, tmp, &mdp5_data->rot_proc_list, list) {
- if (rot->pid == pid) {
- if (!list_empty(&rot->list))
- list_del_init(&rot->list);
- mdss_mdp_rotator_release(rot);
- }
- }
- return 0;
- }
- static int mdss_mdp_overlay_play_wait(struct msm_fb_data_type *mfd,
- struct msmfb_overlay_data *req)
- {
- int ret = 0;
- if (!mfd)
- return -ENODEV;
- ret = mfd->mdp.kickoff_fnc(mfd, NULL);
- if (!ret)
- pr_err("error displaying\n");
- return ret;
- }
- static int mdss_mdp_overlay_queue(struct msm_fb_data_type *mfd,
- struct msmfb_overlay_data *req)
- {
- struct mdss_mdp_pipe *pipe;
- struct mdss_mdp_data *src_data;
- int ret;
- u32 flags;
- struct mdss_data_type *mdata = mfd_to_mdata(mfd);
- pipe = mdss_mdp_pipe_get(mdata, req->id);
- if (IS_ERR_OR_NULL(pipe)) {
- pr_err("pipe ndx=%x doesn't exist\n", req->id);
- return pipe ? PTR_ERR(pipe) : -ENODEV;
- }
- pr_debug("ov queue pnum=%d\n", pipe->num);
- if (pipe->flags & MDP_SOLID_FILL)
- pr_warn("Unexpected buffer queue to a solid fill pipe\n");
- flags = (pipe->flags & MDP_SECURE_OVERLAY_SESSION);
- flags |= (pipe->flags & MDP_SECURE_DISPLAY_OVERLAY_SESSION);
- src_data = &pipe->back_buf;
- if (src_data->num_planes) {
- pr_warn("dropped buffer pnum=%d play=%d addr=0x%x\n",
- pipe->num, pipe->play_cnt, src_data->p[0].addr);
- mdss_mdp_overlay_free_buf(src_data);
- }
- ret = mdss_mdp_overlay_get_buf(mfd, src_data, &req->data, 1, flags);
- if (IS_ERR_VALUE(ret)) {
- pr_err("src_data pmem error\n");
- }
- mdss_mdp_pipe_unmap(pipe);
- return ret;
- }
- static int mdss_mdp_overlay_play(struct msm_fb_data_type *mfd,
- struct msmfb_overlay_data *req)
- {
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- int ret = 0;
- pr_debug("play req id=%x\n", req->id);
- ret = mutex_lock_interruptible(&mdp5_data->ov_lock);
- if (ret)
- return ret;
- if (!mfd->panel_power_on) {
- ret = -EPERM;
- goto done;
- }
- ret = mdss_mdp_overlay_start(mfd);
- if (ret) {
- pr_err("unable to start overlay %d (%d)\n", mfd->index, ret);
- goto done;
- }
- if (req->id & MDSS_MDP_ROT_SESSION_MASK) {
- ret = mdss_mdp_rotator_play(mfd, req);
- } else if (req->id == BORDERFILL_NDX) {
- pr_debug("borderfill enable\n");
- mdp5_data->borderfill_enable = true;
- ret = mdss_mdp_overlay_free_fb_pipe(mfd);
- } else {
- ret = mdss_mdp_overlay_queue(mfd, req);
- }
- done:
- mutex_unlock(&mdp5_data->ov_lock);
- return ret;
- }
- static int mdss_mdp_overlay_free_fb_pipe(struct msm_fb_data_type *mfd)
- {
- struct mdss_mdp_pipe *pipe;
- u32 fb_ndx = 0;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- pipe = mdss_mdp_mixer_stage_pipe(mdp5_data->ctl,
- MDSS_MDP_MIXER_MUX_LEFT,
- MDSS_MDP_STAGE_BASE);
- if (pipe)
- fb_ndx |= pipe->ndx;
- pipe = mdss_mdp_mixer_stage_pipe(mdp5_data->ctl,
- MDSS_MDP_MIXER_MUX_RIGHT,
- MDSS_MDP_STAGE_BASE);
- if (pipe)
- fb_ndx |= pipe->ndx;
- if (fb_ndx) {
- pr_debug("unstaging framebuffer pipes %x\n", fb_ndx);
- mdss_mdp_overlay_release(mfd, fb_ndx);
- }
- return 0;
- }
- static int mdss_mdp_overlay_get_fb_pipe(struct msm_fb_data_type *mfd,
- struct mdss_mdp_pipe **ppipe,
- int mixer_mux)
- {
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- struct mdss_mdp_pipe *pipe;
- int ret;
- pipe = mdss_mdp_mixer_stage_pipe(mdp5_data->ctl, mixer_mux,
- MDSS_MDP_STAGE_BASE);
- if (pipe == NULL) {
- struct mdp_overlay req;
- struct fb_info *fbi = mfd->fbi;
- struct mdss_mdp_mixer *mixer;
- int bpp;
- mixer = mdss_mdp_mixer_get(mdp5_data->ctl,
- MDSS_MDP_MIXER_MUX_LEFT);
- if (!mixer) {
- pr_err("unable to retrieve mixer\n");
- return -ENODEV;
- }
- memset(&req, 0, sizeof(req));
- bpp = fbi->var.bits_per_pixel / 8;
- req.id = MSMFB_NEW_REQUEST;
- req.src.format = mfd->fb_imgType;
- req.src.height = fbi->var.yres;
- req.src.width = fbi->fix.line_length / bpp;
- if (mixer_mux == MDSS_MDP_MIXER_MUX_RIGHT) {
- if (req.src.width <= mixer->width) {
- pr_warn("right fb pipe not needed\n");
- return -EINVAL;
- }
- req.flags = req.flags | MDSS_MDP_RIGHT_MIXER;
- req.src_rect.x = mixer->width;
- req.src_rect.w = fbi->var.xres - mixer->width;
- } else {
- req.src_rect.x = 0;
- req.src_rect.w = MIN(fbi->var.xres,
- mixer->width);
- }
- req.src_rect.y = 0;
- req.src_rect.h = req.src.height;
- req.dst_rect.w = req.src_rect.w;
- req.dst_rect.h = req.src_rect.h;
- req.z_order = MDSS_MDP_STAGE_BASE;
- pr_debug("allocating base pipe mux=%d\n", mixer_mux);
- ret = mdss_mdp_overlay_pipe_setup(mfd, &req, &pipe);
- if (ret)
- return ret;
- }
- pr_debug("ctl=%d pnum=%d\n", mdp5_data->ctl->num, pipe->num);
- *ppipe = pipe;
- return 0;
- }
- static void mdss_mdp_overlay_pan_display(struct msm_fb_data_type *mfd)
- {
- struct mdss_mdp_data *buf;
- struct mdss_mdp_pipe *pipe;
- struct fb_info *fbi;
- struct mdss_overlay_private *mdp5_data;
- u32 offset;
- int bpp, ret;
- if (!mfd)
- return;
- fbi = mfd->fbi;
- mdp5_data = mfd_to_mdp5_data(mfd);
- if (!mdp5_data || !mdp5_data->ctl)
- return;
- if (!fbi->fix.smem_start || fbi->fix.smem_len == 0 ||
- mdp5_data->borderfill_enable) {
- mfd->mdp.kickoff_fnc(mfd, NULL);
- return;
- }
- if (mutex_lock_interruptible(&mdp5_data->ov_lock))
- return;
- if ((!mfd->panel_power_on) && !((mfd->dcm_state == DCM_ENTER) &&
- (mfd->panel.type == MIPI_CMD_PANEL))) {
- mutex_unlock(&mdp5_data->ov_lock);
- return;
- }
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_ON, false);
- bpp = fbi->var.bits_per_pixel / 8;
- offset = fbi->var.xoffset * bpp +
- fbi->var.yoffset * fbi->fix.line_length;
- if (offset > fbi->fix.smem_len) {
- pr_err("invalid fb offset=%u total length=%u\n",
- offset, fbi->fix.smem_len);
- goto pan_display_error;
- }
- ret = mdss_mdp_overlay_start(mfd);
- if (ret) {
- pr_err("unable to start overlay %d (%d)\n", mfd->index, ret);
- goto pan_display_error;
- }
- ret = mdss_iommu_ctrl(1);
- if (IS_ERR_VALUE(ret)) {
- pr_err("IOMMU attach failed\n");
- goto pan_display_error;
- }
- ret = mdss_mdp_overlay_get_fb_pipe(mfd, &pipe,
- MDSS_MDP_MIXER_MUX_LEFT);
- if (ret) {
- pr_err("unable to allocate base pipe\n");
- goto pan_display_error;
- }
- if (mdss_mdp_pipe_map(pipe)) {
- pr_err("unable to map base pipe\n");
- goto pan_display_error;
- }
- buf = &pipe->back_buf;
- if (is_mdss_iommu_attached()) {
- if (!mfd->iova) {
- pr_err("mfd iova is zero\n");
- mdss_mdp_pipe_unmap(pipe);
- goto pan_display_error;
- }
- buf->p[0].addr = mfd->iova;
- } else {
- buf->p[0].addr = fbi->fix.smem_start;
- }
- buf->p[0].addr += offset;
- buf->p[0].len = fbi->fix.smem_len - offset;
- buf->num_planes = 1;
- mdss_mdp_pipe_unmap(pipe);
- if (fbi->var.xres > MAX_MIXER_WIDTH || mfd->split_display) {
- ret = mdss_mdp_overlay_get_fb_pipe(mfd, &pipe,
- MDSS_MDP_MIXER_MUX_RIGHT);
- if (ret) {
- pr_err("unable to allocate right base pipe\n");
- goto pan_display_error;
- }
- if (mdss_mdp_pipe_map(pipe)) {
- pr_err("unable to map right base pipe\n");
- goto pan_display_error;
- }
- pipe->back_buf = *buf;
- mdss_mdp_pipe_unmap(pipe);
- }
- mutex_unlock(&mdp5_data->ov_lock);
- if ((fbi->var.activate & FB_ACTIVATE_VBL) ||
- (fbi->var.activate & FB_ACTIVATE_FORCE))
- mfd->mdp.kickoff_fnc(mfd, NULL);
- mdss_iommu_ctrl(0);
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_OFF, false);
- return;
- pan_display_error:
- mdss_iommu_ctrl(0);
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_OFF, false);
- mutex_unlock(&mdp5_data->ov_lock);
- }
- static void remove_underrun_vsync_handler(struct work_struct *work)
- {
- int rc;
- struct mdss_mdp_ctl *ctl =
- container_of(work, typeof(*ctl), remove_underrun_handler);
- if (!ctl || !ctl->remove_vsync_handler) {
- pr_err("ctl or vsync handler is NULL\n");
- return;
- }
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_ON, false);
- rc = ctl->remove_vsync_handler(ctl,
- &ctl->recover_underrun_handler);
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_OFF, false);
- }
- static void mdss_mdp_recover_underrun_handler(struct mdss_mdp_ctl *ctl,
- ktime_t t)
- {
- if (!ctl) {
- pr_err("ctl is NULL\n");
- return;
- }
- mdss_mdp_ctl_reset(ctl);
- schedule_work(&ctl->remove_underrun_handler);
- }
- /* function is called in irq context should have minimum processing */
- static void mdss_mdp_overlay_handle_vsync(struct mdss_mdp_ctl *ctl,
- ktime_t t)
- {
- struct msm_fb_data_type *mfd = NULL;
- struct mdss_overlay_private *mdp5_data = NULL;
- if (!ctl) {
- pr_err("ctl is NULL\n");
- return;
- }
- mfd = ctl->mfd;
- if (!mfd || !mfd->mdp.private1) {
- pr_warn("Invalid handle for vsync\n");
- return;
- }
- mdp5_data = mfd_to_mdp5_data(mfd);
- if (!mdp5_data) {
- pr_err("mdp5_data is NULL\n");
- return;
- }
- pr_debug("vsync on fb%d play_cnt=%d\n", mfd->index, ctl->play_cnt);
- mdp5_data->vsync_time = t;
- sysfs_notify_dirent(mdp5_data->vsync_event_sd);
- }
- int mdss_mdp_overlay_vsync_ctrl(struct msm_fb_data_type *mfd, int en)
- {
- struct mdss_mdp_ctl *ctl = mfd_to_ctl(mfd);
- int rc;
- if (!ctl)
- return -ENODEV;
- if (!ctl->add_vsync_handler || !ctl->remove_vsync_handler)
- return -EOPNOTSUPP;
- if (!ctl->panel_data->panel_info.cont_splash_enabled
- && !ctl->power_on) {
- pr_debug("fb%d vsync pending first update en=%d\n",
- mfd->index, en);
- return -EPERM;
- }
- pr_debug("fb%d vsync en=%d\n", mfd->index, en);
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_ON, false);
- if (en)
- rc = ctl->add_vsync_handler(ctl, &ctl->vsync_handler);
- else
- rc = ctl->remove_vsync_handler(ctl, &ctl->vsync_handler);
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_OFF, false);
- return rc;
- }
- static ssize_t dynamic_fps_sysfs_rda_dfps(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- ssize_t ret;
- struct mdss_panel_data *pdata;
- struct fb_info *fbi = dev_get_drvdata(dev);
- struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)fbi->par;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- if (!mdp5_data->ctl || !mdp5_data->ctl->power_on)
- return 0;
- pdata = dev_get_platdata(&mfd->pdev->dev);
- if (!pdata) {
- pr_err("no panel connected for fb%d\n", mfd->index);
- return -ENODEV;
- }
- mutex_lock(&mdp5_data->dfps_lock);
- ret = snprintf(buf, PAGE_SIZE, "%d\n",
- pdata->panel_info.mipi.frame_rate);
- pr_debug("%s: '%d'\n", __func__,
- pdata->panel_info.mipi.frame_rate);
- mutex_unlock(&mdp5_data->dfps_lock);
- return ret;
- } /* dynamic_fps_sysfs_rda_dfps */
- static ssize_t dynamic_fps_sysfs_wta_dfps(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
- {
- int dfps, rc = 0;
- struct mdss_panel_data *pdata;
- struct fb_info *fbi = dev_get_drvdata(dev);
- struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)fbi->par;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- rc = kstrtoint(buf, 10, &dfps);
- if (rc) {
- pr_err("%s: kstrtoint failed. rc=%d\n", __func__, rc);
- return rc;
- }
- if (!mdp5_data->ctl || !mdp5_data->ctl->power_on)
- return 0;
- pdata = dev_get_platdata(&mfd->pdev->dev);
- if (!pdata) {
- pr_err("no panel connected for fb%d\n", mfd->index);
- return -ENODEV;
- }
- if (dfps == pdata->panel_info.mipi.frame_rate) {
- pr_debug("%s: FPS is already %d\n",
- __func__, dfps);
- return count;
- }
- mutex_lock(&mdp5_data->dfps_lock);
- if (dfps < pdata->panel_info.min_fps) {
- pr_err("Unsupported FPS. min_fps = %d\n",
- pdata->panel_info.min_fps);
- mutex_unlock(&mdp5_data->dfps_lock);
- return -EINVAL;
- } else if (dfps > pdata->panel_info.max_fps) {
- pr_warn("Unsupported FPS. Configuring to max_fps = %d\n",
- pdata->panel_info.max_fps);
- dfps = pdata->panel_info.max_fps;
- rc = mdss_mdp_ctl_update_fps(mdp5_data->ctl, dfps);
- } else {
- rc = mdss_mdp_ctl_update_fps(mdp5_data->ctl, dfps);
- }
- if (!rc) {
- pr_info("%s: configured to '%d' FPS\n", __func__, dfps);
- } else {
- pr_err("Failed to configure '%d' FPS. rc = %d\n",
- dfps, rc);
- mutex_unlock(&mdp5_data->dfps_lock);
- return rc;
- }
- pdata->panel_info.new_fps = dfps;
- mutex_unlock(&mdp5_data->dfps_lock);
- return count;
- } /* dynamic_fps_sysfs_wta_dfps */
- static DEVICE_ATTR(dynamic_fps, S_IRUGO | S_IWUSR, dynamic_fps_sysfs_rda_dfps,
- dynamic_fps_sysfs_wta_dfps);
- static struct attribute *dynamic_fps_fs_attrs[] = {
- &dev_attr_dynamic_fps.attr,
- NULL,
- };
- static struct attribute_group dynamic_fps_fs_attrs_group = {
- .attrs = dynamic_fps_fs_attrs,
- };
- static ssize_t mdss_mdp_vsync_show_event(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct fb_info *fbi = dev_get_drvdata(dev);
- struct msm_fb_data_type *mfd = (struct msm_fb_data_type *)fbi->par;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- u64 vsync_ticks;
- int ret;
- if (!mdp5_data->ctl ||
- (!mdp5_data->ctl->panel_data->panel_info.cont_splash_enabled
- && !mdp5_data->ctl->power_on))
- return -EAGAIN;
- vsync_ticks = ktime_to_ns(mdp5_data->vsync_time);
- pr_debug("fb%d vsync=%llu", mfd->index, vsync_ticks);
- ret = scnprintf(buf, PAGE_SIZE, "VSYNC=%llu\n", vsync_ticks);
- return ret;
- }
- static inline int mdss_mdp_ad_is_supported(struct msm_fb_data_type *mfd)
- {
- struct mdss_mdp_ctl *ctl = mfd_to_ctl(mfd);
- struct mdss_mdp_mixer *mixer;
- if (!ctl) {
- pr_debug("there is no ctl attached to fb\n");
- return 0;
- }
- mixer = mdss_mdp_mixer_get(ctl, MDSS_MDP_MIXER_MUX_LEFT);
- if (mixer && (mixer->num > ctl->mdata->nad_cfgs)) {
- if (!mixer)
- pr_warn("there is no mixer attached to fb\n");
- else
- pr_debug("mixer attached (%d) doesnt support ad\n",
- mixer->num);
- return 0;
- }
- mixer = mdss_mdp_mixer_get(ctl, MDSS_MDP_MIXER_MUX_RIGHT);
- if (mixer && (mixer->num > ctl->mdata->nad_cfgs))
- return 0;
- return 1;
- }
- static ssize_t mdss_mdp_ad_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct fb_info *fbi = dev_get_drvdata(dev);
- struct msm_fb_data_type *mfd = fbi->par;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- int ret, state;
- state = mdss_mdp_ad_is_supported(mfd) ? mdp5_data->ad_state : -1;
- ret = scnprintf(buf, PAGE_SIZE, "%d", state);
- return ret;
- }
- static ssize_t mdss_mdp_ad_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
- {
- struct fb_info *fbi = dev_get_drvdata(dev);
- struct msm_fb_data_type *mfd = fbi->par;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- int ret, ad;
- ret = kstrtoint(buf, 10, &ad);
- if (ret) {
- pr_err("Invalid input for ad\n");
- return -EINVAL;
- }
- mdp5_data->ad_state = ad;
- sysfs_notify(&dev->kobj, NULL, "ad");
- return count;
- }
- static DEVICE_ATTR(vsync_event, S_IRUGO, mdss_mdp_vsync_show_event, NULL);
- static DEVICE_ATTR(ad, S_IRUGO | S_IWUSR | S_IWGRP, mdss_mdp_ad_show,
- mdss_mdp_ad_store);
- static struct attribute *mdp_overlay_sysfs_attrs[] = {
- &dev_attr_vsync_event.attr,
- &dev_attr_ad.attr,
- NULL,
- };
- static struct attribute_group mdp_overlay_sysfs_group = {
- .attrs = mdp_overlay_sysfs_attrs,
- };
- static int mdss_mdp_hw_cursor_update(struct msm_fb_data_type *mfd,
- struct fb_cursor *cursor)
- {
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- struct mdss_mdp_mixer *mixer;
- struct fb_image *img = &cursor->image;
- u32 blendcfg;
- int off, ret = 0;
- if (!mfd->cursor_buf && (cursor->set & FB_CUR_SETIMAGE)) {
- mfd->cursor_buf = dma_alloc_coherent(NULL, MDSS_MDP_CURSOR_SIZE,
- (dma_addr_t *) &mfd->cursor_buf_phys,
- GFP_KERNEL);
- if (!mfd->cursor_buf) {
- pr_err("can't allocate cursor buffer\n");
- return -ENOMEM;
- }
- ret = msm_iommu_map_contig_buffer(mfd->cursor_buf_phys,
- mdss_get_iommu_domain(MDSS_IOMMU_DOMAIN_UNSECURE),
- 0, MDSS_MDP_CURSOR_SIZE, SZ_4K, 0,
- &(mfd->cursor_buf_iova));
- if (IS_ERR_VALUE(ret)) {
- dma_free_coherent(NULL, MDSS_MDP_CURSOR_SIZE,
- mfd->cursor_buf,
- (dma_addr_t) mfd->cursor_buf_phys);
- pr_err("unable to map cursor buffer to iommu(%d)\n",
- ret);
- return -ENOMEM;
- }
- }
- mixer = mdss_mdp_mixer_get(mdp5_data->ctl, MDSS_MDP_MIXER_MUX_DEFAULT);
- off = MDSS_MDP_REG_LM_OFFSET(mixer->num);
- if (!mixer)
- return -ENODEV;
- if ((img->width > MDSS_MDP_CURSOR_WIDTH) ||
- (img->height > MDSS_MDP_CURSOR_HEIGHT) ||
- (img->depth != 32))
- return -EINVAL;
- pr_debug("mixer=%d enable=%x set=%x\n", mixer->num, cursor->enable,
- cursor->set);
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_ON, false);
- blendcfg = MDSS_MDP_REG_READ(off + MDSS_MDP_REG_LM_CURSOR_BLEND_CONFIG);
- if (cursor->set & FB_CUR_SETPOS)
- MDSS_MDP_REG_WRITE(off + MDSS_MDP_REG_LM_CURSOR_START_XY,
- (img->dy << 16) | img->dx);
- if (cursor->set & FB_CUR_SETIMAGE) {
- int calpha_en, transp_en, alpha, size, cursor_addr;
- ret = copy_from_user(mfd->cursor_buf, img->data,
- img->width * img->height * 4);
- if (ret)
- return ret;
- if (is_mdss_iommu_attached())
- cursor_addr = mfd->cursor_buf_iova;
- else
- cursor_addr = mfd->cursor_buf_phys;
- if (img->bg_color == 0xffffffff)
- transp_en = 0;
- else
- transp_en = 1;
- alpha = (img->fg_color & 0xff000000) >> 24;
- if (alpha)
- calpha_en = 0x0; /* xrgb */
- else
- calpha_en = 0x2; /* argb */
- size = (img->height << 16) | img->width;
- MDSS_MDP_REG_WRITE(off + MDSS_MDP_REG_LM_CURSOR_IMG_SIZE, size);
- MDSS_MDP_REG_WRITE(off + MDSS_MDP_REG_LM_CURSOR_SIZE, size);
- MDSS_MDP_REG_WRITE(off + MDSS_MDP_REG_LM_CURSOR_STRIDE,
- img->width * 4);
- MDSS_MDP_REG_WRITE(off + MDSS_MDP_REG_LM_CURSOR_BASE_ADDR,
- cursor_addr);
- wmb();
- blendcfg &= ~0x1;
- blendcfg |= (transp_en << 3) | (calpha_en << 1);
- MDSS_MDP_REG_WRITE(off + MDSS_MDP_REG_LM_CURSOR_BLEND_CONFIG,
- blendcfg);
- if (calpha_en)
- MDSS_MDP_REG_WRITE(off +
- MDSS_MDP_REG_LM_CURSOR_BLEND_PARAM,
- alpha);
- if (transp_en) {
- MDSS_MDP_REG_WRITE(off +
- MDSS_MDP_REG_LM_CURSOR_BLEND_TRANSP_LOW0,
- ((img->bg_color & 0xff00) << 8) |
- (img->bg_color & 0xff));
- MDSS_MDP_REG_WRITE(off +
- MDSS_MDP_REG_LM_CURSOR_BLEND_TRANSP_LOW1,
- ((img->bg_color & 0xff0000) >> 16));
- MDSS_MDP_REG_WRITE(off +
- MDSS_MDP_REG_LM_CURSOR_BLEND_TRANSP_HIGH0,
- ((img->bg_color & 0xff00) << 8) |
- (img->bg_color & 0xff));
- MDSS_MDP_REG_WRITE(off +
- MDSS_MDP_REG_LM_CURSOR_BLEND_TRANSP_HIGH1,
- ((img->bg_color & 0xff0000) >> 16));
- }
- }
- if (!cursor->enable != !(blendcfg & 0x1)) {
- if (cursor->enable) {
- pr_debug("enable hw cursor on mixer=%d\n", mixer->num);
- blendcfg |= 0x1;
- } else {
- pr_debug("disable hw cursor on mixer=%d\n", mixer->num);
- blendcfg &= ~0x1;
- }
- MDSS_MDP_REG_WRITE(off + MDSS_MDP_REG_LM_CURSOR_BLEND_CONFIG,
- blendcfg);
- mixer->cursor_enabled = cursor->enable;
- mixer->params_changed++;
- }
- mixer->ctl->flush_bits |= BIT(6) << mixer->num;
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_OFF, false);
- return 0;
- }
- static int mdss_bl_scale_config(struct msm_fb_data_type *mfd,
- struct mdp_bl_scale_data *data)
- {
- int ret = 0;
- int curr_bl;
- mutex_lock(&mfd->bl_lock);
- curr_bl = mfd->bl_level;
- mfd->bl_scale = data->scale;
- mfd->bl_min_lvl = data->min_lvl;
- pr_debug("update scale = %d, min_lvl = %d\n", mfd->bl_scale,
- mfd->bl_min_lvl);
- /* Update current backlight to use new scaling, if it is not zero */
- if (curr_bl)
- mdss_fb_set_backlight(mfd, curr_bl);
- mutex_unlock(&mfd->bl_lock);
- return ret;
- }
- static int mdss_mdp_pp_ioctl(struct msm_fb_data_type *mfd,
- void __user *argp)
- {
- int ret;
- struct msmfb_mdp_pp mdp_pp;
- u32 copyback = 0;
- u32 copy_from_kernel = 0;
- if (mfd->panel_info->partial_update_enabled) {
- pr_err("Partical update feature is enabled.");
- return -EPERM;
- }
- ret = copy_from_user(&mdp_pp, argp, sizeof(mdp_pp));
- if (ret)
- return ret;
- /* Supprt only MDP register read/write and
- exit_dcm in DCM state*/
- if (mfd->dcm_state == DCM_ENTER &&
- (mdp_pp.op != mdp_op_calib_buffer &&
- mdp_pp.op != mdp_op_calib_dcm_state))
- return -EPERM;
- switch (mdp_pp.op) {
- case mdp_op_pa_cfg:
- ret = mdss_mdp_pa_config(&mdp_pp.data.pa_cfg_data,
- ©back);
- break;
- case mdp_op_pa_v2_cfg:
- ret = mdss_mdp_pa_v2_config(&mdp_pp.data.pa_v2_cfg_data,
- ©back);
- break;
- case mdp_op_pcc_cfg:
- ret = mdss_mdp_pcc_config(&mdp_pp.data.pcc_cfg_data,
- ©back);
- break;
- case mdp_op_lut_cfg:
- switch (mdp_pp.data.lut_cfg_data.lut_type) {
- case mdp_lut_igc:
- ret = mdss_mdp_igc_lut_config(
- (struct mdp_igc_lut_data *)
- &mdp_pp.data.lut_cfg_data.data,
- ©back, copy_from_kernel);
- break;
- case mdp_lut_pgc:
- ret = mdss_mdp_argc_config(
- &mdp_pp.data.lut_cfg_data.data.pgc_lut_data,
- ©back);
- break;
- case mdp_lut_hist:
- ret = mdss_mdp_hist_lut_config(
- (struct mdp_hist_lut_data *)
- &mdp_pp.data.lut_cfg_data.data, ©back);
- break;
- default:
- ret = -ENOTSUPP;
- break;
- }
- break;
- case mdp_op_dither_cfg:
- ret = mdss_mdp_dither_config(
- &mdp_pp.data.dither_cfg_data,
- ©back);
- break;
- case mdp_op_gamut_cfg:
- ret = mdss_mdp_gamut_config(
- &mdp_pp.data.gamut_cfg_data,
- ©back);
- break;
- case mdp_bl_scale_cfg:
- ret = mdss_bl_scale_config(mfd, (struct mdp_bl_scale_data *)
- &mdp_pp.data.bl_scale_data);
- break;
- case mdp_op_ad_cfg:
- ret = mdss_mdp_ad_config(mfd, &mdp_pp.data.ad_init_cfg);
- break;
- case mdp_op_ad_input:
- ret = mdss_mdp_ad_input(mfd, &mdp_pp.data.ad_input, 1);
- if (ret > 0) {
- ret = 0;
- copyback = 1;
- }
- break;
- case mdp_op_calib_cfg:
- ret = mdss_mdp_calib_config((struct mdp_calib_config_data *)
- &mdp_pp.data.calib_cfg, ©back);
- break;
- case mdp_op_calib_mode:
- ret = mdss_mdp_calib_mode(mfd, &mdp_pp.data.mdss_calib_cfg);
- break;
- case mdp_op_calib_buffer:
- ret = mdss_mdp_calib_config_buffer(
- (struct mdp_calib_config_buffer *)
- &mdp_pp.data.calib_buffer, ©back);
- break;
- case mdp_op_calib_dcm_state:
- ret = mdss_fb_dcm(mfd, mdp_pp.data.calib_dcm.dcm_state);
- break;
- default:
- pr_err("Unsupported request to MDP_PP IOCTL. %d = op\n",
- mdp_pp.op);
- ret = -EINVAL;
- break;
- }
- if ((ret == 0) && copyback)
- ret = copy_to_user(argp, &mdp_pp, sizeof(struct msmfb_mdp_pp));
- return ret;
- }
- static int mdss_mdp_histo_ioctl(struct msm_fb_data_type *mfd, u32 cmd,
- void __user *argp)
- {
- int ret = -ENOSYS;
- struct mdp_histogram_data hist;
- struct mdp_histogram_start_req hist_req;
- u32 block;
- u32 pp_bus_handle;
- static int req = -1;
- if (mfd->panel_info->partial_update_enabled) {
- pr_err("Partical update feature is enabled.");
- return -EPERM;
- }
- switch (cmd) {
- case MSMFB_HISTOGRAM_START:
- if (!mfd->panel_power_on)
- return -EPERM;
- pp_bus_handle = mdss_mdp_get_mdata()->pp_bus_hdl;
- req = msm_bus_scale_client_update_request(pp_bus_handle,
- PP_CLK_CFG_ON);
- if (req)
- pr_err("Updated pp_bus_scale failed, ret = %d", req);
- ret = copy_from_user(&hist_req, argp, sizeof(hist_req));
- if (ret)
- return ret;
- ret = mdss_mdp_hist_start(&hist_req);
- break;
- case MSMFB_HISTOGRAM_STOP:
- ret = copy_from_user(&block, argp, sizeof(int));
- if (ret)
- return ret;
- ret = mdss_mdp_hist_stop(block);
- if (ret)
- return ret;
- if (!req) {
- pp_bus_handle = mdss_mdp_get_mdata()->pp_bus_hdl;
- req = msm_bus_scale_client_update_request(pp_bus_handle,
- PP_CLK_CFG_OFF);
- if (req)
- pr_err("Updated pp_bus_scale failed, ret = %d",
- req);
- }
- break;
- case MSMFB_HISTOGRAM:
- if (!mfd->panel_power_on)
- return -EPERM;
- ret = copy_from_user(&hist, argp, sizeof(hist));
- if (ret)
- return ret;
- ret = mdss_mdp_hist_collect(&hist);
- if (!ret)
- ret = copy_to_user(argp, &hist, sizeof(hist));
- break;
- default:
- break;
- }
- return ret;
- }
- static int mdss_fb_set_metadata(struct msm_fb_data_type *mfd,
- struct msmfb_metadata *metadata)
- {
- struct mdss_data_type *mdata = mfd_to_mdata(mfd);
- struct mdss_mdp_ctl *ctl = mfd_to_ctl(mfd);
- int ret = 0;
- if (!ctl)
- return -EPERM;
- switch (metadata->op) {
- case metadata_op_vic:
- if (mfd->panel_info)
- mfd->panel_info->vic =
- metadata->data.video_info_code;
- else
- ret = -EINVAL;
- break;
- case metadata_op_crc:
- if (!mfd->panel_power_on)
- return -EPERM;
- ret = mdss_misr_set(mdata, &metadata->data.misr_request, ctl);
- break;
- case metadata_op_wb_format:
- ret = mdss_mdp_wb_set_format(mfd,
- metadata->data.mixer_cfg.writeback_format);
- break;
- case metadata_op_wb_secure:
- ret = mdss_mdp_wb_set_secure(mfd, metadata->data.secure_en);
- break;
- default:
- pr_warn("unsupported request to MDP META IOCTL\n");
- ret = -EINVAL;
- break;
- }
- return ret;
- }
- static int mdss_fb_get_hw_caps(struct msm_fb_data_type *mfd,
- struct mdss_hw_caps *caps)
- {
- struct mdss_data_type *mdata = mfd_to_mdata(mfd);
- caps->mdp_rev = mdata->mdp_rev;
- caps->vig_pipes = mdata->nvig_pipes;
- caps->rgb_pipes = mdata->nrgb_pipes;
- caps->dma_pipes = mdata->ndma_pipes;
- if (mdata->has_bwc)
- caps->features |= MDP_BWC_EN;
- if (mdata->has_decimation)
- caps->features |= MDP_DECIMATION_EN;
- caps->max_smp_cnt = mdss_res->smp_mb_cnt;
- caps->smp_per_pipe = mdata->smp_mb_per_pipe;
- return 0;
- }
- static int mdss_fb_get_metadata(struct msm_fb_data_type *mfd,
- struct msmfb_metadata *metadata)
- {
- struct mdss_data_type *mdata = mfd_to_mdata(mfd);
- struct mdss_mdp_ctl *ctl = mfd_to_ctl(mfd);
- int ret = 0;
- if (!ctl)
- return -EPERM;
- switch (metadata->op) {
- case metadata_op_frame_rate:
- metadata->data.panel_frame_rate =
- mdss_panel_get_framerate(mfd->panel_info);
- break;
- case metadata_op_get_caps:
- ret = mdss_fb_get_hw_caps(mfd, &metadata->data.caps);
- break;
- case metadata_op_get_ion_fd:
- if (mfd->fb_ion_handle) {
- metadata->data.fbmem_ionfd =
- dma_buf_fd(mfd->fbmem_buf, 0);
- if (metadata->data.fbmem_ionfd < 0)
- pr_err("fd allocation failed. fd = %d\n",
- metadata->data.fbmem_ionfd);
- }
- break;
- case metadata_op_crc:
- if (!mfd->panel_power_on)
- return -EPERM;
- ret = mdss_misr_get(mdata, &metadata->data.misr_request, ctl);
- break;
- case metadata_op_wb_format:
- ret = mdss_mdp_wb_get_format(mfd, &metadata->data.mixer_cfg);
- break;
- case metadata_op_wb_secure:
- ret = mdss_mdp_wb_get_secure(mfd, &metadata->data.secure_en);
- break;
- default:
- pr_warn("Unsupported request to MDP META IOCTL.\n");
- ret = -EINVAL;
- break;
- }
- return ret;
- }
- static int __handle_overlay_prepare(struct msm_fb_data_type *mfd,
- struct mdp_overlay_list *ovlist,
- struct mdp_overlay *overlays)
- {
- struct mdss_mdp_pipe *right_plist[MDSS_MDP_MAX_STAGE] = { 0 };
- struct mdss_mdp_pipe *left_plist[MDSS_MDP_MAX_STAGE] = { 0 };
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- struct mdss_mdp_pipe *pipe;
- struct mdp_overlay *req;
- int ret = 0, left_cnt = 0, right_cnt = 0;
- int i;
- u32 new_reqs = 0;
- u32 left_lm_w = left_lm_w_from_mfd(mfd);
- ret = mutex_lock_interruptible(&mdp5_data->ov_lock);
- if (ret)
- return ret;
- if (!mfd->panel_power_on) {
- mutex_unlock(&mdp5_data->ov_lock);
- return -EPERM;
- }
- pr_debug("prepare fb%d num_overlays=%d\n", mfd->index,
- ovlist->num_overlays);
- for (i = 0; i < ovlist->num_overlays; i++) {
- req = overlays + i;
- req->z_order += MDSS_MDP_STAGE_0;
- ret = mdss_mdp_overlay_pipe_setup(mfd, req, &pipe);
- req->z_order -= MDSS_MDP_STAGE_0;
- if (IS_ERR_VALUE(ret))
- goto validate_exit;
- /* keep track of the new overlays to unset in case of errors */
- if (pipe->play_cnt == 0)
- new_reqs |= pipe->ndx;
- if (IS_RIGHT_MIXER_OV(req->flags, req->dst_rect.x, left_lm_w)) {
- if (right_cnt >= MDSS_MDP_MAX_STAGE) {
- pr_err("too many pipes on right mixer\n");
- ret = -EINVAL;
- goto validate_exit;
- }
- right_plist[right_cnt] = pipe;
- right_cnt++;
- } else {
- if (left_cnt >= MDSS_MDP_MAX_STAGE) {
- pr_err("too many pipes on left mixer\n");
- ret = -EINVAL;
- goto validate_exit;
- }
- left_plist[left_cnt] = pipe;
- left_cnt++;
- }
- }
- ret = mdss_mdp_perf_bw_check(mdp5_data->ctl, left_plist, left_cnt,
- right_plist, right_cnt);
- validate_exit:
- if (IS_ERR_VALUE(ret))
- mdss_mdp_overlay_release(mfd, new_reqs);
- mutex_unlock(&mdp5_data->ov_lock);
- ovlist->processed_overlays = i;
- return ret;
- }
- static int __handle_ioctl_overlay_prepare(struct msm_fb_data_type *mfd,
- void __user *argp)
- {
- struct mdp_overlay_list ovlist;
- struct mdp_overlay *req_list[OVERLAY_MAX];
- struct mdp_overlay *overlays;
- int i, ret;
- if (copy_from_user(&ovlist, argp, sizeof(ovlist)))
- return -EFAULT;
- if (ovlist.num_overlays >= OVERLAY_MAX) {
- pr_err("Number of overlays exceeds max\n");
- return -EINVAL;
- }
- overlays = kmalloc(ovlist.num_overlays * sizeof(*overlays), GFP_KERNEL);
- if (!overlays) {
- pr_err("Unable to allocate memory for overlays\n");
- return -ENOMEM;
- }
- if (copy_from_user(req_list, ovlist.overlay_list,
- sizeof(struct mdp_overlay*) * ovlist.num_overlays)) {
- ret = -EFAULT;
- goto validate_exit;
- }
- for (i = 0; i < ovlist.num_overlays; i++) {
- if (copy_from_user(overlays + i, req_list[i],
- sizeof(struct mdp_overlay))) {
- ret = -EFAULT;
- goto validate_exit;
- }
- }
- ret = __handle_overlay_prepare(mfd, &ovlist, overlays);
- if (!IS_ERR_VALUE(ret)) {
- for (i = 0; i < ovlist.num_overlays; i++) {
- if (copy_to_user(req_list[i], overlays + i,
- sizeof(struct mdp_overlay))) {
- ret = -EFAULT;
- goto validate_exit;
- }
- }
- }
- if (copy_to_user(argp, &ovlist, sizeof(ovlist)))
- ret = -EFAULT;
- validate_exit:
- kfree(overlays);
- return ret;
- }
- static int mdss_mdp_overlay_ioctl_handler(struct msm_fb_data_type *mfd,
- u32 cmd, void __user *argp)
- {
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- struct mdp_overlay *req = NULL;
- int val, ret = -ENOSYS;
- struct msmfb_metadata metadata;
- switch (cmd) {
- case MSMFB_MDP_PP:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_MDP_PP\n", __func__);
- ret = mdss_mdp_pp_ioctl(mfd, argp);
- break;
- case MSMFB_HISTOGRAM_START:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_HISTOGRAM_START\n", __func__);
- case MSMFB_HISTOGRAM_STOP:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_HISTOGRAM_STOP\n", __func__);
- case MSMFB_HISTOGRAM:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_HISTOGRAM\n", __func__);
- ret = mdss_mdp_histo_ioctl(mfd, cmd, argp);
- break;
- case MSMFB_OVERLAY_GET:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_OVERLAY_GET\n", __func__);
- req = kmalloc(sizeof(struct mdp_overlay), GFP_KERNEL);
- if (!req)
- return -ENOMEM;
- ret = copy_from_user(req, argp, sizeof(*req));
- if (!ret) {
- ret = mdss_mdp_overlay_get(mfd, req);
- if (!IS_ERR_VALUE(ret))
- ret = copy_to_user(argp, req, sizeof(*req));
- }
- if (ret)
- pr_debug("OVERLAY_GET failed (%d)\n", ret);
- break;
- case MSMFB_OVERLAY_SET:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_OVERLAY_SET\n", __func__);
- req = kmalloc(sizeof(struct mdp_overlay), GFP_KERNEL);
- if (!req)
- {
- pr_err("MSMFB_OVERLAY_SET kmalloc result was NULL \n");
- return -ENOMEM;
- }
- ret = copy_from_user(req, argp, sizeof(*req));
- if (!ret) {
- ret = mdss_mdp_overlay_set(mfd, req);
- if (!IS_ERR_VALUE(ret))
- ret = copy_to_user(argp, req, sizeof(*req));
- }
- if (ret)
- pr_debug("OVERLAY_SET failed (%d)\n", ret);
- break;
- case MSMFB_OVERLAY_UNSET:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_OVERLAY_UNSET\n", __func__);
- if (!IS_ERR_VALUE(copy_from_user(&val, argp, sizeof(val))))
- ret = mdss_mdp_overlay_unset(mfd, val);
- break;
- case MSMFB_OVERLAY_PLAY_ENABLE:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_OVERLAY_PLAY_ENABLE\n", __func__);
- if (!copy_from_user(&val, argp, sizeof(val))) {
- mdp5_data->overlay_play_enable = val;
- ret = 0;
- } else {
- pr_err("OVERLAY_PLAY_ENABLE failed (%d)\n", ret);
- ret = -EFAULT;
- }
- break;
- case MSMFB_OVERLAY_PLAY:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_OVERLAY_PLAY\n", __func__);
- if (mdp5_data->overlay_play_enable) {
- struct msmfb_overlay_data data;
- ret = copy_from_user(&data, argp, sizeof(data));
- if (!ret)
- ret = mdss_mdp_overlay_play(mfd, &data);
- if (ret)
- pr_debug("OVERLAY_PLAY failed (%d)\n", ret);
- } else {
- ret = 0;
- }
- break;
- case MSMFB_OVERLAY_PLAY_WAIT:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_OVERLAY_PLAY_WAIT\n", __func__);
- if (mdp5_data->overlay_play_enable) {
- struct msmfb_overlay_data data;
- ret = copy_from_user(&data, argp, sizeof(data));
- if (!ret)
- ret = mdss_mdp_overlay_play_wait(mfd, &data);
- if (ret)
- pr_err("OVERLAY_PLAY_WAIT failed (%d)\n", ret);
- } else {
- ret = 0;
- }
- break;
- case MSMFB_VSYNC_CTRL:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_VSYNC_CTRL\n", __func__);
- case MSMFB_OVERLAY_VSYNC_CTRL:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_OVERLAY_VSYNC_CTRL\n", __func__);
- if (!copy_from_user(&val, argp, sizeof(val))) {
- mutex_lock(&mfd->ctx_lock);
- ret = mdss_mdp_overlay_vsync_ctrl(mfd, val);
- mutex_unlock(&mfd->ctx_lock);
- } else {
- pr_err("MSMFB_OVERLAY_VSYNC_CTRL failed (%d)\n", ret);
- ret = -EFAULT;
- }
- break;
- case MSMFB_OVERLAY_COMMIT:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_OVERLAY_COMMIT\n", __func__);
- mdss_fb_wait_for_fence(&(mfd->mdp_sync_pt_data));
- ret = mfd->mdp.kickoff_fnc(mfd, NULL);
- break;
- case MSMFB_METADATA_SET:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_METADATA_SET\n", __func__);
- ret = copy_from_user(&metadata, argp, sizeof(metadata));
- if (ret)
- return ret;
- ret = mdss_fb_set_metadata(mfd, &metadata);
- break;
- case MSMFB_METADATA_GET:
- ID_PRINTK(ID_HDMI, "%s() MSMFB_METADATA_GET\n", __func__);
- ret = copy_from_user(&metadata, argp, sizeof(metadata));
- if (ret)
- return ret;
- ret = mdss_fb_get_metadata(mfd, &metadata);
- if (!ret)
- ret = copy_to_user(argp, &metadata, sizeof(metadata));
- break;
- case MSMFB_OVERLAY_PREPARE:
- ret = __handle_ioctl_overlay_prepare(mfd, argp);
- break;
- default:
- ID_PRINTK(ID_HDMI, "%s() default\n", __func__);
- if (mfd->panel.type == WRITEBACK_PANEL)
- ret = mdss_mdp_wb_ioctl_handler(mfd, cmd, argp);
- break;
- }
- kfree(req);
- return ret;
- }
- /**
- * __mdss_mdp_overlay_ctl_init - Helper function to intialize control structure
- * @mfd: msm frame buffer data structure associated with the fb device.
- *
- * Helper function that allocates and initializes the mdp control structure
- * for a frame buffer device. Whenver applicable, this function will also setup
- * the control for the split display path as well.
- *
- * Return: pointer to the newly allocated control structure.
- */
- static struct mdss_mdp_ctl *__mdss_mdp_overlay_ctl_init(
- struct msm_fb_data_type *mfd)
- {
- int rc = 0;
- struct mdss_mdp_ctl *ctl;
- struct mdss_panel_data *pdata;
- if (!mfd)
- return ERR_PTR(-EINVAL);
- pdata = dev_get_platdata(&mfd->pdev->dev);
- if (!pdata) {
- pr_err("no panel connected for fb%d\n", mfd->index);
- rc = -ENODEV;
- goto error;
- }
- ctl = mdss_mdp_ctl_init(pdata, mfd);
- if (IS_ERR_OR_NULL(ctl)) {
- pr_err("Unable to initialize ctl for fb%d\n",
- mfd->index);
- rc = PTR_ERR(ctl);
- goto error;
- }
- ctl->vsync_handler.vsync_handler =
- mdss_mdp_overlay_handle_vsync;
- ctl->vsync_handler.cmd_post_flush = false;
- ctl->recover_underrun_handler.vsync_handler =
- mdss_mdp_recover_underrun_handler;
- ctl->recover_underrun_handler.cmd_post_flush = false;
- INIT_WORK(&ctl->remove_underrun_handler,
- remove_underrun_vsync_handler);
- if (mfd->split_display && pdata->next) {
- /* enable split display */
- rc = mdss_mdp_ctl_split_display_setup(ctl, pdata->next);
- if (rc) {
- mdss_mdp_ctl_destroy(ctl);
- goto error;
- }
- }
- error:
- if (rc)
- return ERR_PTR(rc);
- else
- return ctl;
- }
- static int mdss_mdp_overlay_on(struct msm_fb_data_type *mfd)
- {
- int rc;
- struct mdss_overlay_private *mdp5_data;
- struct mdss_mdp_ctl *ctl = NULL;
- struct mdss_panel_info *pinfo = mfd->panel_info;
- if (!mfd)
- return -ENODEV;
- if (mfd->key != MFD_KEY)
- return -EINVAL;
- pr_info("%s: ++ \n",__func__);
- mdp5_data = mfd_to_mdp5_data(mfd);
- if (!mdp5_data)
- return -EINVAL;
- if (!mdp5_data->ctl) {
- ctl = __mdss_mdp_overlay_ctl_init(mfd);
- if (IS_ERR_OR_NULL(ctl))
- return PTR_ERR(ctl);
- mdp5_data->ctl = ctl;
- }
- if (!mfd->panel_info->cont_splash_enabled &&
- (mfd->panel_info->type != DTV_PANEL) &&
- !(pinfo->alpm_event && pinfo->alpm_event(CHECK_PREVIOUS_STATUS))) {
- rc = mdss_mdp_overlay_start(mfd);
- if (!IS_ERR_VALUE(rc) &&
- (mfd->panel_info->type != WRITEBACK_PANEL)) {
- atomic_inc(&mfd->mdp_sync_pt_data.commit_cnt);
- rc = mdss_mdp_overlay_kickoff(mfd, NULL);
- }
- } else {
- rc = mdss_mdp_ctl_setup(mdp5_data->ctl);
- if (rc)
- return rc;
- }
- if (IS_ERR_VALUE(rc)) {
- pr_err("Failed to turn on fb%d\n", mfd->index);
- mdss_mdp_overlay_off(mfd);
- }
- pr_info("%s: -- \n",__func__);
- return rc;
- }
- static int mdss_mdp_overlay_off(struct msm_fb_data_type *mfd)
- {
- int rc;
- struct mdss_overlay_private *mdp5_data;
- struct mdss_mdp_mixer *mixer;
- int need_cleanup;
- struct mdss_panel_info *pinfo;
- if (!mfd)
- return -ENODEV;
- if (mfd->key != MFD_KEY)
- return -EINVAL;
- pinfo = mfd->panel_info;
- mdp5_data = mfd_to_mdp5_data(mfd);
- if (!mdp5_data || !mdp5_data->ctl) {
- pr_err("ctl not initialized\n");
- return -ENODEV;
- }
- if (!mdp5_data->ctl->power_on)
- return 0;
- mdss_mdp_overlay_free_fb_pipe(mfd);
- mixer = mdss_mdp_mixer_get(mdp5_data->ctl, MDSS_MDP_MIXER_MUX_LEFT);
- if (mixer)
- mixer->cursor_enabled = 0;
- mixer = mdss_mdp_mixer_get(mdp5_data->ctl, MDSS_MDP_MIXER_MUX_RIGHT);
- if (mixer)
- mixer->cursor_enabled = 0;
- mutex_lock(&mdp5_data->list_lock);
- need_cleanup = !list_empty(&mdp5_data->pipes_cleanup);
- mutex_unlock(&mdp5_data->list_lock);
- if (need_cleanup) {
- if (pinfo->alpm_event && pinfo->alpm_event(CHECK_CURRENT_STATUS)) {
- pr_debug("[ALPM_DEBUG] %s, Skip cleanup pipes on fb%d\n",\
- __func__, mfd->index);
- } else {
- pr_debug("cleaning up pipes on fb%d\n", mfd->index);
- mdss_mdp_overlay_kickoff(mfd, NULL);
- }
- }
- /*
- * If retire fences are still active wait for a vsync time
- * for retire fence to be updated.
- * As a last resort signal the timeline if vsync doesn't arrive.
- */
- if (mdp5_data->retire_cnt) {
- u32 fps = mdss_panel_get_framerate(mfd->panel_info);
- u32 vsync_time = 1000 / (fps ? : DEFAULT_FRAME_RATE);
- msleep(vsync_time);
- __vsync_retire_signal(mfd, mdp5_data->retire_cnt);
- }
- rc = mdss_mdp_ctl_stop(mdp5_data->ctl);
- if (rc == 0) {
- __mdss_mdp_overlay_free_list_purge(mfd);
- mdss_mdp_ctl_notifier_unregister(mdp5_data->ctl,
- &mfd->mdp_sync_pt_data.notifier);
- if (!mfd->ref_cnt) {
- mdp5_data->borderfill_enable = false;
- mdss_mdp_ctl_destroy(mdp5_data->ctl);
- mdp5_data->ctl = NULL;
- }
- if (atomic_dec_return(&ov_active_panels) == 0)
- mdss_mdp_rotator_release_all();
- rc = pm_runtime_put(&mfd->pdev->dev);
- if (rc)
- pr_err("unable to suspend w/pm_runtime_put (%d)\n", rc);
- }
- return rc;
- }
- int mdss_panel_register_done(struct mdss_panel_data *pdata)
- {
- static int first_register=true;
- /*
- * Clocks are already on if continuous splash is enabled,
- * increasing ref_cnt to help balance clocks once done.
- */
- if (pdata->panel_info.cont_splash_enabled && first_register) {
- mdss_mdp_footswitch_ctrl_splash(1);
- first_register=false;
- }
- return 0;
- }
- static int __mdss_mdp_ctl_handoff(struct mdss_mdp_ctl *ctl,
- struct mdss_data_type *mdata)
- {
- int rc = 0;
- int i, j;
- u32 mixercfg;
- struct mdss_mdp_pipe *pipe = NULL;
- if (!ctl || !mdata)
- return -EINVAL;
- for (i = 0; i < mdata->nmixers_intf; i++) {
- mixercfg = mdss_mdp_ctl_read(ctl, MDSS_MDP_REG_CTL_LAYER(i));
- pr_debug("for lm%d mixercfg = 0x%09x\n", i, mixercfg);
- j = MDSS_MDP_SSPP_VIG0;
- for (; j < MDSS_MDP_MAX_SSPP && mixercfg; j++) {
- u32 cfg = j * 3;
- if ((j == MDSS_MDP_SSPP_VIG3) ||
- (j == MDSS_MDP_SSPP_RGB3)) {
- /* Add 2 to account for Cursor & Border bits */
- cfg += 2;
- }
- if (mixercfg & (0x7 << cfg)) {
- pr_debug("Pipe %d staged\n", j);
- pipe = mdss_mdp_pipe_search(mdata, BIT(j));
- if (!pipe) {
- pr_warn("Invalid pipe %d staged\n", j);
- continue;
- }
- rc = mdss_mdp_pipe_handoff(pipe);
- if (rc) {
- pr_err("Failed to handoff pipe%d\n",
- pipe->num);
- goto exit;
- }
- rc = mdss_mdp_mixer_handoff(ctl, i, pipe);
- if (rc) {
- pr_err("failed to handoff mix%d\n", i);
- goto exit;
- }
- }
- }
- }
- exit:
- return rc;
- }
- /**
- * mdss_mdp_overlay_handoff() - Read MDP registers to handoff an active ctl path
- * @mfd: Msm frame buffer structure associated with the fb device.
- *
- * This function populates the MDP software structures with the current state of
- * the MDP hardware to handoff any active control path for the framebuffer
- * device. This is needed to identify any ctl, mixers and pipes being set up by
- * the bootloader to display the splash screen when the continuous splash screen
- * feature is enabled in kernel.
- */
- static int mdss_mdp_overlay_handoff(struct msm_fb_data_type *mfd)
- {
- int rc = 0;
- struct mdss_data_type *mdata = mfd_to_mdata(mfd);
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- struct mdss_mdp_ctl *ctl = NULL;
- struct mdss_mdp_ctl *sctl = NULL;
- if (!mdp5_data->ctl) {
- ctl = __mdss_mdp_overlay_ctl_init(mfd);
- if (IS_ERR_OR_NULL(ctl)) {
- rc = PTR_ERR(ctl);
- goto error;
- }
- mdp5_data->ctl = ctl;
- }
- if (IS_ERR_OR_NULL(ctl)) {
- rc = PTR_ERR(ctl);
- goto error;
- }
- /*
- * vsync interrupt needs on during continuous splash, this is
- * to initialize necessary ctl members here.
- */
- rc = mdss_mdp_ctl_start(ctl, true);
- if (rc) {
- pr_err("Failed to initialize ctl\n");
- goto error;
- }
- ctl->clk_rate = mdss_mdp_get_clk_rate(MDSS_CLK_MDP_SRC);
- pr_debug("Set the ctl clock rate to %d Hz\n", ctl->clk_rate);
- rc = __mdss_mdp_ctl_handoff(ctl, mdata);
- if (rc) {
- pr_err("primary ctl handoff failed. rc=%d\n", rc);
- goto error;
- }
- if (mfd->split_display) {
- sctl = mdss_mdp_get_split_ctl(ctl);
- if (!sctl) {
- pr_err("cannot get secondary ctl. fail the handoff\n");
- rc = -EPERM;
- goto error;
- }
- rc = __mdss_mdp_ctl_handoff(sctl, mdata);
- if (rc) {
- pr_err("secondary ctl handoff failed. rc=%d\n", rc);
- goto error;
- }
- }
- rc = mdss_mdp_smp_handoff(mdata);
- if (rc)
- pr_err("Failed to handoff smps\n");
- mdp5_data->handoff = true;
- error:
- if (rc && ctl) {
- mdss_mdp_handoff_cleanup_pipes(mfd, MDSS_MDP_PIPE_TYPE_RGB);
- mdss_mdp_handoff_cleanup_pipes(mfd, MDSS_MDP_PIPE_TYPE_VIG);
- mdss_mdp_handoff_cleanup_pipes(mfd, MDSS_MDP_PIPE_TYPE_DMA);
- mdss_mdp_ctl_destroy(ctl);
- mdp5_data->ctl = NULL;
- mdp5_data->handoff = false;
- }
- return rc;
- }
- static void __vsync_retire_handle_vsync(struct mdss_mdp_ctl *ctl, ktime_t t)
- {
- struct msm_fb_data_type *mfd = ctl->mfd;
- struct mdss_overlay_private *mdp5_data;
- if (!mfd || !mfd->mdp.private1) {
- pr_warn("Invalid handle for vsync\n");
- return;
- }
- mdp5_data = mfd_to_mdp5_data(mfd);
- queue_kthread_work(&mdp5_data->worker, &mdp5_data->vsync_work);
- }
- static void __vsync_retire_work_handler(struct kthread_work *work)
- {
- struct mdss_overlay_private *mdp5_data =
- container_of(work, typeof(*mdp5_data), vsync_work);
- if (!mdp5_data->ctl || !mdp5_data->ctl->mfd)
- return;
- if (!mdp5_data->ctl->remove_vsync_handler)
- return;
- __vsync_retire_signal(mdp5_data->ctl->mfd, 1);
- }
- static void __vsync_retire_signal(struct msm_fb_data_type *mfd, int val)
- {
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- mutex_lock(&mfd->mdp_sync_pt_data.sync_mutex);
- if (mdp5_data->retire_cnt > 0) {
- sw_sync_timeline_inc(mdp5_data->vsync_timeline, val);
- mdp5_data->retire_cnt -= min(val, mdp5_data->retire_cnt);
- if (mdp5_data->retire_cnt == 0) {
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_ON, false);
- mdp5_data->ctl->remove_vsync_handler(mdp5_data->ctl,
- &mdp5_data->vsync_retire_handler);
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_OFF, false);
- }
- }
- mutex_unlock(&mfd->mdp_sync_pt_data.sync_mutex);
- }
- static struct sync_fence *
- __vsync_retire_get_fence(struct msm_sync_pt_data *sync_pt_data)
- {
- struct msm_fb_data_type *mfd;
- struct mdss_overlay_private *mdp5_data;
- struct mdss_mdp_ctl *ctl;
- int rc, value;
- mfd = container_of(sync_pt_data, typeof(*mfd), mdp_sync_pt_data);
- mdp5_data = mfd_to_mdp5_data(mfd);
- if (!mdp5_data || !mdp5_data->ctl)
- return ERR_PTR(-ENODEV);
- ctl = mdp5_data->ctl;
- if (!ctl->add_vsync_handler)
- return ERR_PTR(-EOPNOTSUPP);
- if (!ctl->power_on) {
- pr_debug("fb%d vsync pending first update\n", mfd->index);
- return ERR_PTR(-EPERM);
- }
- if (!mdp5_data->vsync_retire_handler.enabled) {
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_ON, false);
- rc = ctl->add_vsync_handler(ctl,
- &mdp5_data->vsync_retire_handler);
- mdss_mdp_clk_ctrl(MDP_BLOCK_POWER_OFF, false);
- if (IS_ERR_VALUE(rc))
- return ERR_PTR(rc);
- }
- value = mdp5_data->vsync_timeline->value + 1 + mdp5_data->retire_cnt;
- mdp5_data->retire_cnt++;
- return mdss_fb_sync_get_fence(mdp5_data->vsync_timeline,
- "mdp-retire", value);
- }
- static int __vsync_retire_setup(struct msm_fb_data_type *mfd)
- {
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- char name[24];
- struct sched_param param = { .sched_priority = 5 };
- snprintf(name, sizeof(name), "mdss_fb%d_retire", mfd->index);
- mdp5_data->vsync_timeline = sw_sync_timeline_create(name);
- if (mdp5_data->vsync_timeline == NULL) {
- pr_err("cannot vsync create time line");
- return -ENOMEM;
- }
- init_kthread_worker(&mdp5_data->worker);
- init_kthread_work(&mdp5_data->vsync_work, __vsync_retire_work_handler);
- mdp5_data->thread = kthread_run(kthread_worker_fn,
- &mdp5_data->worker, "vsync_retire_work");
- if (IS_ERR(mdp5_data->thread)) {
- pr_err("unable to start vsync thread\n");
- mdp5_data->thread = NULL;
- return -ENOMEM;
- }
- sched_setscheduler(mdp5_data->thread, SCHED_FIFO, ¶m);
- mfd->mdp_sync_pt_data.get_retire_fence = __vsync_retire_get_fence;
- mdp5_data->vsync_retire_handler.vsync_handler =
- __vsync_retire_handle_vsync;
- mdp5_data->vsync_retire_handler.cmd_post_flush = false;
- return 0;
- }
- static int mdss_mdp_update_panel_info(struct msm_fb_data_type *mfd, int mode)
- {
- int ret = 0;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- struct mdss_mdp_ctl *ctl = mdp5_data->ctl;
- ret = mdss_mdp_ctl_intf_event(ctl, MDSS_EVENT_DSI_DYNAMIC_SWITCH,
- (void *)(unsigned long)mode);
- if (ret)
- pr_err("Dynamic switch to %s mode failed!\n",
- mode ? "command" : "video");
- /*
- * Destroy current ctrl sturcture as this is
- * going to be re-initialized with the requested mode.
- */
- mdss_mdp_ctl_destroy(mdp5_data->ctl);
- mdp5_data->ctl = NULL;
- return 0;
- }
- int mdss_mdp_overlay_init(struct msm_fb_data_type *mfd)
- {
- struct device *dev = mfd->fbi->dev;
- struct msm_mdp_interface *mdp5_interface = &mfd->mdp;
- struct mdss_overlay_private *mdp5_data = NULL;
- int rc;
- mdp5_interface->on_fnc = mdss_mdp_overlay_on;
- mdp5_interface->off_fnc = mdss_mdp_overlay_off;
- mdp5_interface->release_fnc = __mdss_mdp_overlay_release_all;
- mdp5_interface->do_histogram = NULL;
- mdp5_interface->cursor_update = mdss_mdp_hw_cursor_update;
- mdp5_interface->dma_fnc = mdss_mdp_overlay_pan_display;
- mdp5_interface->ioctl_handler = mdss_mdp_overlay_ioctl_handler;
- mdp5_interface->panel_register_done = mdss_panel_register_done;
- mdp5_interface->kickoff_fnc = mdss_mdp_overlay_kickoff;
- mdp5_interface->get_sync_fnc = mdss_mdp_rotator_sync_pt_get;
- mdp5_interface->splash_init_fnc = mdss_mdp_splash_init;
- mdp5_interface->configure_panel = mdss_mdp_update_panel_info;
- mdp5_data = kmalloc(sizeof(struct mdss_overlay_private), GFP_KERNEL);
- if (!mdp5_data) {
- pr_err("fail to allocate mdp5 private data structure");
- return -ENOMEM;
- }
- memset(mdp5_data, 0, sizeof(struct mdss_overlay_private));
- INIT_LIST_HEAD(&mdp5_data->pipes_used);
- INIT_LIST_HEAD(&mdp5_data->pipes_cleanup);
- INIT_LIST_HEAD(&mdp5_data->rot_proc_list);
- mutex_init(&mdp5_data->list_lock);
- mutex_init(&mdp5_data->ov_lock);
- mutex_init(&mdp5_data->dfps_lock);
- mdp5_data->hw_refresh = true;
- mdp5_data->overlay_play_enable = true;
- mdp5_data->mdata = dev_get_drvdata(mfd->pdev->dev.parent);
- if (!mdp5_data->mdata) {
- pr_err("unable to initialize overlay for fb%d\n", mfd->index);
- rc = -ENODEV;
- goto init_fail;
- }
- mfd->mdp.private1 = mdp5_data;
- mfd->wait_for_kickoff = true;
- rc = mdss_mdp_overlay_fb_parse_dt(mfd);
- if (rc)
- return rc;
- rc = sysfs_create_group(&dev->kobj, &mdp_overlay_sysfs_group);
- if (rc) {
- pr_err("vsync sysfs group creation failed, ret=%d\n", rc);
- goto init_fail;
- }
- mdp5_data->vsync_event_sd = sysfs_get_dirent(dev->kobj.sd, NULL,
- "vsync_event");
- if (!mdp5_data->vsync_event_sd) {
- pr_err("vsync_event sysfs lookup failed\n");
- rc = -ENODEV;
- goto init_fail;
- }
- if (mfd->panel_info->type == MIPI_VIDEO_PANEL) {
- rc = sysfs_create_group(&dev->kobj,
- &dynamic_fps_fs_attrs_group);
- if (rc) {
- pr_err("Error dfps sysfs creation ret=%d\n", rc);
- goto init_fail;
- }
- }
- if (mfd->panel_info->mipi.dynamic_switch_enabled ||
- mfd->panel_info->type == MIPI_CMD_PANEL) {
- rc = __vsync_retire_setup(mfd);
- if (IS_ERR_VALUE(rc)) {
- pr_err("unable to create vsync timeline\n");
- goto init_fail;
- }
- }
- mfd->mdp_sync_pt_data.async_wait_fences = true;
- rc = sysfs_create_link_nowarn(&dev->kobj,
- &mdp5_data->mdata->pdev->dev.kobj, "mdp");
- if (rc)
- pr_warn("problem creating link to mdp sysfs\n");
- pm_runtime_set_suspended(&mfd->pdev->dev);
- pm_runtime_enable(&mfd->pdev->dev);
- kobject_uevent(&dev->kobj, KOBJ_ADD);
- pr_debug("vsync kobject_uevent(KOBJ_ADD)\n");
- mdp5_data->cpu_pm_hdl = add_event_timer(NULL, (void *)mdp5_data);
- if (!mdp5_data->cpu_pm_hdl)
- pr_warn("%s: unable to add event timer\n", __func__);
- if (mfd->panel_info->cont_splash_enabled) {
- rc = mdss_mdp_overlay_handoff(mfd);
- if (rc) {
- /*
- * Even though handoff failed, it is not fatal.
- * MDP can continue, just that we would have a longer
- * delay in transitioning from splash screen to boot
- * animation
- */
- pr_warn("Overlay handoff failed for fb%d. rc=%d\n",
- mfd->index, rc);
- rc = 0;
- }
- }
- if (mdss_mdp_pp_overlay_init(mfd))
- pr_warn("Failed to initialize pp overlay data.\n");
- return rc;
- init_fail:
- kfree(mdp5_data);
- return rc;
- }
- static int mdss_mdp_overlay_fb_parse_dt(struct msm_fb_data_type *mfd)
- {
- int rc = 0;
- struct platform_device *pdev = mfd->pdev;
- struct mdss_overlay_private *mdp5_mdata = mfd_to_mdp5_data(mfd);
- mdp5_mdata->mixer_swap = of_property_read_bool(pdev->dev.of_node,
- "qcom,mdss-mixer-swap");
- if (mdp5_mdata->mixer_swap) {
- pr_info("mixer swap is enabled for fb device=%s\n",
- pdev->name);
- }
- return rc;
- }
- #if defined (CONFIG_FB_MSM_MDSS_DBG_SEQ_TICK)
- void mdss_dbg_tick_save(int op_name)
- {
- ktime_t tick;
- tick = ktime_get();
- switch(op_name)
- {
- case COMMIT :
- mdss_dbg_tick.commit[mdss_dbg_tick.commit_cnt] = ktime_to_ns(tick);
- mdss_dbg_tick.commit_cnt++;
- if(mdss_dbg_tick.commit_cnt > 9)
- mdss_dbg_tick.commit_cnt = 0;
- break;
- case KICKOFF :
- mdss_dbg_tick.kickoff[mdss_dbg_tick.kickoff_cnt] = ktime_to_ns(tick);
- mdss_dbg_tick.kickoff_cnt++;
- if(mdss_dbg_tick.kickoff_cnt > 9)
- mdss_dbg_tick.kickoff_cnt = 0;
- break;
- case PP_DONE :
- mdss_dbg_tick.pingpong_done[mdss_dbg_tick.pingpong_done_cnt] = ktime_to_ns(tick);
- mdss_dbg_tick.pingpong_done_cnt++;
- if(mdss_dbg_tick.pingpong_done_cnt > 9)
- mdss_dbg_tick.pingpong_done_cnt = 0;
- break;
- }
- }
- #endif
- /*
- * [srcx,srcy,srcw,srch]->[dstx,dsty,dstw,dsth][flags]|src_format|bpp|pipe_ndx|
- * mdp_clk = %ld, bus_ab = %llu, bus_ib = %llu
- */
- void mdss_mdp_underrun_dump_info(struct msm_fb_data_type *mfd)
- {
- struct mdss_mdp_pipe *pipe;
- struct mdss_overlay_private *mdp5_data = mfd_to_mdp5_data(mfd);
- int pcount = mdp5_data->mdata->nrgb_pipes+ mdp5_data->mdata->nvig_pipes+mdp5_data->mdata->ndma_pipes;
- pr_info(" ============ dump_start ===========\n");
- list_for_each_entry(pipe, &mdp5_data->pipes_used, list) {
- if (pipe)
- pr_info(" [%4d, %4d, %4d, %4d] -> [%4d, %4d, %4d, %4d]"
- "|flags = %8d|src_format = %2d|bpp = %2d|ndx = %3d|\n",
- pipe->src.x, pipe->src.y, pipe->src.w, pipe->src.h,
- pipe->dst.x, pipe->dst.y, pipe->dst.w, pipe->dst.h,
- pipe->flags, pipe->src_fmt->format, pipe->src_fmt->bpp,
- pipe->ndx);
- pr_info("pipe addr : %pK\n", pipe);
- pcount--;
- if(!pcount) break;
- }
- mdss_mdp_underrun_clk_info();
- pr_info(" ============ dump_end =========== \n");
- }
|