dsi_display.c 210 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/list.h>
  6. #include <linux/of.h>
  7. #include <linux/of_gpio.h>
  8. #include <linux/err.h>
  9. #include "msm_drv.h"
  10. #include "sde_connector.h"
  11. #include "msm_mmu.h"
  12. #include "dsi_display.h"
  13. #include "dsi_panel.h"
  14. #include "dsi_ctrl.h"
  15. #include "dsi_ctrl_hw.h"
  16. #include "dsi_drm.h"
  17. #include "dsi_clk.h"
  18. #include "dsi_pwr.h"
  19. #include "sde_dbg.h"
  20. #include "dsi_parser.h"
  21. #define to_dsi_display(x) container_of(x, struct dsi_display, host)
  22. #define INT_BASE_10 10
  23. #define MISR_BUFF_SIZE 256
  24. #define ESD_MODE_STRING_MAX_LEN 256
  25. #define ESD_TRIGGER_STRING_MAX_LEN 10
  26. #define MAX_NAME_SIZE 64
  27. #define MAX_TE_RECHECKS 5
  28. #define DSI_CLOCK_BITRATE_RADIX 10
  29. #define MAX_TE_SOURCE_ID 2
  30. #define SEC_PANEL_NAME_MAX_LEN 256
  31. u8 dbgfs_tx_cmd_buf[SZ_4K];
  32. static char dsi_display_primary[MAX_CMDLINE_PARAM_LEN];
  33. static char dsi_display_secondary[MAX_CMDLINE_PARAM_LEN];
  34. static struct dsi_display_boot_param boot_displays[MAX_DSI_ACTIVE_DISPLAY] = {
  35. {.boot_param = dsi_display_primary},
  36. {.boot_param = dsi_display_secondary},
  37. };
  38. static const struct of_device_id dsi_display_dt_match[] = {
  39. {.compatible = "qcom,dsi-display"},
  40. {}
  41. };
  42. bool is_skip_op_required(struct dsi_display *display)
  43. {
  44. if (!display)
  45. return false;
  46. return (display->is_cont_splash_enabled || display->trusted_vm_env);
  47. }
  48. static void dsi_display_mask_ctrl_error_interrupts(struct dsi_display *display,
  49. u32 mask, bool enable)
  50. {
  51. int i;
  52. struct dsi_display_ctrl *ctrl;
  53. if (!display)
  54. return;
  55. display_for_each_ctrl(i, display) {
  56. ctrl = &display->ctrl[i];
  57. if (!ctrl)
  58. continue;
  59. dsi_ctrl_mask_error_status_interrupts(ctrl->ctrl, mask, enable);
  60. }
  61. }
  62. static int dsi_display_config_clk_gating(struct dsi_display *display,
  63. bool enable)
  64. {
  65. int rc = 0, i = 0;
  66. struct dsi_display_ctrl *mctrl, *ctrl;
  67. enum dsi_clk_gate_type clk_selection;
  68. enum dsi_clk_gate_type const default_clk_select = PIXEL_CLK | DSI_PHY;
  69. if (!display) {
  70. DSI_ERR("Invalid params\n");
  71. return -EINVAL;
  72. }
  73. if (display->panel->host_config.force_hs_clk_lane) {
  74. DSI_DEBUG("no dsi clock gating for continuous clock mode\n");
  75. return 0;
  76. }
  77. mctrl = &display->ctrl[display->clk_master_idx];
  78. if (!mctrl) {
  79. DSI_ERR("Invalid controller\n");
  80. return -EINVAL;
  81. }
  82. clk_selection = display->clk_gating_config;
  83. if (!enable) {
  84. /* for disable path, make sure to disable all clk gating */
  85. clk_selection = DSI_CLK_ALL;
  86. } else if (!clk_selection || clk_selection > DSI_CLK_NONE) {
  87. /* Default selection, no overrides */
  88. clk_selection = default_clk_select;
  89. } else if (clk_selection == DSI_CLK_NONE) {
  90. clk_selection = 0;
  91. }
  92. DSI_DEBUG("%s clock gating Byte:%s Pixel:%s PHY:%s\n",
  93. enable ? "Enabling" : "Disabling",
  94. clk_selection & BYTE_CLK ? "yes" : "no",
  95. clk_selection & PIXEL_CLK ? "yes" : "no",
  96. clk_selection & DSI_PHY ? "yes" : "no");
  97. rc = dsi_ctrl_config_clk_gating(mctrl->ctrl, enable, clk_selection);
  98. if (rc) {
  99. DSI_ERR("[%s] failed to %s clk gating for clocks %d, rc=%d\n",
  100. display->name, enable ? "enable" : "disable",
  101. clk_selection, rc);
  102. return rc;
  103. }
  104. display_for_each_ctrl(i, display) {
  105. ctrl = &display->ctrl[i];
  106. if (!ctrl->ctrl || (ctrl == mctrl))
  107. continue;
  108. /**
  109. * In Split DSI usecase we should not enable clock gating on
  110. * DSI PHY1 to ensure no display atrifacts are seen.
  111. */
  112. clk_selection &= ~DSI_PHY;
  113. rc = dsi_ctrl_config_clk_gating(ctrl->ctrl, enable,
  114. clk_selection);
  115. if (rc) {
  116. DSI_ERR("[%s] failed to %s clk gating for clocks %d, rc=%d\n",
  117. display->name, enable ? "enable" : "disable",
  118. clk_selection, rc);
  119. return rc;
  120. }
  121. }
  122. return 0;
  123. }
  124. static void dsi_display_set_ctrl_esd_check_flag(struct dsi_display *display,
  125. bool enable)
  126. {
  127. int i;
  128. struct dsi_display_ctrl *ctrl;
  129. if (!display)
  130. return;
  131. display_for_each_ctrl(i, display) {
  132. ctrl = &display->ctrl[i];
  133. if (!ctrl)
  134. continue;
  135. ctrl->ctrl->esd_check_underway = enable;
  136. }
  137. }
  138. static void dsi_display_ctrl_irq_update(struct dsi_display *display, bool en)
  139. {
  140. int i;
  141. struct dsi_display_ctrl *ctrl;
  142. if (!display)
  143. return;
  144. display_for_each_ctrl(i, display) {
  145. ctrl = &display->ctrl[i];
  146. if (!ctrl)
  147. continue;
  148. dsi_ctrl_irq_update(ctrl->ctrl, en);
  149. }
  150. }
  151. void dsi_rect_intersect(const struct dsi_rect *r1,
  152. const struct dsi_rect *r2,
  153. struct dsi_rect *result)
  154. {
  155. int l, t, r, b;
  156. if (!r1 || !r2 || !result)
  157. return;
  158. l = max(r1->x, r2->x);
  159. t = max(r1->y, r2->y);
  160. r = min((r1->x + r1->w), (r2->x + r2->w));
  161. b = min((r1->y + r1->h), (r2->y + r2->h));
  162. if (r <= l || b <= t) {
  163. memset(result, 0, sizeof(*result));
  164. } else {
  165. result->x = l;
  166. result->y = t;
  167. result->w = r - l;
  168. result->h = b - t;
  169. }
  170. }
  171. int dsi_display_set_backlight(struct drm_connector *connector,
  172. void *display, u32 bl_lvl)
  173. {
  174. struct dsi_display *dsi_display = display;
  175. struct dsi_panel *panel;
  176. u32 bl_scale, bl_scale_sv;
  177. u64 bl_temp;
  178. int rc = 0;
  179. if (dsi_display == NULL || dsi_display->panel == NULL)
  180. return -EINVAL;
  181. panel = dsi_display->panel;
  182. mutex_lock(&panel->panel_lock);
  183. if (!dsi_panel_initialized(panel)) {
  184. rc = -EINVAL;
  185. goto error;
  186. }
  187. panel->bl_config.bl_level = bl_lvl;
  188. /* scale backlight */
  189. bl_scale = panel->bl_config.bl_scale;
  190. bl_temp = bl_lvl * bl_scale / MAX_BL_SCALE_LEVEL;
  191. bl_scale_sv = panel->bl_config.bl_scale_sv;
  192. bl_temp = (u32)bl_temp * bl_scale_sv / MAX_SV_BL_SCALE_LEVEL;
  193. if (bl_temp > panel->bl_config.bl_max_level)
  194. bl_temp = panel->bl_config.bl_max_level;
  195. DSI_DEBUG("bl_scale = %u, bl_scale_sv = %u, bl_lvl = %u\n",
  196. bl_scale, bl_scale_sv, (u32)bl_temp);
  197. rc = dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
  198. DSI_CORE_CLK, DSI_CLK_ON);
  199. if (rc) {
  200. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  201. dsi_display->name, rc);
  202. goto error;
  203. }
  204. rc = dsi_panel_set_backlight(panel, (u32)bl_temp);
  205. if (rc)
  206. DSI_ERR("unable to set backlight\n");
  207. rc = dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
  208. DSI_CORE_CLK, DSI_CLK_OFF);
  209. if (rc) {
  210. DSI_ERR("[%s] failed to disable DSI core clocks, rc=%d\n",
  211. dsi_display->name, rc);
  212. goto error;
  213. }
  214. error:
  215. mutex_unlock(&panel->panel_lock);
  216. return rc;
  217. }
  218. static int dsi_display_cmd_engine_enable(struct dsi_display *display)
  219. {
  220. int rc = 0;
  221. int i;
  222. struct dsi_display_ctrl *m_ctrl, *ctrl;
  223. bool skip_op = is_skip_op_required(display);
  224. m_ctrl = &display->ctrl[display->cmd_master_idx];
  225. mutex_lock(&m_ctrl->ctrl->ctrl_lock);
  226. if (display->cmd_engine_refcount > 0) {
  227. display->cmd_engine_refcount++;
  228. goto done;
  229. }
  230. rc = dsi_ctrl_set_cmd_engine_state(m_ctrl->ctrl,
  231. DSI_CTRL_ENGINE_ON, skip_op);
  232. if (rc) {
  233. DSI_ERR("[%s] enable mcmd engine failed, skip_op:%d rc:%d\n",
  234. display->name, skip_op, rc);
  235. goto done;
  236. }
  237. display_for_each_ctrl(i, display) {
  238. ctrl = &display->ctrl[i];
  239. if (!ctrl->ctrl || (ctrl == m_ctrl))
  240. continue;
  241. rc = dsi_ctrl_set_cmd_engine_state(ctrl->ctrl,
  242. DSI_CTRL_ENGINE_ON, skip_op);
  243. if (rc) {
  244. DSI_ERR(
  245. "[%s] enable cmd engine failed, skip_op:%d rc:%d\n",
  246. display->name, skip_op, rc);
  247. goto error_disable_master;
  248. }
  249. }
  250. display->cmd_engine_refcount++;
  251. goto done;
  252. error_disable_master:
  253. (void)dsi_ctrl_set_cmd_engine_state(m_ctrl->ctrl,
  254. DSI_CTRL_ENGINE_OFF, skip_op);
  255. done:
  256. mutex_unlock(&m_ctrl->ctrl->ctrl_lock);
  257. return rc;
  258. }
  259. static int dsi_display_cmd_engine_disable(struct dsi_display *display)
  260. {
  261. int rc = 0;
  262. int i;
  263. struct dsi_display_ctrl *m_ctrl, *ctrl;
  264. bool skip_op = is_skip_op_required(display);
  265. m_ctrl = &display->ctrl[display->cmd_master_idx];
  266. mutex_lock(&m_ctrl->ctrl->ctrl_lock);
  267. if (display->cmd_engine_refcount == 0) {
  268. DSI_ERR("[%s] Invalid refcount\n", display->name);
  269. goto done;
  270. } else if (display->cmd_engine_refcount > 1) {
  271. display->cmd_engine_refcount--;
  272. goto done;
  273. }
  274. display_for_each_ctrl(i, display) {
  275. ctrl = &display->ctrl[i];
  276. if (!ctrl->ctrl || (ctrl == m_ctrl))
  277. continue;
  278. rc = dsi_ctrl_set_cmd_engine_state(ctrl->ctrl,
  279. DSI_CTRL_ENGINE_OFF, skip_op);
  280. if (rc)
  281. DSI_ERR(
  282. "[%s] disable cmd engine failed, skip_op:%d rc:%d\n",
  283. display->name, skip_op, rc);
  284. }
  285. rc = dsi_ctrl_set_cmd_engine_state(m_ctrl->ctrl,
  286. DSI_CTRL_ENGINE_OFF, skip_op);
  287. if (rc) {
  288. DSI_ERR("[%s] disable mcmd engine failed, skip_op:%d rc:%d\n",
  289. display->name, skip_op, rc);
  290. goto error;
  291. }
  292. error:
  293. display->cmd_engine_refcount = 0;
  294. done:
  295. mutex_unlock(&m_ctrl->ctrl->ctrl_lock);
  296. return rc;
  297. }
  298. static void dsi_display_aspace_cb_locked(void *cb_data, bool is_detach)
  299. {
  300. struct dsi_display *display;
  301. struct dsi_display_ctrl *display_ctrl;
  302. int rc, cnt;
  303. if (!cb_data) {
  304. DSI_ERR("aspace cb called with invalid cb_data\n");
  305. return;
  306. }
  307. display = (struct dsi_display *)cb_data;
  308. /*
  309. * acquire panel_lock to make sure no commands are in-progress
  310. * while detaching the non-secure context banks
  311. */
  312. dsi_panel_acquire_panel_lock(display->panel);
  313. if (is_detach) {
  314. /* invalidate the stored iova */
  315. display->cmd_buffer_iova = 0;
  316. /* return the virtual address mapping */
  317. msm_gem_put_vaddr(display->tx_cmd_buf);
  318. msm_gem_vunmap(display->tx_cmd_buf, OBJ_LOCK_NORMAL);
  319. } else {
  320. rc = msm_gem_get_iova(display->tx_cmd_buf,
  321. display->aspace, &(display->cmd_buffer_iova));
  322. if (rc) {
  323. DSI_ERR("failed to get the iova rc %d\n", rc);
  324. goto end;
  325. }
  326. display->vaddr =
  327. (void *) msm_gem_get_vaddr(display->tx_cmd_buf);
  328. if (IS_ERR_OR_NULL(display->vaddr)) {
  329. DSI_ERR("failed to get va rc %d\n", rc);
  330. goto end;
  331. }
  332. }
  333. display_for_each_ctrl(cnt, display) {
  334. display_ctrl = &display->ctrl[cnt];
  335. display_ctrl->ctrl->cmd_buffer_size = display->cmd_buffer_size;
  336. display_ctrl->ctrl->cmd_buffer_iova = display->cmd_buffer_iova;
  337. display_ctrl->ctrl->vaddr = display->vaddr;
  338. display_ctrl->ctrl->secure_mode = is_detach;
  339. }
  340. end:
  341. /* release panel_lock */
  342. dsi_panel_release_panel_lock(display->panel);
  343. }
  344. static irqreturn_t dsi_display_panel_te_irq_handler(int irq, void *data)
  345. {
  346. struct dsi_display *display = (struct dsi_display *)data;
  347. /*
  348. * This irq handler is used for sole purpose of identifying
  349. * ESD attacks on panel and we can safely assume IRQ_HANDLED
  350. * in case of display not being initialized yet
  351. */
  352. if (!display)
  353. return IRQ_HANDLED;
  354. SDE_EVT32(SDE_EVTLOG_FUNC_CASE1);
  355. complete_all(&display->esd_te_gate);
  356. return IRQ_HANDLED;
  357. }
  358. static void dsi_display_change_te_irq_status(struct dsi_display *display,
  359. bool enable)
  360. {
  361. if (!display) {
  362. DSI_ERR("Invalid params\n");
  363. return;
  364. }
  365. /* Handle unbalanced irq enable/disable calls */
  366. if (enable && !display->is_te_irq_enabled) {
  367. enable_irq(gpio_to_irq(display->disp_te_gpio));
  368. display->is_te_irq_enabled = true;
  369. } else if (!enable && display->is_te_irq_enabled) {
  370. disable_irq(gpio_to_irq(display->disp_te_gpio));
  371. display->is_te_irq_enabled = false;
  372. }
  373. }
  374. static void dsi_display_register_te_irq(struct dsi_display *display)
  375. {
  376. int rc = 0;
  377. struct platform_device *pdev;
  378. struct device *dev;
  379. unsigned int te_irq;
  380. pdev = display->pdev;
  381. if (!pdev) {
  382. DSI_ERR("invalid platform device\n");
  383. return;
  384. }
  385. dev = &pdev->dev;
  386. if (!dev) {
  387. DSI_ERR("invalid device\n");
  388. return;
  389. }
  390. if (display->trusted_vm_env) {
  391. DSI_INFO("GPIO's are not enabled in trusted VM\n");
  392. return;
  393. }
  394. if (!gpio_is_valid(display->disp_te_gpio)) {
  395. rc = -EINVAL;
  396. goto error;
  397. }
  398. init_completion(&display->esd_te_gate);
  399. te_irq = gpio_to_irq(display->disp_te_gpio);
  400. /* Avoid deferred spurious irqs with disable_irq() */
  401. irq_set_status_flags(te_irq, IRQ_DISABLE_UNLAZY);
  402. rc = devm_request_irq(dev, te_irq, dsi_display_panel_te_irq_handler,
  403. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  404. "TE_GPIO", display);
  405. if (rc) {
  406. DSI_ERR("TE request_irq failed for ESD rc:%d\n", rc);
  407. irq_clear_status_flags(te_irq, IRQ_DISABLE_UNLAZY);
  408. goto error;
  409. }
  410. disable_irq(te_irq);
  411. display->is_te_irq_enabled = false;
  412. return;
  413. error:
  414. /* disable the TE based ESD check */
  415. DSI_WARN("Unable to register for TE IRQ\n");
  416. if (display->panel->esd_config.status_mode == ESD_MODE_PANEL_TE)
  417. display->panel->esd_config.esd_enabled = false;
  418. }
  419. /* Allocate memory for cmd dma tx buffer */
  420. static int dsi_host_alloc_cmd_tx_buffer(struct dsi_display *display)
  421. {
  422. int rc = 0, cnt = 0;
  423. struct dsi_display_ctrl *display_ctrl;
  424. display->tx_cmd_buf = msm_gem_new(display->drm_dev,
  425. SZ_4K,
  426. MSM_BO_UNCACHED);
  427. if ((display->tx_cmd_buf) == NULL) {
  428. DSI_ERR("Failed to allocate cmd tx buf memory\n");
  429. rc = -ENOMEM;
  430. goto error;
  431. }
  432. display->cmd_buffer_size = SZ_4K;
  433. display->aspace = msm_gem_smmu_address_space_get(
  434. display->drm_dev, MSM_SMMU_DOMAIN_UNSECURE);
  435. if (PTR_ERR(display->aspace) == -ENODEV) {
  436. display->aspace = NULL;
  437. DSI_DEBUG("IOMMU not present, relying on VRAM\n");
  438. } else if (IS_ERR_OR_NULL(display->aspace)) {
  439. rc = PTR_ERR(display->aspace);
  440. display->aspace = NULL;
  441. DSI_ERR("failed to get aspace %d\n", rc);
  442. goto free_gem;
  443. } else if (display->aspace) {
  444. /* register to aspace */
  445. rc = msm_gem_address_space_register_cb(display->aspace,
  446. dsi_display_aspace_cb_locked, (void *)display);
  447. if (rc) {
  448. DSI_ERR("failed to register callback %d\n", rc);
  449. goto free_gem;
  450. }
  451. }
  452. rc = msm_gem_get_iova(display->tx_cmd_buf, display->aspace,
  453. &(display->cmd_buffer_iova));
  454. if (rc) {
  455. DSI_ERR("failed to get the iova rc %d\n", rc);
  456. goto free_aspace_cb;
  457. }
  458. display->vaddr =
  459. (void *) msm_gem_get_vaddr(display->tx_cmd_buf);
  460. if (IS_ERR_OR_NULL(display->vaddr)) {
  461. DSI_ERR("failed to get va rc %d\n", rc);
  462. rc = -EINVAL;
  463. goto put_iova;
  464. }
  465. display_for_each_ctrl(cnt, display) {
  466. display_ctrl = &display->ctrl[cnt];
  467. display_ctrl->ctrl->cmd_buffer_size = SZ_4K;
  468. display_ctrl->ctrl->cmd_buffer_iova =
  469. display->cmd_buffer_iova;
  470. display_ctrl->ctrl->vaddr = display->vaddr;
  471. display_ctrl->ctrl->tx_cmd_buf = display->tx_cmd_buf;
  472. }
  473. return rc;
  474. put_iova:
  475. msm_gem_put_iova(display->tx_cmd_buf, display->aspace);
  476. free_aspace_cb:
  477. msm_gem_address_space_unregister_cb(display->aspace,
  478. dsi_display_aspace_cb_locked, display);
  479. free_gem:
  480. mutex_lock(&display->drm_dev->struct_mutex);
  481. msm_gem_free_object(display->tx_cmd_buf);
  482. mutex_unlock(&display->drm_dev->struct_mutex);
  483. error:
  484. return rc;
  485. }
  486. static bool dsi_display_validate_reg_read(struct dsi_panel *panel)
  487. {
  488. int i, j = 0;
  489. int len = 0, *lenp;
  490. int group = 0, count = 0;
  491. struct drm_panel_esd_config *config;
  492. if (!panel)
  493. return false;
  494. config = &(panel->esd_config);
  495. lenp = config->status_valid_params ?: config->status_cmds_rlen;
  496. count = config->status_cmd.count;
  497. for (i = 0; i < count; i++)
  498. len += lenp[i];
  499. for (i = 0; i < len; i++)
  500. j += len;
  501. for (j = 0; j < config->groups; ++j) {
  502. for (i = 0; i < len; ++i) {
  503. if (config->return_buf[i] !=
  504. config->status_value[group + i]) {
  505. DRM_ERROR("mismatch: 0x%x\n",
  506. config->return_buf[i]);
  507. break;
  508. }
  509. }
  510. if (i == len)
  511. return true;
  512. group += len;
  513. }
  514. return false;
  515. }
  516. static void dsi_display_parse_demura_data(struct dsi_display *display)
  517. {
  518. int rc = 0;
  519. display->panel_id = 0;
  520. if (display->fw) {
  521. DSI_INFO("FW definition unsupported for Demura panel data\n");
  522. return;
  523. }
  524. rc = of_property_read_u64(display->pdev->dev.of_node,
  525. "qcom,demura-panel-id", &display->panel_id);
  526. if (rc)
  527. DSI_INFO("No panel ID is present for this display\n");
  528. else
  529. DSI_INFO("panel id found: %lx\n", display->panel_id);
  530. }
  531. static void dsi_display_parse_te_data(struct dsi_display *display)
  532. {
  533. struct platform_device *pdev;
  534. struct device *dev;
  535. int rc = 0;
  536. u32 val = 0;
  537. pdev = display->pdev;
  538. if (!pdev) {
  539. DSI_ERR("Invalid platform device\n");
  540. return;
  541. }
  542. dev = &pdev->dev;
  543. if (!dev) {
  544. DSI_ERR("Invalid platform device\n");
  545. return;
  546. }
  547. display->disp_te_gpio = of_get_named_gpio(dev->of_node,
  548. "qcom,platform-te-gpio", 0);
  549. if (display->fw)
  550. rc = dsi_parser_read_u32(display->parser_node,
  551. "qcom,panel-te-source", &val);
  552. else
  553. rc = of_property_read_u32(dev->of_node,
  554. "qcom,panel-te-source", &val);
  555. if (rc || (val > MAX_TE_SOURCE_ID)) {
  556. DSI_ERR("invalid vsync source selection\n");
  557. val = 0;
  558. }
  559. display->te_source = val;
  560. }
  561. static void dsi_display_set_cmd_tx_ctrl_flags(struct dsi_display *display,
  562. struct dsi_cmd_desc *cmd)
  563. {
  564. struct dsi_display_ctrl *ctrl, *m_ctrl;
  565. struct mipi_dsi_msg *msg = &cmd->msg;
  566. u32 flags = 0;
  567. int i = 0;
  568. m_ctrl = &display->ctrl[display->clk_master_idx];
  569. display_for_each_ctrl(i, display) {
  570. ctrl = &display->ctrl[i];
  571. if (!ctrl->ctrl)
  572. continue;
  573. /*
  574. * Set cmd transfer mode flags.
  575. * 1) Default selection is CMD fetch from memory.
  576. * 2) In secure session override and use FIFO rather than
  577. * memory.
  578. * 3) If cmd_len is greater than FIFO size non embedded mode of
  579. * tx is used.
  580. */
  581. flags = DSI_CTRL_CMD_FETCH_MEMORY;
  582. if (ctrl->ctrl->secure_mode) {
  583. flags &= ~DSI_CTRL_CMD_FETCH_MEMORY;
  584. flags |= DSI_CTRL_CMD_FIFO_STORE;
  585. } else if (msg->tx_len > DSI_EMBEDDED_MODE_DMA_MAX_SIZE_BYTES) {
  586. flags |= DSI_CTRL_CMD_NON_EMBEDDED_MODE;
  587. }
  588. /* Set flags needed for broadcast. Read commands are always unicast */
  589. if (!(msg->flags & MIPI_DSI_MSG_UNICAST_COMMAND) && (display->ctrl_count > 1))
  590. flags |= DSI_CTRL_CMD_BROADCAST | DSI_CTRL_CMD_DEFER_TRIGGER;
  591. /*
  592. * Set flags for command scheduling.
  593. * 1) In video mode command DMA scheduling is default.
  594. * 2) In command mode command DMA scheduling depends on message
  595. * flag and TE needs to be running.
  596. */
  597. if (display->panel->panel_mode == DSI_OP_VIDEO_MODE) {
  598. flags |= DSI_CTRL_CMD_CUSTOM_DMA_SCHED;
  599. } else {
  600. if (msg->flags & MIPI_DSI_MSG_CMD_DMA_SCHED)
  601. flags |= DSI_CTRL_CMD_CUSTOM_DMA_SCHED;
  602. if (!display->enabled)
  603. flags &= ~DSI_CTRL_CMD_CUSTOM_DMA_SCHED;
  604. }
  605. /* Set flags for last command */
  606. if (!(msg->flags & MIPI_DSI_MSG_BATCH_COMMAND))
  607. flags |= DSI_CTRL_CMD_LAST_COMMAND;
  608. /*
  609. * Set flags for asynchronous wait.
  610. * Asynchronous wait is supported in the following scenarios
  611. * 1) queue_cmd_waits is set by connector and
  612. * - commands are not sent using DSI FIFO memory
  613. * - commands are not sent in non-embedded mode
  614. * - not a video mode panel
  615. * - no explicit msg post_wait_ms is specified
  616. * - not a read command
  617. * 2) if async override msg flag is present
  618. */
  619. if (display->queue_cmd_waits)
  620. if (!(flags & DSI_CTRL_CMD_FIFO_STORE) &&
  621. !(flags & DSI_CTRL_CMD_NON_EMBEDDED_MODE) &&
  622. !(display->panel->panel_mode == DSI_OP_VIDEO_MODE) &&
  623. (cmd->post_wait_ms == 0) &&
  624. !(cmd->ctrl_flags & DSI_CTRL_CMD_READ))
  625. flags |= DSI_CTRL_CMD_ASYNC_WAIT;
  626. if (msg->flags & MIPI_DSI_MSG_ASYNC_OVERRIDE)
  627. flags |= DSI_CTRL_CMD_ASYNC_WAIT;
  628. }
  629. cmd->ctrl_flags |= flags;
  630. }
  631. static int dsi_display_read_status(struct dsi_display_ctrl *ctrl,
  632. struct dsi_display *display)
  633. {
  634. int i, rc = 0, count = 0, start = 0, *lenp;
  635. struct drm_panel_esd_config *config;
  636. struct dsi_cmd_desc *cmds;
  637. struct dsi_panel *panel;
  638. u32 flags = 0;
  639. if (!display->panel || !ctrl || !ctrl->ctrl)
  640. return -EINVAL;
  641. panel = display->panel;
  642. /*
  643. * When DSI controller is not in initialized state, we do not want to
  644. * report a false ESD failure and hence we defer until next read
  645. * happen.
  646. */
  647. if (!dsi_ctrl_validate_host_state(ctrl->ctrl))
  648. return 1;
  649. config = &(panel->esd_config);
  650. lenp = config->status_valid_params ?: config->status_cmds_rlen;
  651. count = config->status_cmd.count;
  652. cmds = config->status_cmd.cmds;
  653. flags = DSI_CTRL_CMD_READ;
  654. for (i = 0; i < count; ++i) {
  655. memset(config->status_buf, 0x0, SZ_4K);
  656. if (config->status_cmd.state == DSI_CMD_SET_STATE_LP)
  657. cmds[i].msg.flags |= MIPI_DSI_MSG_USE_LPM;
  658. cmds[i].msg.flags |= MIPI_DSI_MSG_UNICAST_COMMAND;
  659. cmds[i].msg.rx_buf = config->status_buf;
  660. cmds[i].msg.rx_len = config->status_cmds_rlen[i];
  661. cmds[i].ctrl_flags = flags;
  662. dsi_display_set_cmd_tx_ctrl_flags(display,&cmds[i]);
  663. rc = dsi_ctrl_cmd_transfer(ctrl->ctrl, &cmds[i]);
  664. if (rc <= 0) {
  665. DSI_ERR("rx cmd transfer failed rc=%d\n", rc);
  666. return rc;
  667. }
  668. memcpy(config->return_buf + start,
  669. config->status_buf, lenp[i]);
  670. start += lenp[i];
  671. }
  672. return rc;
  673. }
  674. static int dsi_display_validate_status(struct dsi_display_ctrl *ctrl,
  675. struct dsi_display *display)
  676. {
  677. int rc = 0;
  678. rc = dsi_display_read_status(ctrl, display);
  679. if (rc <= 0) {
  680. goto exit;
  681. } else {
  682. /*
  683. * panel status read successfully.
  684. * check for validity of the data read back.
  685. */
  686. rc = dsi_display_validate_reg_read(display->panel);
  687. if (!rc) {
  688. rc = -EINVAL;
  689. goto exit;
  690. }
  691. }
  692. exit:
  693. return rc;
  694. }
  695. static int dsi_display_status_reg_read(struct dsi_display *display)
  696. {
  697. int rc = 0, i;
  698. struct dsi_display_ctrl *m_ctrl, *ctrl;
  699. DSI_DEBUG(" ++\n");
  700. m_ctrl = &display->ctrl[display->cmd_master_idx];
  701. if (display->tx_cmd_buf == NULL) {
  702. rc = dsi_host_alloc_cmd_tx_buffer(display);
  703. if (rc) {
  704. DSI_ERR("failed to allocate cmd tx buffer memory\n");
  705. goto done;
  706. }
  707. }
  708. rc = dsi_display_cmd_engine_enable(display);
  709. if (rc) {
  710. DSI_ERR("cmd engine enable failed\n");
  711. return -EPERM;
  712. }
  713. rc = dsi_display_validate_status(m_ctrl, display);
  714. if (rc <= 0) {
  715. DSI_ERR("[%s] read status failed on master,rc=%d\n",
  716. display->name, rc);
  717. goto exit;
  718. }
  719. if (!display->panel->sync_broadcast_en)
  720. goto exit;
  721. display_for_each_ctrl(i, display) {
  722. ctrl = &display->ctrl[i];
  723. if (ctrl == m_ctrl)
  724. continue;
  725. rc = dsi_display_validate_status(ctrl, display);
  726. if (rc <= 0) {
  727. DSI_ERR("[%s] read status failed on slave,rc=%d\n",
  728. display->name, rc);
  729. goto exit;
  730. }
  731. }
  732. exit:
  733. dsi_display_cmd_engine_disable(display);
  734. done:
  735. return rc;
  736. }
  737. static int dsi_display_status_bta_request(struct dsi_display *display)
  738. {
  739. int rc = 0;
  740. DSI_DEBUG(" ++\n");
  741. /* TODO: trigger SW BTA and wait for acknowledgment */
  742. return rc;
  743. }
  744. static int dsi_display_status_check_te(struct dsi_display *display,
  745. int rechecks)
  746. {
  747. int rc = 1, i = 0;
  748. int const esd_te_timeout = msecs_to_jiffies(3*20);
  749. if (!rechecks)
  750. return rc;
  751. dsi_display_change_te_irq_status(display, true);
  752. for (i = 0; i < rechecks; i++) {
  753. reinit_completion(&display->esd_te_gate);
  754. if (!wait_for_completion_timeout(&display->esd_te_gate,
  755. esd_te_timeout)) {
  756. DSI_ERR("TE check failed\n");
  757. dsi_display_change_te_irq_status(display, false);
  758. return -EINVAL;
  759. }
  760. }
  761. dsi_display_change_te_irq_status(display, false);
  762. return rc;
  763. }
  764. int dsi_display_check_status(struct drm_connector *connector, void *display,
  765. bool te_check_override)
  766. {
  767. struct dsi_display *dsi_display = display;
  768. struct dsi_panel *panel;
  769. u32 status_mode;
  770. int rc = 0x1, ret;
  771. u32 mask;
  772. int te_rechecks = 1;
  773. if (!dsi_display || !dsi_display->panel)
  774. return -EINVAL;
  775. panel = dsi_display->panel;
  776. dsi_panel_acquire_panel_lock(panel);
  777. if (!panel->panel_initialized) {
  778. DSI_DEBUG("Panel not initialized\n");
  779. goto release_panel_lock;
  780. }
  781. /* Prevent another ESD check,when ESD recovery is underway */
  782. if (atomic_read(&panel->esd_recovery_pending))
  783. goto release_panel_lock;
  784. status_mode = panel->esd_config.status_mode;
  785. if ((status_mode == ESD_MODE_SW_SIM_SUCCESS) ||
  786. (dsi_display->sw_te_using_wd))
  787. goto release_panel_lock;
  788. if (status_mode == ESD_MODE_SW_SIM_FAILURE) {
  789. rc = -EINVAL;
  790. goto release_panel_lock;
  791. }
  792. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY, status_mode, te_check_override);
  793. if (te_check_override)
  794. te_rechecks = MAX_TE_RECHECKS;
  795. if ((dsi_display->trusted_vm_env) ||
  796. (panel->panel_mode == DSI_OP_VIDEO_MODE))
  797. te_rechecks = 0;
  798. ret = dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
  799. DSI_ALL_CLKS, DSI_CLK_ON);
  800. if (ret)
  801. goto release_panel_lock;
  802. /* Mask error interrupts before attempting ESD read */
  803. mask = BIT(DSI_FIFO_OVERFLOW) | BIT(DSI_FIFO_UNDERFLOW);
  804. dsi_display_set_ctrl_esd_check_flag(dsi_display, true);
  805. dsi_display_mask_ctrl_error_interrupts(dsi_display, mask, true);
  806. if (status_mode == ESD_MODE_REG_READ) {
  807. rc = dsi_display_status_reg_read(dsi_display);
  808. } else if (status_mode == ESD_MODE_SW_BTA) {
  809. rc = dsi_display_status_bta_request(dsi_display);
  810. } else if (status_mode == ESD_MODE_PANEL_TE) {
  811. rc = dsi_display_status_check_te(dsi_display, te_rechecks);
  812. te_check_override = false;
  813. } else {
  814. DSI_WARN("Unsupported check status mode: %d\n", status_mode);
  815. panel->esd_config.esd_enabled = false;
  816. }
  817. if (rc <= 0 && te_check_override)
  818. rc = dsi_display_status_check_te(dsi_display, te_rechecks);
  819. /* Unmask error interrupts if check passed*/
  820. if (rc > 0) {
  821. dsi_display_set_ctrl_esd_check_flag(dsi_display, false);
  822. dsi_display_mask_ctrl_error_interrupts(dsi_display, mask,
  823. false);
  824. if (te_check_override && panel->esd_config.esd_enabled == false)
  825. rc = dsi_display_status_check_te(dsi_display,
  826. te_rechecks);
  827. }
  828. dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
  829. DSI_ALL_CLKS, DSI_CLK_OFF);
  830. /* Handle Panel failures during display disable sequence */
  831. if (rc <=0)
  832. atomic_set(&panel->esd_recovery_pending, 1);
  833. release_panel_lock:
  834. dsi_panel_release_panel_lock(panel);
  835. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT, rc);
  836. return rc;
  837. }
  838. static int dsi_display_ctrl_get_host_init_state(struct dsi_display *dsi_display,
  839. bool *state)
  840. {
  841. struct dsi_display_ctrl *ctrl;
  842. int i, rc = -EINVAL;
  843. display_for_each_ctrl(i, dsi_display) {
  844. ctrl = &dsi_display->ctrl[i];
  845. rc = dsi_ctrl_get_host_engine_init_state(ctrl->ctrl, state);
  846. if (rc)
  847. break;
  848. }
  849. return rc;
  850. }
  851. static int dsi_display_cmd_rx(struct dsi_display *display,
  852. struct dsi_cmd_desc *cmd)
  853. {
  854. struct dsi_display_ctrl *m_ctrl = NULL;
  855. u32 mask = 0, flags = 0;
  856. int rc = 0;
  857. if (!display || !display->panel)
  858. return -EINVAL;
  859. m_ctrl = &display->ctrl[display->cmd_master_idx];
  860. if (!m_ctrl || !m_ctrl->ctrl)
  861. return -EINVAL;
  862. /* acquire panel_lock to make sure no commands are in progress */
  863. dsi_panel_acquire_panel_lock(display->panel);
  864. if (!display->panel->panel_initialized) {
  865. DSI_DEBUG("panel not initialized\n");
  866. goto release_panel_lock;
  867. }
  868. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  869. DSI_ALL_CLKS, DSI_CLK_ON);
  870. if (rc)
  871. goto release_panel_lock;
  872. mask = BIT(DSI_FIFO_OVERFLOW) | BIT(DSI_FIFO_UNDERFLOW);
  873. dsi_display_mask_ctrl_error_interrupts(display, mask, true);
  874. rc = dsi_display_cmd_engine_enable(display);
  875. if (rc) {
  876. DSI_ERR("cmd engine enable failed rc = %d\n", rc);
  877. goto error;
  878. }
  879. flags = DSI_CTRL_CMD_READ;
  880. cmd->ctrl_flags = flags;
  881. dsi_display_set_cmd_tx_ctrl_flags(display, cmd);
  882. rc = dsi_ctrl_cmd_transfer(m_ctrl->ctrl, cmd);
  883. if (rc <= 0)
  884. DSI_ERR("rx cmd transfer failed rc = %d\n", rc);
  885. dsi_display_cmd_engine_disable(display);
  886. error:
  887. dsi_display_mask_ctrl_error_interrupts(display, mask, false);
  888. dsi_display_clk_ctrl(display->dsi_clk_handle,
  889. DSI_ALL_CLKS, DSI_CLK_OFF);
  890. release_panel_lock:
  891. dsi_panel_release_panel_lock(display->panel);
  892. return rc;
  893. }
  894. int dsi_display_cmd_transfer(struct drm_connector *connector,
  895. void *display, const char *cmd_buf,
  896. u32 cmd_buf_len)
  897. {
  898. struct dsi_display *dsi_display = display;
  899. int rc = 0, cnt = 0, i = 0;
  900. bool state = false, transfer = false;
  901. struct dsi_panel_cmd_set *set;
  902. if (!dsi_display || !cmd_buf) {
  903. DSI_ERR("[DSI] invalid params\n");
  904. return -EINVAL;
  905. }
  906. DSI_DEBUG("[DSI] Display command transfer\n");
  907. if (!(cmd_buf[3] & MIPI_DSI_MSG_BATCH_COMMAND))
  908. transfer = true;
  909. mutex_lock(&dsi_display->display_lock);
  910. rc = dsi_display_ctrl_get_host_init_state(dsi_display, &state);
  911. /**
  912. * Handle scenario where a command transfer is initiated through
  913. * sysfs interface when device is in suepnd state.
  914. */
  915. if (!rc && !state) {
  916. pr_warn_ratelimited("Command xfer attempted while device is in suspend state\n"
  917. );
  918. rc = -EPERM;
  919. goto end;
  920. }
  921. if (rc || !state) {
  922. DSI_ERR("[DSI] Invalid host state %d rc %d\n",
  923. state, rc);
  924. rc = -EPERM;
  925. goto end;
  926. }
  927. /*
  928. * Reset the dbgfs buffer if the commands sent exceed the available
  929. * buffer size. For video mode, limiting the buffer size to 2K to
  930. * ensure no performance issues.
  931. */
  932. if (dsi_display->panel->panel_mode == DSI_OP_CMD_MODE) {
  933. if ((dsi_display->tx_cmd_buf_ndx + cmd_buf_len) > SZ_4K) {
  934. memset(dbgfs_tx_cmd_buf, 0, SZ_4K);
  935. dsi_display->tx_cmd_buf_ndx = 0;
  936. }
  937. } else {
  938. if ((dsi_display->tx_cmd_buf_ndx + cmd_buf_len) > SZ_2K) {
  939. memset(dbgfs_tx_cmd_buf, 0, SZ_4K);
  940. dsi_display->tx_cmd_buf_ndx = 0;
  941. }
  942. }
  943. memcpy(&dbgfs_tx_cmd_buf[dsi_display->tx_cmd_buf_ndx], cmd_buf,
  944. cmd_buf_len);
  945. dsi_display->tx_cmd_buf_ndx += cmd_buf_len;
  946. if (transfer) {
  947. struct dsi_cmd_desc *cmds;
  948. set = &dsi_display->cmd_set;
  949. set->count = 0;
  950. dsi_panel_get_cmd_pkt_count(dbgfs_tx_cmd_buf,
  951. dsi_display->tx_cmd_buf_ndx, &cnt);
  952. dsi_panel_alloc_cmd_packets(set, cnt);
  953. dsi_panel_create_cmd_packets(dbgfs_tx_cmd_buf,
  954. dsi_display->tx_cmd_buf_ndx, cnt, set->cmds);
  955. cmds = set->cmds;
  956. dsi_display->tx_cmd_buf_ndx = 0;
  957. for (i = 0; i < cnt; i++) {
  958. rc = dsi_host_transfer_sub(&dsi_display->host, cmds);
  959. if (rc < 0) {
  960. DSI_ERR("failed to send command, rc=%d\n", rc);
  961. break;
  962. }
  963. if (cmds->post_wait_ms)
  964. usleep_range(cmds->post_wait_ms*1000,
  965. ((cmds->post_wait_ms*1000)+10));
  966. cmds++;
  967. }
  968. memset(dbgfs_tx_cmd_buf, 0, SZ_4K);
  969. dsi_panel_destroy_cmd_packets(set);
  970. dsi_panel_dealloc_cmd_packets(set);
  971. }
  972. end:
  973. mutex_unlock(&dsi_display->display_lock);
  974. return rc;
  975. }
  976. static void _dsi_display_continuous_clk_ctrl(struct dsi_display *display,
  977. bool enable)
  978. {
  979. int i;
  980. struct dsi_display_ctrl *ctrl;
  981. if (!display || !display->panel->host_config.force_hs_clk_lane)
  982. return;
  983. display_for_each_ctrl(i, display) {
  984. ctrl = &display->ctrl[i];
  985. /*
  986. * For phy ver 4.0 chipsets, configure DSI controller and
  987. * DSI PHY to force clk lane to HS mode always whereas
  988. * for other phy ver chipsets, configure DSI controller only.
  989. */
  990. if (ctrl->phy->hw.ops.set_continuous_clk) {
  991. dsi_ctrl_hs_req_sel(ctrl->ctrl, true);
  992. dsi_ctrl_set_continuous_clk(ctrl->ctrl, enable);
  993. dsi_phy_set_continuous_clk(ctrl->phy, enable);
  994. } else {
  995. dsi_ctrl_set_continuous_clk(ctrl->ctrl, enable);
  996. }
  997. }
  998. }
  999. int dsi_display_cmd_receive(void *display, const char *cmd_buf,
  1000. u32 cmd_buf_len, u8 *recv_buf, u32 recv_buf_len)
  1001. {
  1002. struct dsi_display *dsi_display = display;
  1003. struct dsi_cmd_desc cmd = {};
  1004. bool state = false;
  1005. int rc = -1;
  1006. if (!dsi_display || !cmd_buf || !recv_buf) {
  1007. DSI_ERR("[DSI] invalid params\n");
  1008. return -EINVAL;
  1009. }
  1010. rc = dsi_panel_create_cmd_packets(cmd_buf, cmd_buf_len, 1, &cmd);
  1011. if (rc) {
  1012. DSI_ERR("[DSI] command packet create failed, rc = %d\n", rc);
  1013. return rc;
  1014. }
  1015. cmd.msg.rx_buf = recv_buf;
  1016. cmd.msg.rx_len = recv_buf_len;
  1017. cmd.msg.flags |= MIPI_DSI_MSG_UNICAST_COMMAND;
  1018. mutex_lock(&dsi_display->display_lock);
  1019. rc = dsi_display_ctrl_get_host_init_state(dsi_display, &state);
  1020. if (rc || !state) {
  1021. DSI_ERR("[DSI] Invalid host state = %d rc = %d\n",
  1022. state, rc);
  1023. rc = -EPERM;
  1024. goto end;
  1025. }
  1026. rc = dsi_display_cmd_rx(dsi_display, &cmd);
  1027. if (rc <= 0)
  1028. DSI_ERR("[DSI] Display command receive failed, rc=%d\n", rc);
  1029. end:
  1030. mutex_unlock(&dsi_display->display_lock);
  1031. return rc;
  1032. }
  1033. int dsi_display_soft_reset(void *display)
  1034. {
  1035. struct dsi_display *dsi_display;
  1036. struct dsi_display_ctrl *ctrl;
  1037. int rc = 0;
  1038. int i;
  1039. if (!display)
  1040. return -EINVAL;
  1041. dsi_display = display;
  1042. display_for_each_ctrl(i, dsi_display) {
  1043. ctrl = &dsi_display->ctrl[i];
  1044. rc = dsi_ctrl_soft_reset(ctrl->ctrl);
  1045. if (rc) {
  1046. DSI_ERR("[%s] failed to soft reset host_%d, rc=%d\n",
  1047. dsi_display->name, i, rc);
  1048. break;
  1049. }
  1050. }
  1051. return rc;
  1052. }
  1053. enum dsi_pixel_format dsi_display_get_dst_format(
  1054. struct drm_connector *connector,
  1055. void *display)
  1056. {
  1057. enum dsi_pixel_format format = DSI_PIXEL_FORMAT_MAX;
  1058. struct dsi_display *dsi_display = (struct dsi_display *)display;
  1059. if (!dsi_display || !dsi_display->panel) {
  1060. DSI_ERR("Invalid params(s) dsi_display %pK, panel %pK\n",
  1061. dsi_display,
  1062. ((dsi_display) ? dsi_display->panel : NULL));
  1063. return format;
  1064. }
  1065. format = dsi_display->panel->host_config.dst_format;
  1066. return format;
  1067. }
  1068. static void _dsi_display_setup_misr(struct dsi_display *display)
  1069. {
  1070. int i;
  1071. display_for_each_ctrl(i, display) {
  1072. dsi_ctrl_setup_misr(display->ctrl[i].ctrl,
  1073. display->misr_enable,
  1074. display->misr_frame_count);
  1075. }
  1076. }
  1077. int dsi_display_set_power(struct drm_connector *connector,
  1078. int power_mode, void *disp)
  1079. {
  1080. struct dsi_display *display = disp;
  1081. int rc = 0;
  1082. if (!display || !display->panel) {
  1083. DSI_ERR("invalid display/panel\n");
  1084. return -EINVAL;
  1085. }
  1086. switch (power_mode) {
  1087. case SDE_MODE_DPMS_LP1:
  1088. rc = dsi_panel_set_lp1(display->panel);
  1089. break;
  1090. case SDE_MODE_DPMS_LP2:
  1091. rc = dsi_panel_set_lp2(display->panel);
  1092. break;
  1093. case SDE_MODE_DPMS_ON:
  1094. if ((display->panel->power_mode == SDE_MODE_DPMS_LP1) ||
  1095. (display->panel->power_mode == SDE_MODE_DPMS_LP2))
  1096. rc = dsi_panel_set_nolp(display->panel);
  1097. break;
  1098. case SDE_MODE_DPMS_OFF:
  1099. default:
  1100. return rc;
  1101. }
  1102. SDE_EVT32(display->panel->power_mode, power_mode, rc);
  1103. DSI_DEBUG("Power mode transition from %d to %d %s",
  1104. display->panel->power_mode, power_mode,
  1105. rc ? "failed" : "successful");
  1106. if (!rc)
  1107. display->panel->power_mode = power_mode;
  1108. return rc;
  1109. }
  1110. #ifdef CONFIG_DEBUG_FS
  1111. static bool dsi_display_is_te_based_esd(struct dsi_display *display)
  1112. {
  1113. u32 status_mode = 0;
  1114. if (!display->panel) {
  1115. DSI_ERR("Invalid panel data\n");
  1116. return false;
  1117. }
  1118. status_mode = display->panel->esd_config.status_mode;
  1119. if (status_mode == ESD_MODE_PANEL_TE &&
  1120. gpio_is_valid(display->disp_te_gpio))
  1121. return true;
  1122. return false;
  1123. }
  1124. static ssize_t debugfs_dump_info_read(struct file *file,
  1125. char __user *user_buf,
  1126. size_t user_len,
  1127. loff_t *ppos)
  1128. {
  1129. struct dsi_display *display = file->private_data;
  1130. char *buf;
  1131. u32 len = 0;
  1132. int i;
  1133. if (!display)
  1134. return -ENODEV;
  1135. if (*ppos)
  1136. return 0;
  1137. buf = kzalloc(SZ_4K, GFP_KERNEL);
  1138. if (!buf)
  1139. return -ENOMEM;
  1140. len += snprintf(buf + len, (SZ_4K - len), "name = %s\n", display->name);
  1141. len += snprintf(buf + len, (SZ_4K - len),
  1142. "\tResolution = %dx%d\n",
  1143. display->config.video_timing.h_active,
  1144. display->config.video_timing.v_active);
  1145. display_for_each_ctrl(i, display) {
  1146. len += snprintf(buf + len, (SZ_4K - len),
  1147. "\tCTRL_%d:\n\t\tctrl = %s\n\t\tphy = %s\n",
  1148. i, display->ctrl[i].ctrl->name,
  1149. display->ctrl[i].phy->name);
  1150. }
  1151. len += snprintf(buf + len, (SZ_4K - len),
  1152. "\tPanel = %s\n", display->panel->name);
  1153. len += snprintf(buf + len, (SZ_4K - len),
  1154. "\tClock master = %s\n",
  1155. display->ctrl[display->clk_master_idx].ctrl->name);
  1156. if (len > user_len)
  1157. len = user_len;
  1158. if (copy_to_user(user_buf, buf, len)) {
  1159. kfree(buf);
  1160. return -EFAULT;
  1161. }
  1162. *ppos += len;
  1163. kfree(buf);
  1164. return len;
  1165. }
  1166. static ssize_t debugfs_misr_setup(struct file *file,
  1167. const char __user *user_buf,
  1168. size_t user_len,
  1169. loff_t *ppos)
  1170. {
  1171. struct dsi_display *display = file->private_data;
  1172. char *buf;
  1173. int rc = 0;
  1174. size_t len;
  1175. u32 enable, frame_count;
  1176. if (!display)
  1177. return -ENODEV;
  1178. if (*ppos)
  1179. return 0;
  1180. buf = kzalloc(MISR_BUFF_SIZE, GFP_KERNEL);
  1181. if (!buf)
  1182. return -ENOMEM;
  1183. /* leave room for termination char */
  1184. len = min_t(size_t, user_len, MISR_BUFF_SIZE - 1);
  1185. if (copy_from_user(buf, user_buf, len)) {
  1186. rc = -EINVAL;
  1187. goto error;
  1188. }
  1189. buf[len] = '\0'; /* terminate the string */
  1190. if (sscanf(buf, "%u %u", &enable, &frame_count) != 2) {
  1191. rc = -EINVAL;
  1192. goto error;
  1193. }
  1194. display->misr_enable = enable;
  1195. display->misr_frame_count = frame_count;
  1196. mutex_lock(&display->display_lock);
  1197. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  1198. DSI_CORE_CLK, DSI_CLK_ON);
  1199. if (rc) {
  1200. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  1201. display->name, rc);
  1202. goto unlock;
  1203. }
  1204. _dsi_display_setup_misr(display);
  1205. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  1206. DSI_CORE_CLK, DSI_CLK_OFF);
  1207. if (rc) {
  1208. DSI_ERR("[%s] failed to disable DSI core clocks, rc=%d\n",
  1209. display->name, rc);
  1210. goto unlock;
  1211. }
  1212. rc = user_len;
  1213. unlock:
  1214. mutex_unlock(&display->display_lock);
  1215. error:
  1216. kfree(buf);
  1217. return rc;
  1218. }
  1219. static ssize_t debugfs_misr_read(struct file *file,
  1220. char __user *user_buf,
  1221. size_t user_len,
  1222. loff_t *ppos)
  1223. {
  1224. struct dsi_display *display = file->private_data;
  1225. char *buf;
  1226. u32 len = 0;
  1227. int rc = 0;
  1228. struct dsi_ctrl *dsi_ctrl;
  1229. int i;
  1230. u32 misr;
  1231. size_t max_len = min_t(size_t, user_len, MISR_BUFF_SIZE);
  1232. if (!display)
  1233. return -ENODEV;
  1234. if (*ppos)
  1235. return 0;
  1236. buf = kzalloc(max_len, GFP_KERNEL);
  1237. if (ZERO_OR_NULL_PTR(buf))
  1238. return -ENOMEM;
  1239. mutex_lock(&display->display_lock);
  1240. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  1241. DSI_CORE_CLK, DSI_CLK_ON);
  1242. if (rc) {
  1243. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  1244. display->name, rc);
  1245. goto error;
  1246. }
  1247. display_for_each_ctrl(i, display) {
  1248. dsi_ctrl = display->ctrl[i].ctrl;
  1249. misr = dsi_ctrl_collect_misr(display->ctrl[i].ctrl);
  1250. len += snprintf((buf + len), max_len - len,
  1251. "DSI_%d MISR: 0x%x\n", dsi_ctrl->cell_index, misr);
  1252. if (len >= max_len)
  1253. break;
  1254. }
  1255. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  1256. DSI_CORE_CLK, DSI_CLK_OFF);
  1257. if (rc) {
  1258. DSI_ERR("[%s] failed to disable DSI core clocks, rc=%d\n",
  1259. display->name, rc);
  1260. goto error;
  1261. }
  1262. if (copy_to_user(user_buf, buf, max_len)) {
  1263. rc = -EFAULT;
  1264. goto error;
  1265. }
  1266. *ppos += len;
  1267. error:
  1268. mutex_unlock(&display->display_lock);
  1269. kfree(buf);
  1270. return len;
  1271. }
  1272. static ssize_t debugfs_esd_trigger_check(struct file *file,
  1273. const char __user *user_buf,
  1274. size_t user_len,
  1275. loff_t *ppos)
  1276. {
  1277. struct dsi_display *display = file->private_data;
  1278. char *buf;
  1279. int rc = 0;
  1280. struct drm_panel_esd_config *esd_config = &display->panel->esd_config;
  1281. u32 esd_trigger;
  1282. size_t len;
  1283. if (!display)
  1284. return -ENODEV;
  1285. if (*ppos)
  1286. return 0;
  1287. if (user_len > sizeof(u32))
  1288. return -EINVAL;
  1289. if (!user_len || !user_buf)
  1290. return -EINVAL;
  1291. if (!display->panel ||
  1292. atomic_read(&display->panel->esd_recovery_pending))
  1293. return user_len;
  1294. if (!esd_config->esd_enabled) {
  1295. DSI_ERR("ESD feature is not enabled\n");
  1296. return -EINVAL;
  1297. }
  1298. buf = kzalloc(ESD_TRIGGER_STRING_MAX_LEN, GFP_KERNEL);
  1299. if (!buf)
  1300. return -ENOMEM;
  1301. len = min_t(size_t, user_len, ESD_TRIGGER_STRING_MAX_LEN - 1);
  1302. if (copy_from_user(buf, user_buf, len)) {
  1303. rc = -EINVAL;
  1304. goto error;
  1305. }
  1306. buf[len] = '\0'; /* terminate the string */
  1307. if (kstrtouint(buf, 10, &esd_trigger)) {
  1308. rc = -EINVAL;
  1309. goto error;
  1310. }
  1311. if (esd_trigger != 1) {
  1312. rc = -EINVAL;
  1313. goto error;
  1314. }
  1315. display->esd_trigger = esd_trigger;
  1316. if (display->esd_trigger) {
  1317. DSI_INFO("ESD attack triggered by user\n");
  1318. rc = dsi_panel_trigger_esd_attack(display->panel,
  1319. display->trusted_vm_env);
  1320. if (rc) {
  1321. DSI_ERR("Failed to trigger ESD attack\n");
  1322. goto error;
  1323. }
  1324. }
  1325. rc = len;
  1326. error:
  1327. kfree(buf);
  1328. return rc;
  1329. }
  1330. static ssize_t debugfs_alter_esd_check_mode(struct file *file,
  1331. const char __user *user_buf,
  1332. size_t user_len,
  1333. loff_t *ppos)
  1334. {
  1335. struct dsi_display *display = file->private_data;
  1336. struct drm_panel_esd_config *esd_config;
  1337. char *buf;
  1338. int rc = 0;
  1339. size_t len;
  1340. if (!display)
  1341. return -ENODEV;
  1342. if (*ppos)
  1343. return 0;
  1344. buf = kzalloc(ESD_MODE_STRING_MAX_LEN, GFP_KERNEL);
  1345. if (ZERO_OR_NULL_PTR(buf))
  1346. return -ENOMEM;
  1347. len = min_t(size_t, user_len, ESD_MODE_STRING_MAX_LEN - 1);
  1348. if (copy_from_user(buf, user_buf, len)) {
  1349. rc = -EINVAL;
  1350. goto error;
  1351. }
  1352. buf[len] = '\0'; /* terminate the string */
  1353. if (!display->panel) {
  1354. rc = -EINVAL;
  1355. goto error;
  1356. }
  1357. esd_config = &display->panel->esd_config;
  1358. if (!esd_config) {
  1359. DSI_ERR("Invalid panel esd config\n");
  1360. rc = -EINVAL;
  1361. goto error;
  1362. }
  1363. if (!esd_config->esd_enabled) {
  1364. rc = -EINVAL;
  1365. goto error;
  1366. }
  1367. if (!strcmp(buf, "te_signal_check\n")) {
  1368. if (display->panel->panel_mode == DSI_OP_VIDEO_MODE) {
  1369. DSI_INFO("TE based ESD check for Video Mode panels is not allowed\n");
  1370. rc = -EINVAL;
  1371. goto error;
  1372. }
  1373. DSI_INFO("ESD check is switched to TE mode by user\n");
  1374. esd_config->status_mode = ESD_MODE_PANEL_TE;
  1375. dsi_display_change_te_irq_status(display, true);
  1376. }
  1377. if (!strcmp(buf, "reg_read\n")) {
  1378. DSI_INFO("ESD check is switched to reg read by user\n");
  1379. rc = dsi_panel_parse_esd_reg_read_configs(display->panel);
  1380. if (rc) {
  1381. DSI_ERR("failed to alter esd check mode,rc=%d\n",
  1382. rc);
  1383. rc = user_len;
  1384. goto error;
  1385. }
  1386. esd_config->status_mode = ESD_MODE_REG_READ;
  1387. if (dsi_display_is_te_based_esd(display))
  1388. dsi_display_change_te_irq_status(display, false);
  1389. }
  1390. if (!strcmp(buf, "esd_sw_sim_success\n"))
  1391. esd_config->status_mode = ESD_MODE_SW_SIM_SUCCESS;
  1392. if (!strcmp(buf, "esd_sw_sim_failure\n"))
  1393. esd_config->status_mode = ESD_MODE_SW_SIM_FAILURE;
  1394. rc = len;
  1395. error:
  1396. kfree(buf);
  1397. return rc;
  1398. }
  1399. static ssize_t debugfs_read_esd_check_mode(struct file *file,
  1400. char __user *user_buf,
  1401. size_t user_len,
  1402. loff_t *ppos)
  1403. {
  1404. struct dsi_display *display = file->private_data;
  1405. struct drm_panel_esd_config *esd_config;
  1406. char *buf;
  1407. int rc = 0;
  1408. size_t len = 0;
  1409. if (!display)
  1410. return -ENODEV;
  1411. if (*ppos)
  1412. return 0;
  1413. if (!display->panel) {
  1414. DSI_ERR("invalid panel data\n");
  1415. return -EINVAL;
  1416. }
  1417. buf = kzalloc(ESD_MODE_STRING_MAX_LEN, GFP_KERNEL);
  1418. if (ZERO_OR_NULL_PTR(buf))
  1419. return -ENOMEM;
  1420. esd_config = &display->panel->esd_config;
  1421. if (!esd_config) {
  1422. DSI_ERR("Invalid panel esd config\n");
  1423. rc = -EINVAL;
  1424. goto error;
  1425. }
  1426. len = min_t(size_t, user_len, ESD_MODE_STRING_MAX_LEN - 1);
  1427. if (!esd_config->esd_enabled) {
  1428. rc = snprintf(buf, len, "ESD feature not enabled");
  1429. goto output_mode;
  1430. }
  1431. switch (esd_config->status_mode) {
  1432. case ESD_MODE_REG_READ:
  1433. rc = snprintf(buf, len, "reg_read");
  1434. break;
  1435. case ESD_MODE_PANEL_TE:
  1436. rc = snprintf(buf, len, "te_signal_check");
  1437. break;
  1438. case ESD_MODE_SW_SIM_FAILURE:
  1439. rc = snprintf(buf, len, "esd_sw_sim_failure");
  1440. break;
  1441. case ESD_MODE_SW_SIM_SUCCESS:
  1442. rc = snprintf(buf, len, "esd_sw_sim_success");
  1443. break;
  1444. default:
  1445. rc = snprintf(buf, len, "invalid");
  1446. break;
  1447. }
  1448. output_mode:
  1449. if (!rc) {
  1450. rc = -EINVAL;
  1451. goto error;
  1452. }
  1453. if (copy_to_user(user_buf, buf, len)) {
  1454. rc = -EFAULT;
  1455. goto error;
  1456. }
  1457. *ppos += len;
  1458. error:
  1459. kfree(buf);
  1460. return len;
  1461. }
  1462. static ssize_t debugfs_update_cmd_scheduling_params(struct file *file,
  1463. const char __user *user_buf,
  1464. size_t user_len,
  1465. loff_t *ppos)
  1466. {
  1467. struct dsi_display *display = file->private_data;
  1468. struct dsi_display_ctrl *display_ctrl;
  1469. char *buf;
  1470. int rc = 0;
  1471. u32 line = 0, window = 0;
  1472. size_t len;
  1473. int i;
  1474. if (!display)
  1475. return -ENODEV;
  1476. if (*ppos)
  1477. return 0;
  1478. buf = kzalloc(256, GFP_KERNEL);
  1479. if (ZERO_OR_NULL_PTR(buf))
  1480. return -ENOMEM;
  1481. len = min_t(size_t, user_len, 255);
  1482. if (copy_from_user(buf, user_buf, len)) {
  1483. rc = -EINVAL;
  1484. goto error;
  1485. }
  1486. buf[len] = '\0'; /* terminate the string */
  1487. if (sscanf(buf, "%d %d", &line, &window) != 2)
  1488. return -EFAULT;
  1489. display_for_each_ctrl(i, display) {
  1490. struct dsi_ctrl *ctrl;
  1491. display_ctrl = &display->ctrl[i];
  1492. if (!display_ctrl->ctrl)
  1493. continue;
  1494. ctrl = display_ctrl->ctrl;
  1495. ctrl->host_config.common_config.dma_sched_line = line;
  1496. ctrl->host_config.common_config.dma_sched_window = window;
  1497. }
  1498. rc = len;
  1499. error:
  1500. kfree(buf);
  1501. return rc;
  1502. }
  1503. static ssize_t debugfs_read_cmd_scheduling_params(struct file *file,
  1504. char __user *user_buf,
  1505. size_t user_len,
  1506. loff_t *ppos)
  1507. {
  1508. struct dsi_display *display = file->private_data;
  1509. struct dsi_display_ctrl *m_ctrl;
  1510. struct dsi_ctrl *ctrl;
  1511. char *buf;
  1512. u32 len = 0;
  1513. int rc = 0;
  1514. size_t max_len = min_t(size_t, user_len, SZ_4K);
  1515. if (!display)
  1516. return -ENODEV;
  1517. if (*ppos)
  1518. return 0;
  1519. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1520. ctrl = m_ctrl->ctrl;
  1521. buf = kzalloc(max_len, GFP_KERNEL);
  1522. if (ZERO_OR_NULL_PTR(buf))
  1523. return -ENOMEM;
  1524. len += scnprintf(buf, max_len, "Schedule command window start: %d\n",
  1525. ctrl->host_config.common_config.dma_sched_line);
  1526. len += scnprintf((buf + len), max_len - len,
  1527. "Schedule command window width: %d\n",
  1528. ctrl->host_config.common_config.dma_sched_window);
  1529. if (len > max_len)
  1530. len = max_len;
  1531. if (copy_to_user(user_buf, buf, len)) {
  1532. rc = -EFAULT;
  1533. goto error;
  1534. }
  1535. *ppos += len;
  1536. error:
  1537. kfree(buf);
  1538. return len;
  1539. }
  1540. static const struct file_operations dump_info_fops = {
  1541. .open = simple_open,
  1542. .read = debugfs_dump_info_read,
  1543. };
  1544. static const struct file_operations misr_data_fops = {
  1545. .open = simple_open,
  1546. .read = debugfs_misr_read,
  1547. .write = debugfs_misr_setup,
  1548. };
  1549. static const struct file_operations esd_trigger_fops = {
  1550. .open = simple_open,
  1551. .write = debugfs_esd_trigger_check,
  1552. };
  1553. static const struct file_operations esd_check_mode_fops = {
  1554. .open = simple_open,
  1555. .write = debugfs_alter_esd_check_mode,
  1556. .read = debugfs_read_esd_check_mode,
  1557. };
  1558. static const struct file_operations dsi_command_scheduling_fops = {
  1559. .open = simple_open,
  1560. .write = debugfs_update_cmd_scheduling_params,
  1561. .read = debugfs_read_cmd_scheduling_params,
  1562. };
  1563. static int dsi_display_debugfs_init(struct dsi_display *display)
  1564. {
  1565. int rc = 0;
  1566. struct dentry *dir, *dump_file, *misr_data;
  1567. char name[MAX_NAME_SIZE];
  1568. char panel_name[SEC_PANEL_NAME_MAX_LEN];
  1569. char secondary_panel_str[] = "_secondary";
  1570. int i;
  1571. strlcpy(panel_name, display->name, SEC_PANEL_NAME_MAX_LEN);
  1572. if (strcmp(display->display_type, "secondary") == 0)
  1573. strlcat(panel_name, secondary_panel_str, SEC_PANEL_NAME_MAX_LEN);
  1574. dir = debugfs_create_dir(panel_name, NULL);
  1575. if (IS_ERR_OR_NULL(dir)) {
  1576. rc = PTR_ERR(dir);
  1577. DSI_ERR("[%s] debugfs create dir failed, rc = %d\n",
  1578. display->name, rc);
  1579. goto error;
  1580. }
  1581. dump_file = debugfs_create_file("dump_info",
  1582. 0400,
  1583. dir,
  1584. display,
  1585. &dump_info_fops);
  1586. if (IS_ERR_OR_NULL(dump_file)) {
  1587. rc = PTR_ERR(dump_file);
  1588. DSI_ERR("[%s] debugfs create dump info file failed, rc=%d\n",
  1589. display->name, rc);
  1590. goto error_remove_dir;
  1591. }
  1592. dump_file = debugfs_create_file("esd_trigger",
  1593. 0644,
  1594. dir,
  1595. display,
  1596. &esd_trigger_fops);
  1597. if (IS_ERR_OR_NULL(dump_file)) {
  1598. rc = PTR_ERR(dump_file);
  1599. DSI_ERR("[%s] debugfs for esd trigger file failed, rc=%d\n",
  1600. display->name, rc);
  1601. goto error_remove_dir;
  1602. }
  1603. dump_file = debugfs_create_file("esd_check_mode",
  1604. 0644,
  1605. dir,
  1606. display,
  1607. &esd_check_mode_fops);
  1608. if (IS_ERR_OR_NULL(dump_file)) {
  1609. rc = PTR_ERR(dump_file);
  1610. DSI_ERR("[%s] debugfs for esd check mode failed, rc=%d\n",
  1611. display->name, rc);
  1612. goto error_remove_dir;
  1613. }
  1614. dump_file = debugfs_create_file("cmd_sched_params",
  1615. 0644,
  1616. dir,
  1617. display,
  1618. &dsi_command_scheduling_fops);
  1619. if (IS_ERR_OR_NULL(dump_file)) {
  1620. rc = PTR_ERR(dump_file);
  1621. DSI_ERR("[%s] debugfs for cmd scheduling file failed, rc=%d\n",
  1622. display->name, rc);
  1623. goto error_remove_dir;
  1624. }
  1625. misr_data = debugfs_create_file("misr_data",
  1626. 0600,
  1627. dir,
  1628. display,
  1629. &misr_data_fops);
  1630. if (IS_ERR_OR_NULL(misr_data)) {
  1631. rc = PTR_ERR(misr_data);
  1632. DSI_ERR("[%s] debugfs create misr datafile failed, rc=%d\n",
  1633. display->name, rc);
  1634. goto error_remove_dir;
  1635. }
  1636. display_for_each_ctrl(i, display) {
  1637. struct msm_dsi_phy *phy = display->ctrl[i].phy;
  1638. if (!phy || !phy->name)
  1639. continue;
  1640. snprintf(name, ARRAY_SIZE(name),
  1641. "%s_allow_phy_power_off", phy->name);
  1642. dump_file = debugfs_create_bool(name, 0600, dir,
  1643. &phy->allow_phy_power_off);
  1644. if (IS_ERR_OR_NULL(dump_file)) {
  1645. rc = PTR_ERR(dump_file);
  1646. DSI_ERR("[%s] debugfs create %s failed, rc=%d\n",
  1647. display->name, name, rc);
  1648. goto error_remove_dir;
  1649. }
  1650. snprintf(name, ARRAY_SIZE(name),
  1651. "%s_regulator_min_datarate_bps", phy->name);
  1652. debugfs_create_u32(name, 0600, dir, &phy->regulator_min_datarate_bps);
  1653. }
  1654. if (!debugfs_create_bool("ulps_feature_enable", 0600, dir,
  1655. &display->panel->ulps_feature_enabled)) {
  1656. DSI_ERR("[%s] debugfs create ulps feature enable file failed\n",
  1657. display->name);
  1658. goto error_remove_dir;
  1659. }
  1660. if (!debugfs_create_bool("ulps_suspend_feature_enable", 0600, dir,
  1661. &display->panel->ulps_suspend_enabled)) {
  1662. DSI_ERR("[%s] debugfs create ulps-suspend feature enable file failed\n",
  1663. display->name);
  1664. goto error_remove_dir;
  1665. }
  1666. if (!debugfs_create_bool("ulps_status", 0400, dir,
  1667. &display->ulps_enabled)) {
  1668. DSI_ERR("[%s] debugfs create ulps status file failed\n",
  1669. display->name);
  1670. goto error_remove_dir;
  1671. }
  1672. debugfs_create_u32("clk_gating_config", 0600, dir, &display->clk_gating_config);
  1673. display->root = dir;
  1674. dsi_parser_dbg_init(display->parser, dir);
  1675. return rc;
  1676. error_remove_dir:
  1677. debugfs_remove(dir);
  1678. error:
  1679. return rc;
  1680. }
  1681. static int dsi_display_debugfs_deinit(struct dsi_display *display)
  1682. {
  1683. debugfs_remove_recursive(display->root);
  1684. return 0;
  1685. }
  1686. #else
  1687. static int dsi_display_debugfs_init(struct dsi_display *display)
  1688. {
  1689. return 0;
  1690. }
  1691. static int dsi_display_debugfs_deinit(struct dsi_display *display)
  1692. {
  1693. return 0;
  1694. }
  1695. #endif /* CONFIG_DEBUG_FS */
  1696. static void adjust_timing_by_ctrl_count(const struct dsi_display *display,
  1697. struct dsi_display_mode *mode)
  1698. {
  1699. struct dsi_host_common_cfg *host = &display->panel->host_config;
  1700. bool is_split_link = host->split_link.split_link_enabled;
  1701. u32 sublinks_count = host->split_link.num_sublinks;
  1702. if (is_split_link && sublinks_count > 1) {
  1703. mode->timing.h_active /= sublinks_count;
  1704. mode->timing.h_front_porch /= sublinks_count;
  1705. mode->timing.h_sync_width /= sublinks_count;
  1706. mode->timing.h_back_porch /= sublinks_count;
  1707. mode->timing.h_skew /= sublinks_count;
  1708. mode->pixel_clk_khz /= sublinks_count;
  1709. } else {
  1710. if (mode->priv_info->dsc_enabled)
  1711. mode->priv_info->dsc.config.pic_width =
  1712. mode->timing.h_active;
  1713. mode->timing.h_active /= display->ctrl_count;
  1714. mode->timing.h_front_porch /= display->ctrl_count;
  1715. mode->timing.h_sync_width /= display->ctrl_count;
  1716. mode->timing.h_back_porch /= display->ctrl_count;
  1717. mode->timing.h_skew /= display->ctrl_count;
  1718. mode->pixel_clk_khz /= display->ctrl_count;
  1719. }
  1720. }
  1721. static int dsi_display_is_ulps_req_valid(struct dsi_display *display,
  1722. bool enable)
  1723. {
  1724. /* TODO: make checks based on cont. splash */
  1725. DSI_DEBUG("checking ulps req validity\n");
  1726. if (atomic_read(&display->panel->esd_recovery_pending)) {
  1727. DSI_DEBUG("%s: ESD recovery sequence underway\n", __func__);
  1728. return false;
  1729. }
  1730. if (!dsi_panel_ulps_feature_enabled(display->panel) &&
  1731. !display->panel->ulps_suspend_enabled) {
  1732. DSI_DEBUG("%s: ULPS feature is not enabled\n", __func__);
  1733. return false;
  1734. }
  1735. if (!dsi_panel_initialized(display->panel) &&
  1736. !display->panel->ulps_suspend_enabled) {
  1737. DSI_DEBUG("%s: panel not yet initialized\n", __func__);
  1738. return false;
  1739. }
  1740. if (enable && display->ulps_enabled) {
  1741. DSI_DEBUG("ULPS already enabled\n");
  1742. return false;
  1743. } else if (!enable && !display->ulps_enabled) {
  1744. DSI_DEBUG("ULPS already disabled\n");
  1745. return false;
  1746. }
  1747. /*
  1748. * No need to enter ULPS when transitioning from splash screen to
  1749. * boot animation or trusted vm environments since it is expected
  1750. * that the clocks would be turned right back on.
  1751. */
  1752. if (enable && is_skip_op_required(display))
  1753. return false;
  1754. return true;
  1755. }
  1756. /**
  1757. * dsi_display_set_ulps() - set ULPS state for DSI lanes.
  1758. * @dsi_display: DSI display handle.
  1759. * @enable: enable/disable ULPS.
  1760. *
  1761. * ULPS can be enabled/disabled after DSI host engine is turned on.
  1762. *
  1763. * Return: error code.
  1764. */
  1765. static int dsi_display_set_ulps(struct dsi_display *display, bool enable)
  1766. {
  1767. int rc = 0;
  1768. int i = 0;
  1769. struct dsi_display_ctrl *m_ctrl, *ctrl;
  1770. if (!display) {
  1771. DSI_ERR("Invalid params\n");
  1772. return -EINVAL;
  1773. }
  1774. if (!dsi_display_is_ulps_req_valid(display, enable)) {
  1775. DSI_DEBUG("%s: skipping ULPS config, enable=%d\n",
  1776. __func__, enable);
  1777. return 0;
  1778. }
  1779. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1780. /*
  1781. * ULPS entry-exit can be either through the DSI controller or
  1782. * the DSI PHY depending on hardware variation. For some chipsets,
  1783. * both controller version and phy version ulps entry-exit ops can
  1784. * be present. To handle such cases, send ulps request through PHY,
  1785. * if ulps request is handled in PHY, then no need to send request
  1786. * through controller.
  1787. */
  1788. rc = dsi_phy_set_ulps(m_ctrl->phy, &display->config, enable,
  1789. display->clamp_enabled);
  1790. if (rc == DSI_PHY_ULPS_ERROR) {
  1791. DSI_ERR("Ulps PHY state change(%d) failed\n", enable);
  1792. return -EINVAL;
  1793. }
  1794. else if (rc == DSI_PHY_ULPS_HANDLED) {
  1795. display_for_each_ctrl(i, display) {
  1796. ctrl = &display->ctrl[i];
  1797. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1798. continue;
  1799. rc = dsi_phy_set_ulps(ctrl->phy, &display->config,
  1800. enable, display->clamp_enabled);
  1801. if (rc == DSI_PHY_ULPS_ERROR) {
  1802. DSI_ERR("Ulps PHY state change(%d) failed\n",
  1803. enable);
  1804. return -EINVAL;
  1805. }
  1806. }
  1807. }
  1808. else if (rc == DSI_PHY_ULPS_NOT_HANDLED) {
  1809. rc = dsi_ctrl_set_ulps(m_ctrl->ctrl, enable);
  1810. if (rc) {
  1811. DSI_ERR("Ulps controller state change(%d) failed\n",
  1812. enable);
  1813. return rc;
  1814. }
  1815. display_for_each_ctrl(i, display) {
  1816. ctrl = &display->ctrl[i];
  1817. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1818. continue;
  1819. rc = dsi_ctrl_set_ulps(ctrl->ctrl, enable);
  1820. if (rc) {
  1821. DSI_ERR("Ulps controller state change(%d) failed\n",
  1822. enable);
  1823. return rc;
  1824. }
  1825. }
  1826. }
  1827. display->ulps_enabled = enable;
  1828. return 0;
  1829. }
  1830. /**
  1831. * dsi_display_set_clamp() - set clamp state for DSI IO.
  1832. * @dsi_display: DSI display handle.
  1833. * @enable: enable/disable clamping.
  1834. *
  1835. * Return: error code.
  1836. */
  1837. static int dsi_display_set_clamp(struct dsi_display *display, bool enable)
  1838. {
  1839. int rc = 0;
  1840. int i = 0;
  1841. struct dsi_display_ctrl *m_ctrl, *ctrl;
  1842. bool ulps_enabled = false;
  1843. if (!display) {
  1844. DSI_ERR("Invalid params\n");
  1845. return -EINVAL;
  1846. }
  1847. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1848. ulps_enabled = display->ulps_enabled;
  1849. /*
  1850. * Clamp control can be either through the DSI controller or
  1851. * the DSI PHY depending on hardware variation
  1852. */
  1853. rc = dsi_ctrl_set_clamp_state(m_ctrl->ctrl, enable, ulps_enabled);
  1854. if (rc) {
  1855. DSI_ERR("DSI ctrl clamp state change(%d) failed\n", enable);
  1856. return rc;
  1857. }
  1858. rc = dsi_phy_set_clamp_state(m_ctrl->phy, enable);
  1859. if (rc) {
  1860. DSI_ERR("DSI phy clamp state change(%d) failed\n", enable);
  1861. return rc;
  1862. }
  1863. display_for_each_ctrl(i, display) {
  1864. ctrl = &display->ctrl[i];
  1865. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1866. continue;
  1867. rc = dsi_ctrl_set_clamp_state(ctrl->ctrl, enable, ulps_enabled);
  1868. if (rc) {
  1869. DSI_ERR("DSI Clamp state change(%d) failed\n", enable);
  1870. return rc;
  1871. }
  1872. rc = dsi_phy_set_clamp_state(ctrl->phy, enable);
  1873. if (rc) {
  1874. DSI_ERR("DSI phy clamp state change(%d) failed\n",
  1875. enable);
  1876. return rc;
  1877. }
  1878. DSI_DEBUG("Clamps %s for ctrl%d\n",
  1879. enable ? "enabled" : "disabled", i);
  1880. }
  1881. display->clamp_enabled = enable;
  1882. return 0;
  1883. }
  1884. /**
  1885. * dsi_display_setup_ctrl() - setup DSI controller.
  1886. * @dsi_display: DSI display handle.
  1887. *
  1888. * Return: error code.
  1889. */
  1890. static int dsi_display_ctrl_setup(struct dsi_display *display)
  1891. {
  1892. int rc = 0;
  1893. int i = 0;
  1894. struct dsi_display_ctrl *ctrl, *m_ctrl;
  1895. if (!display) {
  1896. DSI_ERR("Invalid params\n");
  1897. return -EINVAL;
  1898. }
  1899. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1900. rc = dsi_ctrl_setup(m_ctrl->ctrl);
  1901. if (rc) {
  1902. DSI_ERR("DSI controller setup failed\n");
  1903. return rc;
  1904. }
  1905. display_for_each_ctrl(i, display) {
  1906. ctrl = &display->ctrl[i];
  1907. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1908. continue;
  1909. rc = dsi_ctrl_setup(ctrl->ctrl);
  1910. if (rc) {
  1911. DSI_ERR("DSI controller setup failed\n");
  1912. return rc;
  1913. }
  1914. }
  1915. return 0;
  1916. }
  1917. static int dsi_display_phy_enable(struct dsi_display *display);
  1918. /**
  1919. * dsi_display_phy_idle_on() - enable DSI PHY while coming out of idle screen.
  1920. * @dsi_display: DSI display handle.
  1921. * @mmss_clamp: True if clamp is enabled.
  1922. *
  1923. * Return: error code.
  1924. */
  1925. static int dsi_display_phy_idle_on(struct dsi_display *display,
  1926. bool mmss_clamp)
  1927. {
  1928. int rc = 0;
  1929. int i = 0;
  1930. struct dsi_display_ctrl *m_ctrl, *ctrl;
  1931. if (!display) {
  1932. DSI_ERR("Invalid params\n");
  1933. return -EINVAL;
  1934. }
  1935. if (mmss_clamp && !display->phy_idle_power_off) {
  1936. dsi_display_phy_enable(display);
  1937. return 0;
  1938. }
  1939. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1940. rc = dsi_phy_idle_ctrl(m_ctrl->phy, true);
  1941. if (rc) {
  1942. DSI_ERR("DSI controller setup failed\n");
  1943. return rc;
  1944. }
  1945. display_for_each_ctrl(i, display) {
  1946. ctrl = &display->ctrl[i];
  1947. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1948. continue;
  1949. rc = dsi_phy_idle_ctrl(ctrl->phy, true);
  1950. if (rc) {
  1951. DSI_ERR("DSI controller setup failed\n");
  1952. return rc;
  1953. }
  1954. }
  1955. display->phy_idle_power_off = false;
  1956. return 0;
  1957. }
  1958. /**
  1959. * dsi_display_phy_idle_off() - disable DSI PHY while going to idle screen.
  1960. * @dsi_display: DSI display handle.
  1961. *
  1962. * Return: error code.
  1963. */
  1964. static int dsi_display_phy_idle_off(struct dsi_display *display)
  1965. {
  1966. int rc = 0;
  1967. int i = 0;
  1968. struct dsi_display_ctrl *m_ctrl, *ctrl;
  1969. if (!display) {
  1970. DSI_ERR("Invalid params\n");
  1971. return -EINVAL;
  1972. }
  1973. display_for_each_ctrl(i, display) {
  1974. struct msm_dsi_phy *phy = display->ctrl[i].phy;
  1975. if (!phy)
  1976. continue;
  1977. if (!phy->allow_phy_power_off) {
  1978. DSI_DEBUG("phy doesn't support this feature\n");
  1979. return 0;
  1980. }
  1981. }
  1982. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1983. rc = dsi_phy_idle_ctrl(m_ctrl->phy, false);
  1984. if (rc) {
  1985. DSI_ERR("[%s] failed to enable cmd engine, rc=%d\n",
  1986. display->name, rc);
  1987. return rc;
  1988. }
  1989. display_for_each_ctrl(i, display) {
  1990. ctrl = &display->ctrl[i];
  1991. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1992. continue;
  1993. rc = dsi_phy_idle_ctrl(ctrl->phy, false);
  1994. if (rc) {
  1995. DSI_ERR("DSI controller setup failed\n");
  1996. return rc;
  1997. }
  1998. }
  1999. display->phy_idle_power_off = true;
  2000. return 0;
  2001. }
  2002. void dsi_display_enable_event(struct drm_connector *connector,
  2003. struct dsi_display *display,
  2004. uint32_t event_idx, struct dsi_event_cb_info *event_info,
  2005. bool enable)
  2006. {
  2007. uint32_t irq_status_idx = DSI_STATUS_INTERRUPT_COUNT;
  2008. int i;
  2009. if (!display) {
  2010. DSI_ERR("invalid display\n");
  2011. return;
  2012. }
  2013. if (event_info)
  2014. event_info->event_idx = event_idx;
  2015. switch (event_idx) {
  2016. case SDE_CONN_EVENT_VID_DONE:
  2017. irq_status_idx = DSI_SINT_VIDEO_MODE_FRAME_DONE;
  2018. break;
  2019. case SDE_CONN_EVENT_CMD_DONE:
  2020. irq_status_idx = DSI_SINT_CMD_FRAME_DONE;
  2021. break;
  2022. case SDE_CONN_EVENT_VID_FIFO_OVERFLOW:
  2023. case SDE_CONN_EVENT_CMD_FIFO_UNDERFLOW:
  2024. if (event_info) {
  2025. display_for_each_ctrl(i, display)
  2026. display->ctrl[i].ctrl->recovery_cb =
  2027. *event_info;
  2028. }
  2029. break;
  2030. case SDE_CONN_EVENT_PANEL_ID:
  2031. if (event_info)
  2032. display_for_each_ctrl(i, display)
  2033. display->ctrl[i].ctrl->panel_id_cb
  2034. = *event_info;
  2035. break;
  2036. default:
  2037. /* nothing to do */
  2038. DSI_DEBUG("[%s] unhandled event %d\n", display->name, event_idx);
  2039. return;
  2040. }
  2041. if (enable) {
  2042. display_for_each_ctrl(i, display)
  2043. dsi_ctrl_enable_status_interrupt(
  2044. display->ctrl[i].ctrl, irq_status_idx,
  2045. event_info);
  2046. } else {
  2047. display_for_each_ctrl(i, display)
  2048. dsi_ctrl_disable_status_interrupt(
  2049. display->ctrl[i].ctrl, irq_status_idx);
  2050. }
  2051. }
  2052. static int dsi_display_ctrl_power_on(struct dsi_display *display)
  2053. {
  2054. int rc = 0;
  2055. int i;
  2056. struct dsi_display_ctrl *ctrl;
  2057. /* Sequence does not matter for split dsi usecases */
  2058. display_for_each_ctrl(i, display) {
  2059. ctrl = &display->ctrl[i];
  2060. if (!ctrl->ctrl)
  2061. continue;
  2062. rc = dsi_ctrl_set_power_state(ctrl->ctrl,
  2063. DSI_CTRL_POWER_VREG_ON);
  2064. if (rc) {
  2065. DSI_ERR("[%s] Failed to set power state, rc=%d\n",
  2066. ctrl->ctrl->name, rc);
  2067. goto error;
  2068. }
  2069. }
  2070. return rc;
  2071. error:
  2072. for (i = i - 1; i >= 0; i--) {
  2073. ctrl = &display->ctrl[i];
  2074. if (!ctrl->ctrl)
  2075. continue;
  2076. (void)dsi_ctrl_set_power_state(ctrl->ctrl,
  2077. DSI_CTRL_POWER_VREG_OFF);
  2078. }
  2079. return rc;
  2080. }
  2081. static int dsi_display_ctrl_power_off(struct dsi_display *display)
  2082. {
  2083. int rc = 0;
  2084. int i;
  2085. struct dsi_display_ctrl *ctrl;
  2086. /* Sequence does not matter for split dsi usecases */
  2087. display_for_each_ctrl(i, display) {
  2088. ctrl = &display->ctrl[i];
  2089. if (!ctrl->ctrl)
  2090. continue;
  2091. rc = dsi_ctrl_set_power_state(ctrl->ctrl,
  2092. DSI_CTRL_POWER_VREG_OFF);
  2093. if (rc) {
  2094. DSI_ERR("[%s] Failed to power off, rc=%d\n",
  2095. ctrl->ctrl->name, rc);
  2096. goto error;
  2097. }
  2098. }
  2099. error:
  2100. return rc;
  2101. }
  2102. static void dsi_display_parse_cmdline_topology(struct dsi_display *display,
  2103. unsigned int display_type)
  2104. {
  2105. char *boot_str = NULL;
  2106. char *str = NULL;
  2107. char *sw_te = NULL;
  2108. unsigned long cmdline_topology = NO_OVERRIDE;
  2109. unsigned long cmdline_timing = NO_OVERRIDE;
  2110. if (display_type >= MAX_DSI_ACTIVE_DISPLAY) {
  2111. DSI_ERR("display_type=%d not supported\n", display_type);
  2112. goto end;
  2113. }
  2114. if (display_type == DSI_PRIMARY)
  2115. boot_str = dsi_display_primary;
  2116. else
  2117. boot_str = dsi_display_secondary;
  2118. sw_te = strnstr(boot_str, ":sim-swte", strlen(boot_str));
  2119. if (sw_te)
  2120. display->sw_te_using_wd = true;
  2121. str = strnstr(boot_str, ":config", strlen(boot_str));
  2122. if (str) {
  2123. if (sscanf(str, ":config%lu", &cmdline_topology) != 1) {
  2124. DSI_ERR("invalid config index override: %s\n",
  2125. boot_str);
  2126. goto end;
  2127. }
  2128. }
  2129. str = strnstr(boot_str, ":timing", strlen(boot_str));
  2130. if (str) {
  2131. if (sscanf(str, ":timing%lu", &cmdline_timing) != 1) {
  2132. DSI_ERR("invalid timing index override: %s\n",
  2133. boot_str);
  2134. cmdline_topology = NO_OVERRIDE;
  2135. goto end;
  2136. }
  2137. }
  2138. DSI_DEBUG("successfully parsed command line topology and timing\n");
  2139. end:
  2140. display->cmdline_topology = cmdline_topology;
  2141. display->cmdline_timing = cmdline_timing;
  2142. }
  2143. /**
  2144. * dsi_display_parse_boot_display_selection()- Parse DSI boot display name
  2145. *
  2146. * Return: returns error status
  2147. */
  2148. static int dsi_display_parse_boot_display_selection(void)
  2149. {
  2150. char *pos = NULL;
  2151. char disp_buf[MAX_CMDLINE_PARAM_LEN] = {'\0'};
  2152. int i, j;
  2153. for (i = 0; i < MAX_DSI_ACTIVE_DISPLAY; i++) {
  2154. strlcpy(disp_buf, boot_displays[i].boot_param,
  2155. MAX_CMDLINE_PARAM_LEN);
  2156. pos = strnstr(disp_buf, ":", MAX_CMDLINE_PARAM_LEN);
  2157. /* Use ':' as a delimiter to retrieve the display name */
  2158. if (!pos) {
  2159. DSI_DEBUG("display name[%s]is not valid\n", disp_buf);
  2160. continue;
  2161. }
  2162. for (j = 0; (disp_buf + j) < pos; j++)
  2163. boot_displays[i].name[j] = *(disp_buf + j);
  2164. boot_displays[i].name[j] = '\0';
  2165. boot_displays[i].boot_disp_en = true;
  2166. }
  2167. return 0;
  2168. }
  2169. static int dsi_display_phy_power_on(struct dsi_display *display)
  2170. {
  2171. int rc = 0;
  2172. int i;
  2173. struct dsi_display_ctrl *ctrl;
  2174. /* Sequence does not matter for split dsi usecases */
  2175. display_for_each_ctrl(i, display) {
  2176. ctrl = &display->ctrl[i];
  2177. if (!ctrl->ctrl)
  2178. continue;
  2179. rc = dsi_phy_set_power_state(ctrl->phy, true);
  2180. if (rc) {
  2181. DSI_ERR("[%s] Failed to set power state, rc=%d\n",
  2182. ctrl->phy->name, rc);
  2183. goto error;
  2184. }
  2185. }
  2186. return rc;
  2187. error:
  2188. for (i = i - 1; i >= 0; i--) {
  2189. ctrl = &display->ctrl[i];
  2190. if (!ctrl->phy)
  2191. continue;
  2192. (void)dsi_phy_set_power_state(ctrl->phy, false);
  2193. }
  2194. return rc;
  2195. }
  2196. static int dsi_display_phy_power_off(struct dsi_display *display)
  2197. {
  2198. int rc = 0;
  2199. int i;
  2200. struct dsi_display_ctrl *ctrl;
  2201. /* Sequence does not matter for split dsi usecases */
  2202. display_for_each_ctrl(i, display) {
  2203. ctrl = &display->ctrl[i];
  2204. if (!ctrl->phy)
  2205. continue;
  2206. rc = dsi_phy_set_power_state(ctrl->phy, false);
  2207. if (rc) {
  2208. DSI_ERR("[%s] Failed to power off, rc=%d\n",
  2209. ctrl->ctrl->name, rc);
  2210. goto error;
  2211. }
  2212. }
  2213. error:
  2214. return rc;
  2215. }
  2216. static int dsi_display_set_clk_src(struct dsi_display *display, bool set_xo)
  2217. {
  2218. int rc = 0;
  2219. int i;
  2220. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2221. struct dsi_ctrl_clk_info *info;
  2222. if (display->trusted_vm_env)
  2223. return 0;
  2224. /*
  2225. * In case of split DSI usecases, the clock for master controller should
  2226. * be enabled before the other controller. Master controller in the
  2227. * clock context refers to the controller that sources the clock. While turning off the
  2228. * clocks, the source is set to xo.
  2229. */
  2230. m_ctrl = &display->ctrl[display->clk_master_idx];
  2231. info = &m_ctrl->ctrl->clk_info;
  2232. if (!set_xo)
  2233. rc = dsi_ctrl_set_clock_source(m_ctrl->ctrl, &display->clock_info.pll_clks);
  2234. else if ((info->xo_clk.byte_clk) && (info->xo_clk.pixel_clk))
  2235. rc = dsi_ctrl_set_clock_source(m_ctrl->ctrl, &info->xo_clk);
  2236. if (rc) {
  2237. DSI_ERR("[%s] failed to set source clocks for master, rc=%d\n", display->name, rc);
  2238. return rc;
  2239. }
  2240. /* Set source for the rest of the controllers */
  2241. display_for_each_ctrl(i, display) {
  2242. ctrl = &display->ctrl[i];
  2243. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2244. continue;
  2245. info = &ctrl->ctrl->clk_info;
  2246. if (!set_xo)
  2247. rc = dsi_ctrl_set_clock_source(ctrl->ctrl, &display->clock_info.pll_clks);
  2248. else if ((info->xo_clk.byte_clk) && (info->xo_clk.pixel_clk))
  2249. rc = dsi_ctrl_set_clock_source(ctrl->ctrl, &info->xo_clk);
  2250. if (rc) {
  2251. DSI_ERR("[%s] failed to set source clocks, rc=%d\n", display->name, rc);
  2252. return rc;
  2253. }
  2254. }
  2255. return 0;
  2256. }
  2257. int dsi_display_phy_pll_toggle(void *priv, bool prepare)
  2258. {
  2259. int rc = 0;
  2260. struct dsi_display *display = priv;
  2261. struct dsi_display_ctrl *m_ctrl;
  2262. if (!display) {
  2263. DSI_ERR("invalid arguments\n");
  2264. return -EINVAL;
  2265. }
  2266. rc = dsi_display_set_clk_src(display, !prepare);
  2267. m_ctrl = &display->ctrl[display->clk_master_idx];
  2268. if (!m_ctrl->phy) {
  2269. DSI_ERR("[%s] PHY not found\n", display->name);
  2270. return -EINVAL;
  2271. }
  2272. rc = dsi_phy_pll_toggle(m_ctrl->phy, prepare);
  2273. return rc;
  2274. }
  2275. int dsi_display_phy_configure(void *priv, bool commit)
  2276. {
  2277. int rc = 0;
  2278. struct dsi_display *display = priv;
  2279. struct dsi_display_ctrl *m_ctrl;
  2280. struct dsi_pll_resource *pll_res;
  2281. struct dsi_ctrl *ctrl;
  2282. if (!display) {
  2283. DSI_ERR("invalid arguments\n");
  2284. return -EINVAL;
  2285. }
  2286. m_ctrl = &display->ctrl[display->clk_master_idx];
  2287. if ((!m_ctrl->phy) || (!m_ctrl->ctrl)) {
  2288. DSI_ERR("[%s] PHY not found\n", display->name);
  2289. return -EINVAL;
  2290. }
  2291. pll_res = m_ctrl->phy->pll;
  2292. if (!pll_res) {
  2293. DSI_ERR("[%s] PLL res not found\n", display->name);
  2294. return -EINVAL;
  2295. }
  2296. ctrl = m_ctrl->ctrl;
  2297. pll_res->byteclk_rate = ctrl->clk_freq.byte_clk_rate;
  2298. pll_res->pclk_rate = ctrl->clk_freq.pix_clk_rate;
  2299. rc = dsi_phy_configure(m_ctrl->phy, commit);
  2300. return rc;
  2301. }
  2302. static int dsi_display_phy_reset_config(struct dsi_display *display,
  2303. bool enable)
  2304. {
  2305. int rc = 0;
  2306. int i;
  2307. struct dsi_display_ctrl *ctrl;
  2308. display_for_each_ctrl(i, display) {
  2309. ctrl = &display->ctrl[i];
  2310. rc = dsi_ctrl_phy_reset_config(ctrl->ctrl, enable);
  2311. if (rc) {
  2312. DSI_ERR("[%s] failed to %s phy reset, rc=%d\n",
  2313. display->name, enable ? "mask" : "unmask", rc);
  2314. return rc;
  2315. }
  2316. }
  2317. return 0;
  2318. }
  2319. static void dsi_display_toggle_resync_fifo(struct dsi_display *display)
  2320. {
  2321. struct dsi_display_ctrl *ctrl;
  2322. int i;
  2323. if (!display)
  2324. return;
  2325. display_for_each_ctrl(i, display) {
  2326. ctrl = &display->ctrl[i];
  2327. dsi_phy_toggle_resync_fifo(ctrl->phy);
  2328. }
  2329. /*
  2330. * After retime buffer synchronization we need to turn of clk_en_sel
  2331. * bit on each phy. Avoid this for Cphy.
  2332. */
  2333. if (display->panel->host_config.phy_type == DSI_PHY_TYPE_CPHY)
  2334. return;
  2335. display_for_each_ctrl(i, display) {
  2336. ctrl = &display->ctrl[i];
  2337. dsi_phy_reset_clk_en_sel(ctrl->phy);
  2338. }
  2339. }
  2340. static int dsi_display_ctrl_update(struct dsi_display *display)
  2341. {
  2342. int rc = 0;
  2343. int i;
  2344. struct dsi_display_ctrl *ctrl;
  2345. display_for_each_ctrl(i, display) {
  2346. ctrl = &display->ctrl[i];
  2347. rc = dsi_ctrl_host_timing_update(ctrl->ctrl);
  2348. if (rc) {
  2349. DSI_ERR("[%s] failed to update host_%d, rc=%d\n",
  2350. display->name, i, rc);
  2351. goto error_host_deinit;
  2352. }
  2353. }
  2354. return 0;
  2355. error_host_deinit:
  2356. for (i = i - 1; i >= 0; i--) {
  2357. ctrl = &display->ctrl[i];
  2358. (void)dsi_ctrl_host_deinit(ctrl->ctrl);
  2359. }
  2360. return rc;
  2361. }
  2362. static int dsi_display_ctrl_init(struct dsi_display *display)
  2363. {
  2364. int rc = 0;
  2365. int i;
  2366. struct dsi_display_ctrl *ctrl;
  2367. bool skip_op = is_skip_op_required(display);
  2368. /* when ULPS suspend feature is enabled, we will keep the lanes in
  2369. * ULPS during suspend state and clamp DSI phy. Hence while resuming
  2370. * we will programe DSI controller as part of core clock enable.
  2371. * After that we should not re-configure DSI controller again here for
  2372. * usecases where we are resuming from ulps suspend as it might put
  2373. * the HW in bad state.
  2374. */
  2375. if (!display->panel->ulps_suspend_enabled || !display->ulps_enabled) {
  2376. display_for_each_ctrl(i, display) {
  2377. ctrl = &display->ctrl[i];
  2378. rc = dsi_ctrl_host_init(ctrl->ctrl, skip_op);
  2379. if (rc) {
  2380. DSI_ERR(
  2381. "[%s] failed to init host_%d, skip_op=%d, rc=%d\n",
  2382. display->name, i, skip_op, rc);
  2383. goto error_host_deinit;
  2384. }
  2385. }
  2386. } else {
  2387. display_for_each_ctrl(i, display) {
  2388. ctrl = &display->ctrl[i];
  2389. rc = dsi_ctrl_update_host_state(ctrl->ctrl,
  2390. DSI_CTRL_OP_HOST_INIT,
  2391. true);
  2392. if (rc)
  2393. DSI_DEBUG("host init update failed rc=%d\n",
  2394. rc);
  2395. }
  2396. }
  2397. return rc;
  2398. error_host_deinit:
  2399. for (i = i - 1; i >= 0; i--) {
  2400. ctrl = &display->ctrl[i];
  2401. (void)dsi_ctrl_host_deinit(ctrl->ctrl);
  2402. }
  2403. return rc;
  2404. }
  2405. static int dsi_display_ctrl_deinit(struct dsi_display *display)
  2406. {
  2407. int rc = 0;
  2408. int i;
  2409. struct dsi_display_ctrl *ctrl;
  2410. display_for_each_ctrl(i, display) {
  2411. ctrl = &display->ctrl[i];
  2412. rc = dsi_ctrl_host_deinit(ctrl->ctrl);
  2413. if (rc) {
  2414. DSI_ERR("[%s] failed to deinit host_%d, rc=%d\n",
  2415. display->name, i, rc);
  2416. }
  2417. }
  2418. return rc;
  2419. }
  2420. static int dsi_display_ctrl_host_enable(struct dsi_display *display)
  2421. {
  2422. int rc = 0;
  2423. int i;
  2424. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2425. bool skip_op = is_skip_op_required(display);
  2426. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2427. rc = dsi_ctrl_set_host_engine_state(m_ctrl->ctrl,
  2428. DSI_CTRL_ENGINE_ON, skip_op);
  2429. if (rc) {
  2430. DSI_ERR("[%s]enable host engine failed, skip_op:%d rc:%d\n",
  2431. display->name, skip_op, rc);
  2432. goto error;
  2433. }
  2434. display_for_each_ctrl(i, display) {
  2435. ctrl = &display->ctrl[i];
  2436. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2437. continue;
  2438. rc = dsi_ctrl_set_host_engine_state(ctrl->ctrl,
  2439. DSI_CTRL_ENGINE_ON, skip_op);
  2440. if (rc) {
  2441. DSI_ERR(
  2442. "[%s] enable host engine failed, skip_op:%d rc:%d\n",
  2443. display->name, skip_op, rc);
  2444. goto error_disable_master;
  2445. }
  2446. }
  2447. return rc;
  2448. error_disable_master:
  2449. (void)dsi_ctrl_set_host_engine_state(m_ctrl->ctrl,
  2450. DSI_CTRL_ENGINE_OFF, skip_op);
  2451. error:
  2452. return rc;
  2453. }
  2454. static int dsi_display_ctrl_host_disable(struct dsi_display *display)
  2455. {
  2456. int rc = 0;
  2457. int i;
  2458. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2459. bool skip_op = is_skip_op_required(display);
  2460. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2461. /*
  2462. * For platforms where ULPS is controlled by DSI controller block,
  2463. * do not disable dsi controller block if lanes are to be
  2464. * kept in ULPS during suspend. So just update the SW state
  2465. * and return early.
  2466. */
  2467. if (display->panel->ulps_suspend_enabled &&
  2468. !m_ctrl->phy->hw.ops.ulps_ops.ulps_request) {
  2469. display_for_each_ctrl(i, display) {
  2470. ctrl = &display->ctrl[i];
  2471. rc = dsi_ctrl_update_host_state(ctrl->ctrl,
  2472. DSI_CTRL_OP_HOST_ENGINE,
  2473. false);
  2474. if (rc)
  2475. DSI_DEBUG("host state update failed %d\n", rc);
  2476. }
  2477. return rc;
  2478. }
  2479. display_for_each_ctrl(i, display) {
  2480. ctrl = &display->ctrl[i];
  2481. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2482. continue;
  2483. rc = dsi_ctrl_set_host_engine_state(ctrl->ctrl,
  2484. DSI_CTRL_ENGINE_OFF, skip_op);
  2485. if (rc)
  2486. DSI_ERR(
  2487. "[%s] disable host engine failed, skip_op:%d rc:%d\n",
  2488. display->name, skip_op, rc);
  2489. }
  2490. rc = dsi_ctrl_set_host_engine_state(m_ctrl->ctrl,
  2491. DSI_CTRL_ENGINE_OFF, skip_op);
  2492. if (rc) {
  2493. DSI_ERR("[%s] disable mhost engine failed, skip_op:%d rc:%d\n",
  2494. display->name, skip_op, rc);
  2495. goto error;
  2496. }
  2497. error:
  2498. return rc;
  2499. }
  2500. static int dsi_display_vid_engine_enable(struct dsi_display *display)
  2501. {
  2502. int rc = 0;
  2503. int i;
  2504. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2505. bool skip_op = is_skip_op_required(display);
  2506. m_ctrl = &display->ctrl[display->video_master_idx];
  2507. rc = dsi_ctrl_set_vid_engine_state(m_ctrl->ctrl,
  2508. DSI_CTRL_ENGINE_ON, skip_op);
  2509. if (rc) {
  2510. DSI_ERR("[%s] enable mvid engine failed, skip_op:%d rc:%d\n",
  2511. display->name, skip_op, rc);
  2512. goto error;
  2513. }
  2514. display_for_each_ctrl(i, display) {
  2515. ctrl = &display->ctrl[i];
  2516. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2517. continue;
  2518. rc = dsi_ctrl_set_vid_engine_state(ctrl->ctrl,
  2519. DSI_CTRL_ENGINE_ON, skip_op);
  2520. if (rc) {
  2521. DSI_ERR(
  2522. "[%s] enable vid engine failed, skip_op:%d rc:%d\n",
  2523. display->name, skip_op, rc);
  2524. goto error_disable_master;
  2525. }
  2526. }
  2527. return rc;
  2528. error_disable_master:
  2529. (void)dsi_ctrl_set_vid_engine_state(m_ctrl->ctrl,
  2530. DSI_CTRL_ENGINE_OFF, skip_op);
  2531. error:
  2532. return rc;
  2533. }
  2534. static int dsi_display_vid_engine_disable(struct dsi_display *display)
  2535. {
  2536. int rc = 0;
  2537. int i;
  2538. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2539. bool skip_op = is_skip_op_required(display);
  2540. m_ctrl = &display->ctrl[display->video_master_idx];
  2541. display_for_each_ctrl(i, display) {
  2542. ctrl = &display->ctrl[i];
  2543. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2544. continue;
  2545. rc = dsi_ctrl_set_vid_engine_state(ctrl->ctrl,
  2546. DSI_CTRL_ENGINE_OFF, skip_op);
  2547. if (rc)
  2548. DSI_ERR(
  2549. "[%s] disable vid engine failed, skip_op:%d rc:%d\n",
  2550. display->name, skip_op, rc);
  2551. }
  2552. rc = dsi_ctrl_set_vid_engine_state(m_ctrl->ctrl,
  2553. DSI_CTRL_ENGINE_OFF, skip_op);
  2554. if (rc)
  2555. DSI_ERR("[%s] disable mvid engine failed, skip_op:%d rc:%d\n",
  2556. display->name, skip_op, rc);
  2557. return rc;
  2558. }
  2559. static int dsi_display_phy_enable(struct dsi_display *display)
  2560. {
  2561. int rc = 0;
  2562. int i;
  2563. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2564. enum dsi_phy_pll_source m_src = DSI_PLL_SOURCE_STANDALONE;
  2565. bool skip_op = is_skip_op_required(display);
  2566. m_ctrl = &display->ctrl[display->clk_master_idx];
  2567. if (display->ctrl_count > 1)
  2568. m_src = DSI_PLL_SOURCE_NATIVE;
  2569. rc = dsi_phy_enable(m_ctrl->phy, &display->config,
  2570. m_src, true, skip_op);
  2571. if (rc) {
  2572. DSI_ERR("[%s] failed to enable DSI PHY, skip_op=%d rc=%d\n",
  2573. display->name, skip_op, rc);
  2574. goto error;
  2575. }
  2576. display_for_each_ctrl(i, display) {
  2577. ctrl = &display->ctrl[i];
  2578. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2579. continue;
  2580. rc = dsi_phy_enable(ctrl->phy, &display->config,
  2581. DSI_PLL_SOURCE_NON_NATIVE, true, skip_op);
  2582. if (rc) {
  2583. DSI_ERR(
  2584. "[%s] failed to enable DSI PHY, skip_op: %d rc=%d\n",
  2585. display->name, skip_op, rc);
  2586. goto error_disable_master;
  2587. }
  2588. }
  2589. return rc;
  2590. error_disable_master:
  2591. (void)dsi_phy_disable(m_ctrl->phy, skip_op);
  2592. error:
  2593. return rc;
  2594. }
  2595. static int dsi_display_phy_disable(struct dsi_display *display)
  2596. {
  2597. int rc = 0;
  2598. int i;
  2599. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2600. bool skip_op = is_skip_op_required(display);
  2601. m_ctrl = &display->ctrl[display->clk_master_idx];
  2602. display_for_each_ctrl(i, display) {
  2603. ctrl = &display->ctrl[i];
  2604. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2605. continue;
  2606. rc = dsi_phy_disable(ctrl->phy, skip_op);
  2607. if (rc)
  2608. DSI_ERR(
  2609. "[%s] failed to disable DSI PHY, skip_op=%d rc=%d\n",
  2610. display->name, skip_op, rc);
  2611. }
  2612. rc = dsi_phy_disable(m_ctrl->phy, skip_op);
  2613. if (rc)
  2614. DSI_ERR("[%s] failed to disable DSI PHY, skip_op=%d rc=%d\n",
  2615. display->name, skip_op, rc);
  2616. return rc;
  2617. }
  2618. static int dsi_display_wake_up(struct dsi_display *display)
  2619. {
  2620. return 0;
  2621. }
  2622. static void dsi_display_mask_overflow(struct dsi_display *display, u32 flags,
  2623. bool enable)
  2624. {
  2625. struct dsi_display_ctrl *ctrl;
  2626. int i;
  2627. if (!(flags & DSI_CTRL_CMD_LAST_COMMAND))
  2628. return;
  2629. display_for_each_ctrl(i, display) {
  2630. ctrl = &display->ctrl[i];
  2631. if (!ctrl)
  2632. continue;
  2633. dsi_ctrl_mask_overflow(ctrl->ctrl, enable);
  2634. }
  2635. }
  2636. static int dsi_display_broadcast_cmd(struct dsi_display *display, struct dsi_cmd_desc *cmd)
  2637. {
  2638. int rc = 0;
  2639. struct dsi_display_ctrl *ctrl, *m_ctrl;
  2640. int i;
  2641. /*
  2642. * 1. Setup commands in FIFO
  2643. * 2. Trigger commands
  2644. */
  2645. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2646. dsi_display_mask_overflow(display, cmd->ctrl_flags, true);
  2647. cmd->ctrl_flags |= DSI_CTRL_CMD_BROADCAST_MASTER;
  2648. rc = dsi_ctrl_cmd_transfer(m_ctrl->ctrl, cmd);
  2649. if (rc) {
  2650. DSI_ERR("[%s] cmd transfer failed on master,rc=%d\n",
  2651. display->name, rc);
  2652. goto error;
  2653. }
  2654. cmd->ctrl_flags &= ~DSI_CTRL_CMD_BROADCAST_MASTER;
  2655. display_for_each_ctrl(i, display) {
  2656. ctrl = &display->ctrl[i];
  2657. if (ctrl == m_ctrl)
  2658. continue;
  2659. rc = dsi_ctrl_cmd_transfer(ctrl->ctrl, cmd);
  2660. if (rc) {
  2661. DSI_ERR("[%s] cmd transfer failed, rc=%d\n",
  2662. display->name, rc);
  2663. goto error;
  2664. }
  2665. rc = dsi_ctrl_cmd_tx_trigger(ctrl->ctrl, cmd->ctrl_flags);
  2666. if (rc) {
  2667. DSI_ERR("[%s] cmd trigger failed, rc=%d\n",
  2668. display->name, rc);
  2669. goto error;
  2670. }
  2671. }
  2672. rc = dsi_ctrl_cmd_tx_trigger(m_ctrl->ctrl, cmd->ctrl_flags | DSI_CTRL_CMD_BROADCAST_MASTER);
  2673. if (rc) {
  2674. DSI_ERR("[%s] cmd trigger failed for master, rc=%d\n",
  2675. display->name, rc);
  2676. goto error;
  2677. }
  2678. error:
  2679. dsi_display_mask_overflow(display, cmd->ctrl_flags, false);
  2680. return rc;
  2681. }
  2682. static int dsi_display_phy_sw_reset(struct dsi_display *display)
  2683. {
  2684. int rc = 0;
  2685. int i;
  2686. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2687. /*
  2688. * For continuous splash and trusted vm environment,
  2689. * ctrl states are updated separately and hence we do
  2690. * an early return
  2691. */
  2692. if (is_skip_op_required(display)) {
  2693. DSI_DEBUG(
  2694. "cont splash/trusted vm use case, phy sw reset not required\n");
  2695. return 0;
  2696. }
  2697. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2698. rc = dsi_ctrl_phy_sw_reset(m_ctrl->ctrl);
  2699. if (rc) {
  2700. DSI_ERR("[%s] failed to reset phy, rc=%d\n", display->name, rc);
  2701. goto error;
  2702. }
  2703. display_for_each_ctrl(i, display) {
  2704. ctrl = &display->ctrl[i];
  2705. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2706. continue;
  2707. rc = dsi_ctrl_phy_sw_reset(ctrl->ctrl);
  2708. if (rc) {
  2709. DSI_ERR("[%s] failed to reset phy, rc=%d\n",
  2710. display->name, rc);
  2711. goto error;
  2712. }
  2713. }
  2714. error:
  2715. return rc;
  2716. }
  2717. static int dsi_host_attach(struct mipi_dsi_host *host,
  2718. struct mipi_dsi_device *dsi)
  2719. {
  2720. return 0;
  2721. }
  2722. static int dsi_host_detach(struct mipi_dsi_host *host,
  2723. struct mipi_dsi_device *dsi)
  2724. {
  2725. return 0;
  2726. }
  2727. int dsi_host_transfer_sub(struct mipi_dsi_host *host, struct dsi_cmd_desc *cmd)
  2728. {
  2729. struct dsi_display *display;
  2730. int rc = 0, ret = 0;
  2731. if (!host || !cmd) {
  2732. DSI_ERR("Invalid params\n");
  2733. return 0;
  2734. }
  2735. display = to_dsi_display(host);
  2736. /* Avoid sending DCS commands when ESD recovery is pending */
  2737. if (atomic_read(&display->panel->esd_recovery_pending)) {
  2738. DSI_DEBUG("ESD recovery pending\n");
  2739. return 0;
  2740. }
  2741. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  2742. DSI_ALL_CLKS, DSI_CLK_ON);
  2743. if (rc) {
  2744. DSI_ERR("[%s] failed to enable all DSI clocks, rc=%d\n",
  2745. display->name, rc);
  2746. goto error;
  2747. }
  2748. rc = dsi_display_wake_up(display);
  2749. if (rc) {
  2750. DSI_ERR("[%s] failed to wake up display, rc=%d\n",
  2751. display->name, rc);
  2752. goto error_disable_clks;
  2753. }
  2754. rc = dsi_display_cmd_engine_enable(display);
  2755. if (rc) {
  2756. DSI_ERR("[%s] failed to enable cmd engine, rc=%d\n",
  2757. display->name, rc);
  2758. goto error_disable_clks;
  2759. }
  2760. if (display->tx_cmd_buf == NULL) {
  2761. rc = dsi_host_alloc_cmd_tx_buffer(display);
  2762. if (rc) {
  2763. DSI_ERR("failed to allocate cmd tx buffer memory\n");
  2764. goto error_disable_cmd_engine;
  2765. }
  2766. }
  2767. dsi_display_set_cmd_tx_ctrl_flags(display, cmd);
  2768. if (cmd->ctrl_flags & DSI_CTRL_CMD_BROADCAST) {
  2769. rc = dsi_display_broadcast_cmd(display, cmd);
  2770. if (rc) {
  2771. DSI_ERR("[%s] cmd broadcast failed, rc=%d\n", display->name, rc);
  2772. goto error_disable_cmd_engine;
  2773. }
  2774. } else {
  2775. int idx = cmd->ctrl;
  2776. rc = dsi_ctrl_cmd_transfer(display->ctrl[idx].ctrl, cmd);
  2777. if (rc) {
  2778. DSI_ERR("[%s] cmd transfer failed, rc=%d\n",
  2779. display->name, rc);
  2780. goto error_disable_cmd_engine;
  2781. }
  2782. }
  2783. error_disable_cmd_engine:
  2784. ret = dsi_display_cmd_engine_disable(display);
  2785. if (ret) {
  2786. DSI_ERR("[%s]failed to disable DSI cmd engine, rc=%d\n",
  2787. display->name, ret);
  2788. }
  2789. error_disable_clks:
  2790. ret = dsi_display_clk_ctrl(display->dsi_clk_handle,
  2791. DSI_ALL_CLKS, DSI_CLK_OFF);
  2792. if (ret) {
  2793. DSI_ERR("[%s] failed to disable all DSI clocks, rc=%d\n",
  2794. display->name, ret);
  2795. }
  2796. error:
  2797. return rc;
  2798. }
  2799. static ssize_t dsi_host_transfer(struct mipi_dsi_host *host, const struct mipi_dsi_msg *msg)
  2800. {
  2801. int rc = 0;
  2802. struct dsi_cmd_desc cmd;
  2803. if (!msg) {
  2804. DSI_ERR("Invalid params\n");
  2805. return 0;
  2806. }
  2807. memcpy(&cmd.msg, msg, sizeof(*msg));
  2808. cmd.ctrl = 0;
  2809. cmd.post_wait_ms = 0;
  2810. cmd.ctrl_flags = 0;
  2811. rc = dsi_host_transfer_sub(host, &cmd);
  2812. return rc;
  2813. }
  2814. static struct mipi_dsi_host_ops dsi_host_ops = {
  2815. .attach = dsi_host_attach,
  2816. .detach = dsi_host_detach,
  2817. .transfer = dsi_host_transfer,
  2818. };
  2819. static int dsi_display_mipi_host_init(struct dsi_display *display)
  2820. {
  2821. int rc = 0;
  2822. struct mipi_dsi_host *host = &display->host;
  2823. host->dev = &display->pdev->dev;
  2824. host->ops = &dsi_host_ops;
  2825. rc = mipi_dsi_host_register(host);
  2826. if (rc) {
  2827. DSI_ERR("[%s] failed to register mipi dsi host, rc=%d\n",
  2828. display->name, rc);
  2829. goto error;
  2830. }
  2831. error:
  2832. return rc;
  2833. }
  2834. static int dsi_display_mipi_host_deinit(struct dsi_display *display)
  2835. {
  2836. int rc = 0;
  2837. struct mipi_dsi_host *host = &display->host;
  2838. mipi_dsi_host_unregister(host);
  2839. host->dev = NULL;
  2840. host->ops = NULL;
  2841. return rc;
  2842. }
  2843. static bool dsi_display_check_prefix(const char *clk_prefix,
  2844. const char *clk_name)
  2845. {
  2846. return !!strnstr(clk_name, clk_prefix, strlen(clk_name));
  2847. }
  2848. static int dsi_display_get_clocks_count(struct dsi_display *display,
  2849. char *dsi_clk_name)
  2850. {
  2851. if (display->fw)
  2852. return dsi_parser_count_strings(display->parser_node,
  2853. dsi_clk_name);
  2854. else
  2855. return of_property_count_strings(display->panel_node,
  2856. dsi_clk_name);
  2857. }
  2858. static void dsi_display_get_clock_name(struct dsi_display *display,
  2859. char *dsi_clk_name, int index,
  2860. const char **clk_name)
  2861. {
  2862. if (display->fw)
  2863. dsi_parser_read_string_index(display->parser_node,
  2864. dsi_clk_name, index, clk_name);
  2865. else
  2866. of_property_read_string_index(display->panel_node,
  2867. dsi_clk_name, index, clk_name);
  2868. }
  2869. static int dsi_display_clocks_init(struct dsi_display *display)
  2870. {
  2871. int i, rc = 0, num_clk = 0;
  2872. const char *clk_name;
  2873. const char *pll_byte = "pll_byte", *pll_dsi = "pll_dsi";
  2874. struct clk *dsi_clk;
  2875. struct dsi_clk_link_set *pll = &display->clock_info.pll_clks;
  2876. char *dsi_clock_name;
  2877. if (!strcmp(display->display_type, "primary"))
  2878. dsi_clock_name = "qcom,dsi-select-clocks";
  2879. else
  2880. dsi_clock_name = "qcom,dsi-select-sec-clocks";
  2881. num_clk = dsi_display_get_clocks_count(display, dsi_clock_name);
  2882. for (i = 0; i < num_clk; i++) {
  2883. dsi_display_get_clock_name(display, dsi_clock_name, i,
  2884. &clk_name);
  2885. DSI_DEBUG("clock name:%s\n", clk_name);
  2886. dsi_clk = devm_clk_get(&display->pdev->dev, clk_name);
  2887. if (IS_ERR_OR_NULL(dsi_clk)) {
  2888. rc = PTR_ERR(dsi_clk);
  2889. DSI_ERR("failed to get %s, rc=%d\n", clk_name, rc);
  2890. if (dsi_display_check_prefix(pll_byte, clk_name)) {
  2891. pll->byte_clk = NULL;
  2892. goto error;
  2893. }
  2894. if (dsi_display_check_prefix(pll_dsi, clk_name)) {
  2895. pll->pixel_clk = NULL;
  2896. goto error;
  2897. }
  2898. }
  2899. if (dsi_display_check_prefix(pll_byte, clk_name)) {
  2900. pll->byte_clk = dsi_clk;
  2901. continue;
  2902. }
  2903. if (dsi_display_check_prefix(pll_dsi, clk_name)) {
  2904. pll->pixel_clk = dsi_clk;
  2905. continue;
  2906. }
  2907. }
  2908. return 0;
  2909. error:
  2910. return rc;
  2911. }
  2912. static int dsi_display_clk_ctrl_cb(void *priv,
  2913. struct dsi_clk_ctrl_info clk_state_info)
  2914. {
  2915. int rc = 0;
  2916. struct dsi_display *display = NULL;
  2917. void *clk_handle = NULL;
  2918. if (!priv) {
  2919. DSI_ERR("Invalid params\n");
  2920. return -EINVAL;
  2921. }
  2922. display = priv;
  2923. if (clk_state_info.client == DSI_CLK_REQ_MDP_CLIENT) {
  2924. clk_handle = display->mdp_clk_handle;
  2925. } else if (clk_state_info.client == DSI_CLK_REQ_DSI_CLIENT) {
  2926. clk_handle = display->dsi_clk_handle;
  2927. } else {
  2928. DSI_ERR("invalid clk handle, return error\n");
  2929. return -EINVAL;
  2930. }
  2931. /*
  2932. * TODO: Wait for CMD_MDP_DONE interrupt if MDP client tries
  2933. * to turn off DSI clocks.
  2934. */
  2935. rc = dsi_display_clk_ctrl(clk_handle,
  2936. clk_state_info.clk_type, clk_state_info.clk_state);
  2937. if (rc) {
  2938. DSI_ERR("[%s] failed to %d DSI %d clocks, rc=%d\n",
  2939. display->name, clk_state_info.clk_state,
  2940. clk_state_info.clk_type, rc);
  2941. return rc;
  2942. }
  2943. return 0;
  2944. }
  2945. static void dsi_display_ctrl_isr_configure(struct dsi_display *display, bool en)
  2946. {
  2947. int i;
  2948. struct dsi_display_ctrl *ctrl;
  2949. if (!display)
  2950. return;
  2951. display_for_each_ctrl(i, display) {
  2952. ctrl = &display->ctrl[i];
  2953. if (!ctrl)
  2954. continue;
  2955. dsi_ctrl_isr_configure(ctrl->ctrl, en);
  2956. }
  2957. }
  2958. int dsi_pre_clkoff_cb(void *priv,
  2959. enum dsi_clk_type clk,
  2960. enum dsi_lclk_type l_type,
  2961. enum dsi_clk_state new_state)
  2962. {
  2963. int rc = 0, i;
  2964. struct dsi_display *display = priv;
  2965. struct dsi_display_ctrl *ctrl;
  2966. /*
  2967. * If Idle Power Collapse occurs immediately after a CMD
  2968. * transfer with an asynchronous wait for DMA done, ensure
  2969. * that the work queued is scheduled and completed before turning
  2970. * off the clocks and disabling interrupts to validate the command
  2971. * transfer.
  2972. */
  2973. display_for_each_ctrl(i, display) {
  2974. ctrl = &display->ctrl[i];
  2975. if (!ctrl->ctrl || !ctrl->ctrl->dma_wait_queued)
  2976. continue;
  2977. flush_workqueue(display->dma_cmd_workq);
  2978. cancel_work_sync(&ctrl->ctrl->dma_cmd_wait);
  2979. ctrl->ctrl->dma_wait_queued = false;
  2980. }
  2981. if ((clk & DSI_LINK_CLK) && (new_state == DSI_CLK_OFF) &&
  2982. (l_type & DSI_LINK_LP_CLK)) {
  2983. /*
  2984. * If continuous clock is enabled then disable it
  2985. * before entering into ULPS Mode.
  2986. */
  2987. if (display->panel->host_config.force_hs_clk_lane)
  2988. _dsi_display_continuous_clk_ctrl(display, false);
  2989. /*
  2990. * If ULPS feature is enabled, enter ULPS first.
  2991. * However, when blanking the panel, we should enter ULPS
  2992. * only if ULPS during suspend feature is enabled.
  2993. */
  2994. if (!dsi_panel_initialized(display->panel)) {
  2995. if (display->panel->ulps_suspend_enabled)
  2996. rc = dsi_display_set_ulps(display, true);
  2997. } else if (dsi_panel_ulps_feature_enabled(display->panel)) {
  2998. rc = dsi_display_set_ulps(display, true);
  2999. }
  3000. if (rc)
  3001. DSI_ERR("%s: failed enable ulps, rc = %d\n",
  3002. __func__, rc);
  3003. }
  3004. if ((clk & DSI_LINK_CLK) && (new_state == DSI_CLK_OFF) &&
  3005. (l_type & DSI_LINK_HS_CLK)) {
  3006. /*
  3007. * PHY clock gating should be disabled before the PLL and the
  3008. * branch clocks are turned off. Otherwise, it is possible that
  3009. * the clock RCGs may not be turned off correctly resulting
  3010. * in clock warnings.
  3011. */
  3012. rc = dsi_display_config_clk_gating(display, false);
  3013. if (rc)
  3014. DSI_ERR("[%s] failed to disable clk gating, rc=%d\n",
  3015. display->name, rc);
  3016. }
  3017. if ((clk & DSI_CORE_CLK) && (new_state == DSI_CLK_OFF)) {
  3018. /*
  3019. * Enable DSI clamps only if entering idle power collapse or
  3020. * when ULPS during suspend is enabled..
  3021. */
  3022. if (dsi_panel_initialized(display->panel) ||
  3023. display->panel->ulps_suspend_enabled) {
  3024. dsi_display_phy_idle_off(display);
  3025. rc = dsi_display_set_clamp(display, true);
  3026. if (rc)
  3027. DSI_ERR("%s: Failed to enable dsi clamps. rc=%d\n",
  3028. __func__, rc);
  3029. rc = dsi_display_phy_reset_config(display, false);
  3030. if (rc)
  3031. DSI_ERR("%s: Failed to reset phy, rc=%d\n",
  3032. __func__, rc);
  3033. } else {
  3034. /* Make sure that controller is not in ULPS state when
  3035. * the DSI link is not active.
  3036. */
  3037. rc = dsi_display_set_ulps(display, false);
  3038. if (rc)
  3039. DSI_ERR("%s: failed to disable ulps. rc=%d\n",
  3040. __func__, rc);
  3041. }
  3042. /* dsi will not be able to serve irqs from here on */
  3043. dsi_display_ctrl_irq_update(display, false);
  3044. /* cache the MISR values */
  3045. display_for_each_ctrl(i, display) {
  3046. ctrl = &display->ctrl[i];
  3047. if (!ctrl->ctrl)
  3048. continue;
  3049. dsi_ctrl_cache_misr(ctrl->ctrl);
  3050. }
  3051. }
  3052. return rc;
  3053. }
  3054. int dsi_post_clkon_cb(void *priv,
  3055. enum dsi_clk_type clk,
  3056. enum dsi_lclk_type l_type,
  3057. enum dsi_clk_state curr_state)
  3058. {
  3059. int rc = 0;
  3060. struct dsi_display *display = priv;
  3061. bool mmss_clamp = false;
  3062. if ((clk & DSI_LINK_CLK) && (l_type & DSI_LINK_LP_CLK)) {
  3063. mmss_clamp = display->clamp_enabled;
  3064. /*
  3065. * controller setup is needed if coming out of idle
  3066. * power collapse with clamps enabled.
  3067. */
  3068. if (mmss_clamp)
  3069. dsi_display_ctrl_setup(display);
  3070. /*
  3071. * Phy setup is needed if coming out of idle
  3072. * power collapse with clamps enabled.
  3073. */
  3074. if (display->phy_idle_power_off || mmss_clamp)
  3075. dsi_display_phy_idle_on(display, mmss_clamp);
  3076. if (display->ulps_enabled && mmss_clamp) {
  3077. /*
  3078. * ULPS Entry Request. This is needed if the lanes were
  3079. * in ULPS prior to power collapse, since after
  3080. * power collapse and reset, the DSI controller resets
  3081. * back to idle state and not ULPS. This ulps entry
  3082. * request will transition the state of the DSI
  3083. * controller to ULPS which will match the state of the
  3084. * DSI phy. This needs to be done prior to disabling
  3085. * the DSI clamps.
  3086. *
  3087. * Also, reset the ulps flag so that ulps_config
  3088. * function would reconfigure the controller state to
  3089. * ULPS.
  3090. */
  3091. display->ulps_enabled = false;
  3092. rc = dsi_display_set_ulps(display, true);
  3093. if (rc) {
  3094. DSI_ERR("%s: Failed to enter ULPS. rc=%d\n",
  3095. __func__, rc);
  3096. goto error;
  3097. }
  3098. }
  3099. rc = dsi_display_phy_reset_config(display, true);
  3100. if (rc) {
  3101. DSI_ERR("%s: Failed to reset phy, rc=%d\n",
  3102. __func__, rc);
  3103. goto error;
  3104. }
  3105. rc = dsi_display_set_clamp(display, false);
  3106. if (rc) {
  3107. DSI_ERR("%s: Failed to disable dsi clamps. rc=%d\n",
  3108. __func__, rc);
  3109. goto error;
  3110. }
  3111. }
  3112. if ((clk & DSI_LINK_CLK) && (l_type & DSI_LINK_HS_CLK)) {
  3113. /*
  3114. * Toggle the resync FIFO everytime clock changes, except
  3115. * when cont-splash screen transition is going on.
  3116. * Toggling resync FIFO during cont splash transition
  3117. * can lead to blinks on the display.
  3118. */
  3119. if (!display->is_cont_splash_enabled)
  3120. dsi_display_toggle_resync_fifo(display);
  3121. if (display->ulps_enabled) {
  3122. rc = dsi_display_set_ulps(display, false);
  3123. if (rc) {
  3124. DSI_ERR("%s: failed to disable ulps, rc= %d\n",
  3125. __func__, rc);
  3126. goto error;
  3127. }
  3128. }
  3129. if (display->panel->host_config.force_hs_clk_lane)
  3130. _dsi_display_continuous_clk_ctrl(display, true);
  3131. rc = dsi_display_config_clk_gating(display, true);
  3132. if (rc) {
  3133. DSI_ERR("[%s] failed to enable clk gating %d\n",
  3134. display->name, rc);
  3135. goto error;
  3136. }
  3137. }
  3138. /* enable dsi to serve irqs */
  3139. if (clk & DSI_CORE_CLK)
  3140. dsi_display_ctrl_irq_update(display, true);
  3141. error:
  3142. return rc;
  3143. }
  3144. int dsi_post_clkoff_cb(void *priv,
  3145. enum dsi_clk_type clk_type,
  3146. enum dsi_lclk_type l_type,
  3147. enum dsi_clk_state curr_state)
  3148. {
  3149. int rc = 0;
  3150. struct dsi_display *display = priv;
  3151. if (!display) {
  3152. DSI_ERR("%s: Invalid arg\n", __func__);
  3153. return -EINVAL;
  3154. }
  3155. if ((clk_type & DSI_CORE_CLK) &&
  3156. (curr_state == DSI_CLK_OFF)) {
  3157. rc = dsi_display_phy_power_off(display);
  3158. if (rc)
  3159. DSI_ERR("[%s] failed to power off PHY, rc=%d\n",
  3160. display->name, rc);
  3161. rc = dsi_display_ctrl_power_off(display);
  3162. if (rc)
  3163. DSI_ERR("[%s] failed to power DSI vregs, rc=%d\n",
  3164. display->name, rc);
  3165. }
  3166. return rc;
  3167. }
  3168. int dsi_pre_clkon_cb(void *priv,
  3169. enum dsi_clk_type clk_type,
  3170. enum dsi_lclk_type l_type,
  3171. enum dsi_clk_state new_state)
  3172. {
  3173. int rc = 0;
  3174. struct dsi_display *display = priv;
  3175. if (!display) {
  3176. DSI_ERR("%s: invalid input\n", __func__);
  3177. return -EINVAL;
  3178. }
  3179. if ((clk_type & DSI_CORE_CLK) && (new_state == DSI_CLK_ON)) {
  3180. /*
  3181. * Enable DSI core power
  3182. * 1.> PANEL_PM are controlled as part of
  3183. * panel_power_ctrl. Needed not be handled here.
  3184. * 2.> CTRL_PM need to be enabled/disabled
  3185. * only during unblank/blank. Their state should
  3186. * not be changed during static screen.
  3187. */
  3188. DSI_DEBUG("updating power states for ctrl and phy\n");
  3189. rc = dsi_display_ctrl_power_on(display);
  3190. if (rc) {
  3191. DSI_ERR("[%s] failed to power on dsi controllers, rc=%d\n",
  3192. display->name, rc);
  3193. return rc;
  3194. }
  3195. rc = dsi_display_phy_power_on(display);
  3196. if (rc) {
  3197. DSI_ERR("[%s] failed to power on dsi phy, rc = %d\n",
  3198. display->name, rc);
  3199. return rc;
  3200. }
  3201. DSI_DEBUG("%s: Enable DSI core power\n", __func__);
  3202. }
  3203. return rc;
  3204. }
  3205. static void __set_lane_map_v2(u8 *lane_map_v2,
  3206. enum dsi_phy_data_lanes lane0,
  3207. enum dsi_phy_data_lanes lane1,
  3208. enum dsi_phy_data_lanes lane2,
  3209. enum dsi_phy_data_lanes lane3)
  3210. {
  3211. lane_map_v2[DSI_LOGICAL_LANE_0] = lane0;
  3212. lane_map_v2[DSI_LOGICAL_LANE_1] = lane1;
  3213. lane_map_v2[DSI_LOGICAL_LANE_2] = lane2;
  3214. lane_map_v2[DSI_LOGICAL_LANE_3] = lane3;
  3215. }
  3216. static int dsi_display_parse_lane_map(struct dsi_display *display)
  3217. {
  3218. int rc = 0, i = 0;
  3219. const char *data;
  3220. u8 temp[DSI_LANE_MAX - 1];
  3221. if (!display) {
  3222. DSI_ERR("invalid params\n");
  3223. return -EINVAL;
  3224. }
  3225. /* lane-map-v2 supersedes lane-map-v1 setting */
  3226. rc = of_property_read_u8_array(display->pdev->dev.of_node,
  3227. "qcom,lane-map-v2", temp, (DSI_LANE_MAX - 1));
  3228. if (!rc) {
  3229. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++)
  3230. display->lane_map.lane_map_v2[i] = BIT(temp[i]);
  3231. return 0;
  3232. } else if (rc != EINVAL) {
  3233. DSI_DEBUG("Incorrect mapping, configure default\n");
  3234. goto set_default;
  3235. }
  3236. /* lane-map older version, for DSI controller version < 2.0 */
  3237. data = of_get_property(display->pdev->dev.of_node,
  3238. "qcom,lane-map", NULL);
  3239. if (!data)
  3240. goto set_default;
  3241. if (!strcmp(data, "lane_map_3012")) {
  3242. display->lane_map.lane_map_v1 = DSI_LANE_MAP_3012;
  3243. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3244. DSI_PHYSICAL_LANE_1,
  3245. DSI_PHYSICAL_LANE_2,
  3246. DSI_PHYSICAL_LANE_3,
  3247. DSI_PHYSICAL_LANE_0);
  3248. } else if (!strcmp(data, "lane_map_2301")) {
  3249. display->lane_map.lane_map_v1 = DSI_LANE_MAP_2301;
  3250. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3251. DSI_PHYSICAL_LANE_2,
  3252. DSI_PHYSICAL_LANE_3,
  3253. DSI_PHYSICAL_LANE_0,
  3254. DSI_PHYSICAL_LANE_1);
  3255. } else if (!strcmp(data, "lane_map_1230")) {
  3256. display->lane_map.lane_map_v1 = DSI_LANE_MAP_1230;
  3257. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3258. DSI_PHYSICAL_LANE_3,
  3259. DSI_PHYSICAL_LANE_0,
  3260. DSI_PHYSICAL_LANE_1,
  3261. DSI_PHYSICAL_LANE_2);
  3262. } else if (!strcmp(data, "lane_map_0321")) {
  3263. display->lane_map.lane_map_v1 = DSI_LANE_MAP_0321;
  3264. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3265. DSI_PHYSICAL_LANE_0,
  3266. DSI_PHYSICAL_LANE_3,
  3267. DSI_PHYSICAL_LANE_2,
  3268. DSI_PHYSICAL_LANE_1);
  3269. } else if (!strcmp(data, "lane_map_1032")) {
  3270. display->lane_map.lane_map_v1 = DSI_LANE_MAP_1032;
  3271. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3272. DSI_PHYSICAL_LANE_1,
  3273. DSI_PHYSICAL_LANE_0,
  3274. DSI_PHYSICAL_LANE_3,
  3275. DSI_PHYSICAL_LANE_2);
  3276. } else if (!strcmp(data, "lane_map_2103")) {
  3277. display->lane_map.lane_map_v1 = DSI_LANE_MAP_2103;
  3278. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3279. DSI_PHYSICAL_LANE_2,
  3280. DSI_PHYSICAL_LANE_1,
  3281. DSI_PHYSICAL_LANE_0,
  3282. DSI_PHYSICAL_LANE_3);
  3283. } else if (!strcmp(data, "lane_map_3210")) {
  3284. display->lane_map.lane_map_v1 = DSI_LANE_MAP_3210;
  3285. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3286. DSI_PHYSICAL_LANE_3,
  3287. DSI_PHYSICAL_LANE_2,
  3288. DSI_PHYSICAL_LANE_1,
  3289. DSI_PHYSICAL_LANE_0);
  3290. } else {
  3291. DSI_WARN("%s: invalid lane map %s specified. defaulting to lane_map0123\n",
  3292. __func__, data);
  3293. goto set_default;
  3294. }
  3295. return 0;
  3296. set_default:
  3297. /* default lane mapping */
  3298. __set_lane_map_v2(display->lane_map.lane_map_v2, DSI_PHYSICAL_LANE_0,
  3299. DSI_PHYSICAL_LANE_1, DSI_PHYSICAL_LANE_2, DSI_PHYSICAL_LANE_3);
  3300. display->lane_map.lane_map_v1 = DSI_LANE_MAP_0123;
  3301. return 0;
  3302. }
  3303. static int dsi_display_get_phandle_index(
  3304. struct dsi_display *display,
  3305. const char *propname, int count, int index)
  3306. {
  3307. struct device_node *disp_node = display->panel_node;
  3308. u32 *val = NULL;
  3309. int rc = 0;
  3310. val = kcalloc(count, sizeof(*val), GFP_KERNEL);
  3311. if (ZERO_OR_NULL_PTR(val)) {
  3312. rc = -ENOMEM;
  3313. goto end;
  3314. }
  3315. if (index >= count)
  3316. goto end;
  3317. if (display->fw)
  3318. rc = dsi_parser_read_u32_array(display->parser_node,
  3319. propname, val, count);
  3320. else
  3321. rc = of_property_read_u32_array(disp_node, propname,
  3322. val, count);
  3323. if (rc)
  3324. goto end;
  3325. rc = val[index];
  3326. DSI_DEBUG("%s index=%d\n", propname, rc);
  3327. end:
  3328. kfree(val);
  3329. return rc;
  3330. }
  3331. static int dsi_display_get_phandle_count(struct dsi_display *display,
  3332. const char *propname)
  3333. {
  3334. if (display->fw)
  3335. return dsi_parser_count_u32_elems(display->parser_node,
  3336. propname);
  3337. else
  3338. return of_property_count_u32_elems(display->panel_node,
  3339. propname);
  3340. }
  3341. static int dsi_display_parse_dt(struct dsi_display *display)
  3342. {
  3343. int i, rc = 0;
  3344. u32 phy_count = 0;
  3345. struct device_node *of_node = display->pdev->dev.of_node;
  3346. char *dsi_ctrl_name, *dsi_phy_name;
  3347. if (!strcmp(display->display_type, "primary")) {
  3348. dsi_ctrl_name = "qcom,dsi-ctrl-num";
  3349. dsi_phy_name = "qcom,dsi-phy-num";
  3350. } else {
  3351. dsi_ctrl_name = "qcom,dsi-sec-ctrl-num";
  3352. dsi_phy_name = "qcom,dsi-sec-phy-num";
  3353. }
  3354. display->ctrl_count = dsi_display_get_phandle_count(display,
  3355. dsi_ctrl_name);
  3356. phy_count = dsi_display_get_phandle_count(display, dsi_phy_name);
  3357. DSI_DEBUG("ctrl count=%d, phy count=%d\n",
  3358. display->ctrl_count, phy_count);
  3359. if (!phy_count || !display->ctrl_count) {
  3360. DSI_ERR("no ctrl/phys found\n");
  3361. rc = -ENODEV;
  3362. goto error;
  3363. }
  3364. if (phy_count != display->ctrl_count) {
  3365. DSI_ERR("different ctrl and phy counts\n");
  3366. rc = -ENODEV;
  3367. goto error;
  3368. }
  3369. display_for_each_ctrl(i, display) {
  3370. struct dsi_display_ctrl *ctrl = &display->ctrl[i];
  3371. int index;
  3372. index = dsi_display_get_phandle_index(display, dsi_ctrl_name,
  3373. display->ctrl_count, i);
  3374. ctrl->ctrl_of_node = of_parse_phandle(of_node,
  3375. "qcom,dsi-ctrl", index);
  3376. of_node_put(ctrl->ctrl_of_node);
  3377. index = dsi_display_get_phandle_index(display, dsi_phy_name,
  3378. display->ctrl_count, i);
  3379. ctrl->phy_of_node = of_parse_phandle(of_node,
  3380. "qcom,dsi-phy", index);
  3381. of_node_put(ctrl->phy_of_node);
  3382. }
  3383. /* Parse TE data */
  3384. dsi_display_parse_te_data(display);
  3385. /* Parse all external bridges from port 0 */
  3386. display_for_each_ctrl(i, display) {
  3387. display->ext_bridge[i].node_of =
  3388. of_graph_get_remote_node(of_node, 0, i);
  3389. if (display->ext_bridge[i].node_of)
  3390. display->ext_bridge_cnt++;
  3391. else
  3392. break;
  3393. }
  3394. /* Parse Demura data */
  3395. dsi_display_parse_demura_data(display);
  3396. DSI_DEBUG("success\n");
  3397. error:
  3398. return rc;
  3399. }
  3400. static int dsi_display_validate_resources(struct dsi_display *display)
  3401. {
  3402. int rc = 0;
  3403. int i;
  3404. struct dsi_display_ctrl *ctrl;
  3405. display_for_each_ctrl(i, display) {
  3406. ctrl = &display->ctrl[i];
  3407. ctrl->ctrl = dsi_ctrl_get(ctrl->ctrl_of_node);
  3408. if (IS_ERR_OR_NULL(ctrl->ctrl)) {
  3409. rc = PTR_ERR(ctrl->ctrl);
  3410. DSI_ERR("failed to get dsi controller, rc=%d\n", rc);
  3411. ctrl->ctrl = NULL;
  3412. goto error;
  3413. }
  3414. ctrl->phy = dsi_phy_get(ctrl->phy_of_node);
  3415. if (IS_ERR_OR_NULL(ctrl->phy)) {
  3416. rc = PTR_ERR(ctrl->phy);
  3417. DSI_ERR("failed to get phy controller, rc=%d\n", rc);
  3418. dsi_ctrl_put(ctrl->ctrl);
  3419. ctrl->phy = NULL;
  3420. goto error;
  3421. }
  3422. }
  3423. return rc;
  3424. error:
  3425. for (i = i - 1; i >= 0; i--) {
  3426. ctrl = &display->ctrl[i];
  3427. dsi_ctrl_put(ctrl->ctrl);
  3428. dsi_phy_put(ctrl->phy);
  3429. }
  3430. return -EPROBE_DEFER;
  3431. }
  3432. static int dsi_display_res_init(struct dsi_display *display)
  3433. {
  3434. int rc = 0;
  3435. int i;
  3436. display->panel = dsi_panel_get(&display->pdev->dev,
  3437. display->panel_node,
  3438. display->parser_node,
  3439. display->display_type,
  3440. display->cmdline_topology,
  3441. display->trusted_vm_env);
  3442. if (IS_ERR_OR_NULL(display->panel)) {
  3443. rc = PTR_ERR(display->panel);
  3444. DSI_ERR("failed to get panel, rc=%d\n", rc);
  3445. display->panel = NULL;
  3446. goto error;
  3447. }
  3448. display_for_each_ctrl(i, display) {
  3449. struct msm_dsi_phy *phy = display->ctrl[i].phy;
  3450. phy->cfg.force_clk_lane_hs =
  3451. display->panel->host_config.force_hs_clk_lane;
  3452. phy->cfg.phy_type =
  3453. display->panel->host_config.phy_type;
  3454. /*
  3455. * Parse the dynamic clock trim codes for PLL, for video mode panels that have
  3456. * dynamic clock property set.
  3457. */
  3458. if ((display->panel->dyn_clk_caps.dyn_clk_support) &&
  3459. (display->panel->panel_mode == DSI_OP_VIDEO_MODE))
  3460. dsi_phy_pll_parse_dfps_data(phy);
  3461. }
  3462. rc = dsi_display_parse_lane_map(display);
  3463. if (rc) {
  3464. DSI_ERR("Lane map not found, rc=%d\n", rc);
  3465. goto error;
  3466. }
  3467. rc = dsi_display_clocks_init(display);
  3468. if (rc) {
  3469. DSI_ERR("Failed to parse clock data, rc=%d\n", rc);
  3470. goto error;
  3471. }
  3472. /**
  3473. * In trusted vm, the connectors will not be enabled
  3474. * until the HW resources are assigned and accepted.
  3475. */
  3476. if (display->trusted_vm_env)
  3477. display->is_active = false;
  3478. else
  3479. display->is_active = true;
  3480. error:
  3481. return rc;
  3482. }
  3483. static int dsi_display_res_deinit(struct dsi_display *display)
  3484. {
  3485. int rc = 0;
  3486. int i;
  3487. struct dsi_display_ctrl *ctrl;
  3488. display_for_each_ctrl(i, display) {
  3489. ctrl = &display->ctrl[i];
  3490. dsi_phy_put(ctrl->phy);
  3491. dsi_ctrl_put(ctrl->ctrl);
  3492. }
  3493. if (display->panel)
  3494. dsi_panel_put(display->panel);
  3495. return rc;
  3496. }
  3497. static int dsi_display_validate_mode_set(struct dsi_display *display,
  3498. struct dsi_display_mode *mode,
  3499. u32 flags)
  3500. {
  3501. int rc = 0;
  3502. int i;
  3503. struct dsi_display_ctrl *ctrl;
  3504. /*
  3505. * To set a mode:
  3506. * 1. Controllers should be turned off.
  3507. * 2. Link clocks should be off.
  3508. * 3. Phy should be disabled.
  3509. */
  3510. display_for_each_ctrl(i, display) {
  3511. ctrl = &display->ctrl[i];
  3512. if ((ctrl->power_state > DSI_CTRL_POWER_VREG_ON) ||
  3513. (ctrl->phy_enabled)) {
  3514. rc = -EINVAL;
  3515. goto error;
  3516. }
  3517. }
  3518. error:
  3519. return rc;
  3520. }
  3521. static bool dsi_display_is_seamless_dfps_possible(
  3522. const struct dsi_display *display,
  3523. const struct dsi_display_mode *tgt,
  3524. const enum dsi_dfps_type dfps_type)
  3525. {
  3526. struct dsi_display_mode *cur;
  3527. if (!display || !tgt || !display->panel) {
  3528. DSI_ERR("Invalid params\n");
  3529. return false;
  3530. }
  3531. cur = display->panel->cur_mode;
  3532. if (cur->timing.h_active != tgt->timing.h_active) {
  3533. DSI_DEBUG("timing.h_active differs %d %d\n",
  3534. cur->timing.h_active, tgt->timing.h_active);
  3535. return false;
  3536. }
  3537. if (cur->timing.h_back_porch != tgt->timing.h_back_porch) {
  3538. DSI_DEBUG("timing.h_back_porch differs %d %d\n",
  3539. cur->timing.h_back_porch,
  3540. tgt->timing.h_back_porch);
  3541. return false;
  3542. }
  3543. if (cur->timing.h_sync_width != tgt->timing.h_sync_width) {
  3544. DSI_DEBUG("timing.h_sync_width differs %d %d\n",
  3545. cur->timing.h_sync_width,
  3546. tgt->timing.h_sync_width);
  3547. return false;
  3548. }
  3549. if (cur->timing.h_front_porch != tgt->timing.h_front_porch) {
  3550. DSI_DEBUG("timing.h_front_porch differs %d %d\n",
  3551. cur->timing.h_front_porch,
  3552. tgt->timing.h_front_porch);
  3553. if (dfps_type != DSI_DFPS_IMMEDIATE_HFP)
  3554. return false;
  3555. }
  3556. if (cur->timing.h_skew != tgt->timing.h_skew) {
  3557. DSI_DEBUG("timing.h_skew differs %d %d\n",
  3558. cur->timing.h_skew,
  3559. tgt->timing.h_skew);
  3560. return false;
  3561. }
  3562. /* skip polarity comparison */
  3563. if (cur->timing.v_active != tgt->timing.v_active) {
  3564. DSI_DEBUG("timing.v_active differs %d %d\n",
  3565. cur->timing.v_active,
  3566. tgt->timing.v_active);
  3567. return false;
  3568. }
  3569. if (cur->timing.v_back_porch != tgt->timing.v_back_porch) {
  3570. DSI_DEBUG("timing.v_back_porch differs %d %d\n",
  3571. cur->timing.v_back_porch,
  3572. tgt->timing.v_back_porch);
  3573. return false;
  3574. }
  3575. if (cur->timing.v_sync_width != tgt->timing.v_sync_width) {
  3576. DSI_DEBUG("timing.v_sync_width differs %d %d\n",
  3577. cur->timing.v_sync_width,
  3578. tgt->timing.v_sync_width);
  3579. return false;
  3580. }
  3581. if (cur->timing.v_front_porch != tgt->timing.v_front_porch) {
  3582. DSI_DEBUG("timing.v_front_porch differs %d %d\n",
  3583. cur->timing.v_front_porch,
  3584. tgt->timing.v_front_porch);
  3585. if (dfps_type != DSI_DFPS_IMMEDIATE_VFP)
  3586. return false;
  3587. }
  3588. /* skip polarity comparison */
  3589. if (cur->timing.refresh_rate == tgt->timing.refresh_rate)
  3590. DSI_DEBUG("timing.refresh_rate identical %d %d\n",
  3591. cur->timing.refresh_rate,
  3592. tgt->timing.refresh_rate);
  3593. if (cur->pixel_clk_khz != tgt->pixel_clk_khz)
  3594. DSI_DEBUG("pixel_clk_khz differs %d %d\n",
  3595. cur->pixel_clk_khz, tgt->pixel_clk_khz);
  3596. if (cur->dsi_mode_flags != tgt->dsi_mode_flags)
  3597. DSI_DEBUG("flags differs %d %d\n",
  3598. cur->dsi_mode_flags, tgt->dsi_mode_flags);
  3599. return true;
  3600. }
  3601. void dsi_display_update_byte_intf_div(struct dsi_display *display)
  3602. {
  3603. struct dsi_host_common_cfg *config;
  3604. struct dsi_display_ctrl *m_ctrl;
  3605. int phy_ver;
  3606. m_ctrl = &display->ctrl[display->cmd_master_idx];
  3607. config = &display->panel->host_config;
  3608. phy_ver = dsi_phy_get_version(m_ctrl->phy);
  3609. if (phy_ver <= DSI_PHY_VERSION_2_0)
  3610. config->byte_intf_clk_div = 1;
  3611. else
  3612. config->byte_intf_clk_div = 2;
  3613. }
  3614. static int dsi_display_update_dsi_bitrate(struct dsi_display *display,
  3615. u32 bit_clk_rate)
  3616. {
  3617. int rc = 0;
  3618. int i;
  3619. DSI_DEBUG("%s:bit rate:%d\n", __func__, bit_clk_rate);
  3620. if (!display->panel) {
  3621. DSI_ERR("Invalid params\n");
  3622. return -EINVAL;
  3623. }
  3624. if (bit_clk_rate == 0) {
  3625. DSI_ERR("Invalid bit clock rate\n");
  3626. return -EINVAL;
  3627. }
  3628. display->config.bit_clk_rate_hz = bit_clk_rate;
  3629. display_for_each_ctrl(i, display) {
  3630. struct dsi_display_ctrl *dsi_disp_ctrl = &display->ctrl[i];
  3631. struct dsi_ctrl *ctrl = dsi_disp_ctrl->ctrl;
  3632. u32 num_of_lanes = 0, bpp, byte_intf_clk_div;
  3633. u64 bit_rate, pclk_rate, bit_rate_per_lane, byte_clk_rate,
  3634. byte_intf_clk_rate;
  3635. u32 bits_per_symbol = 16, num_of_symbols = 7; /* For Cphy */
  3636. struct dsi_host_common_cfg *host_cfg;
  3637. mutex_lock(&ctrl->ctrl_lock);
  3638. host_cfg = &display->panel->host_config;
  3639. if (host_cfg->data_lanes & DSI_DATA_LANE_0)
  3640. num_of_lanes++;
  3641. if (host_cfg->data_lanes & DSI_DATA_LANE_1)
  3642. num_of_lanes++;
  3643. if (host_cfg->data_lanes & DSI_DATA_LANE_2)
  3644. num_of_lanes++;
  3645. if (host_cfg->data_lanes & DSI_DATA_LANE_3)
  3646. num_of_lanes++;
  3647. if (num_of_lanes == 0) {
  3648. DSI_ERR("Invalid lane count\n");
  3649. rc = -EINVAL;
  3650. goto error;
  3651. }
  3652. bpp = dsi_pixel_format_to_bpp(host_cfg->dst_format);
  3653. bit_rate = display->config.bit_clk_rate_hz * num_of_lanes;
  3654. bit_rate_per_lane = bit_rate;
  3655. do_div(bit_rate_per_lane, num_of_lanes);
  3656. pclk_rate = bit_rate;
  3657. do_div(pclk_rate, bpp);
  3658. if (host_cfg->phy_type == DSI_PHY_TYPE_DPHY) {
  3659. bit_rate_per_lane = bit_rate;
  3660. do_div(bit_rate_per_lane, num_of_lanes);
  3661. byte_clk_rate = bit_rate_per_lane;
  3662. do_div(byte_clk_rate, 8);
  3663. byte_intf_clk_rate = byte_clk_rate;
  3664. byte_intf_clk_div = host_cfg->byte_intf_clk_div;
  3665. do_div(byte_intf_clk_rate, byte_intf_clk_div);
  3666. } else {
  3667. bit_rate_per_lane = bit_clk_rate;
  3668. pclk_rate *= bits_per_symbol;
  3669. do_div(pclk_rate, num_of_symbols);
  3670. byte_clk_rate = bit_clk_rate;
  3671. do_div(byte_clk_rate, num_of_symbols);
  3672. /* For CPHY, byte_intf_clk is same as byte_clk */
  3673. byte_intf_clk_rate = byte_clk_rate;
  3674. }
  3675. DSI_DEBUG("bit_clk_rate = %llu, bit_clk_rate_per_lane = %llu\n",
  3676. bit_rate, bit_rate_per_lane);
  3677. DSI_DEBUG("byte_clk_rate = %llu, byte_intf_clk_rate = %llu\n",
  3678. byte_clk_rate, byte_intf_clk_rate);
  3679. DSI_DEBUG("pclk_rate = %llu\n", pclk_rate);
  3680. SDE_EVT32(i, bit_rate, byte_clk_rate, pclk_rate);
  3681. ctrl->clk_freq.byte_clk_rate = byte_clk_rate;
  3682. ctrl->clk_freq.byte_intf_clk_rate = byte_intf_clk_rate;
  3683. ctrl->clk_freq.pix_clk_rate = pclk_rate;
  3684. rc = dsi_clk_set_link_frequencies(display->dsi_clk_handle,
  3685. ctrl->clk_freq, ctrl->cell_index);
  3686. if (rc) {
  3687. DSI_ERR("Failed to update link frequencies\n");
  3688. goto error;
  3689. }
  3690. ctrl->host_config.bit_clk_rate_hz = bit_clk_rate;
  3691. error:
  3692. mutex_unlock(&ctrl->ctrl_lock);
  3693. /* TODO: recover ctrl->clk_freq in case of failure */
  3694. if (rc)
  3695. return rc;
  3696. }
  3697. return 0;
  3698. }
  3699. static void _dsi_display_calc_pipe_delay(struct dsi_display *display,
  3700. struct dsi_dyn_clk_delay *delay,
  3701. struct dsi_display_mode *mode)
  3702. {
  3703. u32 esc_clk_rate_hz;
  3704. u32 pclk_to_esc_ratio, byte_to_esc_ratio, hr_bit_to_esc_ratio;
  3705. u32 hsync_period = 0;
  3706. struct dsi_display_ctrl *m_ctrl;
  3707. struct dsi_ctrl *dsi_ctrl;
  3708. struct dsi_phy_cfg *cfg;
  3709. int phy_ver;
  3710. m_ctrl = &display->ctrl[display->clk_master_idx];
  3711. dsi_ctrl = m_ctrl->ctrl;
  3712. cfg = &(m_ctrl->phy->cfg);
  3713. esc_clk_rate_hz = dsi_ctrl->clk_freq.esc_clk_rate;
  3714. pclk_to_esc_ratio = (dsi_ctrl->clk_freq.pix_clk_rate /
  3715. esc_clk_rate_hz);
  3716. byte_to_esc_ratio = (dsi_ctrl->clk_freq.byte_clk_rate /
  3717. esc_clk_rate_hz);
  3718. hr_bit_to_esc_ratio = ((dsi_ctrl->clk_freq.byte_clk_rate * 4) /
  3719. esc_clk_rate_hz);
  3720. hsync_period = dsi_h_total_dce(&mode->timing);
  3721. delay->pipe_delay = (hsync_period + 1) / pclk_to_esc_ratio;
  3722. if (!display->panel->video_config.eof_bllp_lp11_en)
  3723. delay->pipe_delay += (17 / pclk_to_esc_ratio) +
  3724. ((21 + (display->config.common_config.t_clk_pre + 1) +
  3725. (display->config.common_config.t_clk_post + 1)) /
  3726. byte_to_esc_ratio) +
  3727. ((((cfg->timing.lane_v3[8] >> 1) + 1) +
  3728. ((cfg->timing.lane_v3[6] >> 1) + 1) +
  3729. ((cfg->timing.lane_v3[3] * 4) +
  3730. (cfg->timing.lane_v3[5] >> 1) + 1) +
  3731. ((cfg->timing.lane_v3[7] >> 1) + 1) +
  3732. ((cfg->timing.lane_v3[1] >> 1) + 1) +
  3733. ((cfg->timing.lane_v3[4] >> 1) + 1)) /
  3734. hr_bit_to_esc_ratio);
  3735. delay->pipe_delay2 = 0;
  3736. if (display->panel->host_config.force_hs_clk_lane)
  3737. delay->pipe_delay2 = (6 / byte_to_esc_ratio) +
  3738. ((((cfg->timing.lane_v3[1] >> 1) + 1) +
  3739. ((cfg->timing.lane_v3[4] >> 1) + 1)) /
  3740. hr_bit_to_esc_ratio);
  3741. /*
  3742. * 100us pll delay recommended for phy ver 2.0 and 3.0
  3743. * 25us pll delay recommended for phy ver 4.0
  3744. */
  3745. phy_ver = dsi_phy_get_version(m_ctrl->phy);
  3746. if (phy_ver <= DSI_PHY_VERSION_3_0)
  3747. delay->pll_delay = 100;
  3748. else
  3749. delay->pll_delay = 25;
  3750. delay->pll_delay = ((delay->pll_delay * esc_clk_rate_hz) / 1000000);
  3751. }
  3752. /*
  3753. * dsi_display_is_type_cphy - check if panel type is cphy
  3754. * @display: Pointer to private display structure
  3755. * Returns: True if panel type is cphy
  3756. */
  3757. static inline bool dsi_display_is_type_cphy(struct dsi_display *display)
  3758. {
  3759. return (display->panel->host_config.phy_type ==
  3760. DSI_PHY_TYPE_CPHY) ? true : false;
  3761. }
  3762. static int _dsi_display_dyn_update_clks(struct dsi_display *display,
  3763. struct link_clk_freq *bkp_freq)
  3764. {
  3765. int rc = 0, i;
  3766. u8 ctrl_version;
  3767. struct dsi_display_ctrl *m_ctrl, *ctrl;
  3768. struct dsi_dyn_clk_caps *dyn_clk_caps;
  3769. struct dsi_clk_link_set *enable_clk;
  3770. m_ctrl = &display->ctrl[display->clk_master_idx];
  3771. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  3772. ctrl_version = m_ctrl->ctrl->version;
  3773. enable_clk = &display->clock_info.pll_clks;
  3774. dsi_clk_prepare_enable(enable_clk);
  3775. dsi_display_phy_configure(display, false);
  3776. display_for_each_ctrl(i, display) {
  3777. ctrl = &display->ctrl[i];
  3778. if (!ctrl->ctrl)
  3779. continue;
  3780. rc = dsi_clk_set_byte_clk_rate(display->dsi_clk_handle,
  3781. ctrl->ctrl->clk_freq.byte_clk_rate,
  3782. ctrl->ctrl->clk_freq.byte_intf_clk_rate, i);
  3783. if (rc) {
  3784. DSI_ERR("failed to set byte rate for index:%d\n", i);
  3785. goto recover_byte_clk;
  3786. }
  3787. rc = dsi_clk_set_pixel_clk_rate(display->dsi_clk_handle,
  3788. ctrl->ctrl->clk_freq.pix_clk_rate, i);
  3789. if (rc) {
  3790. DSI_ERR("failed to set pix rate for index:%d\n", i);
  3791. goto recover_pix_clk;
  3792. }
  3793. }
  3794. display_for_each_ctrl(i, display) {
  3795. ctrl = &display->ctrl[i];
  3796. if (ctrl == m_ctrl)
  3797. continue;
  3798. dsi_phy_dynamic_refresh_trigger(ctrl->phy, false);
  3799. }
  3800. dsi_phy_dynamic_refresh_trigger(m_ctrl->phy, true);
  3801. /*
  3802. * Don't wait for dynamic refresh done for dsi ctrl greater than 2.5
  3803. * and with constant fps, as dynamic refresh will applied with
  3804. * next mdp intf ctrl flush.
  3805. */
  3806. if ((ctrl_version >= DSI_CTRL_VERSION_2_5) &&
  3807. (dyn_clk_caps->maintain_const_fps))
  3808. goto defer_dfps_wait;
  3809. /* wait for dynamic refresh done */
  3810. display_for_each_ctrl(i, display) {
  3811. ctrl = &display->ctrl[i];
  3812. rc = dsi_ctrl_wait4dynamic_refresh_done(ctrl->ctrl);
  3813. if (rc) {
  3814. DSI_ERR("wait4dynamic refresh failed for dsi:%d\n", i);
  3815. goto recover_pix_clk;
  3816. } else {
  3817. DSI_INFO("dynamic refresh done on dsi: %s\n",
  3818. i ? "slave" : "master");
  3819. }
  3820. }
  3821. display_for_each_ctrl(i, display) {
  3822. ctrl = &display->ctrl[i];
  3823. dsi_phy_dynamic_refresh_clear(ctrl->phy);
  3824. }
  3825. defer_dfps_wait:
  3826. if (rc)
  3827. DSI_ERR("could not switch back to src clks %d\n", rc);
  3828. dsi_clk_disable_unprepare(enable_clk);
  3829. return rc;
  3830. recover_pix_clk:
  3831. display_for_each_ctrl(i, display) {
  3832. ctrl = &display->ctrl[i];
  3833. if (!ctrl->ctrl)
  3834. continue;
  3835. dsi_clk_set_pixel_clk_rate(display->dsi_clk_handle,
  3836. bkp_freq->pix_clk_rate, i);
  3837. }
  3838. recover_byte_clk:
  3839. display_for_each_ctrl(i, display) {
  3840. ctrl = &display->ctrl[i];
  3841. if (!ctrl->ctrl)
  3842. continue;
  3843. dsi_clk_set_byte_clk_rate(display->dsi_clk_handle,
  3844. bkp_freq->byte_clk_rate,
  3845. bkp_freq->byte_intf_clk_rate, i);
  3846. }
  3847. return rc;
  3848. }
  3849. static int dsi_display_dynamic_clk_switch_vid(struct dsi_display *display,
  3850. struct dsi_display_mode *mode)
  3851. {
  3852. int rc = 0, mask, i;
  3853. struct dsi_display_ctrl *m_ctrl, *ctrl;
  3854. struct dsi_dyn_clk_delay delay;
  3855. struct link_clk_freq bkp_freq;
  3856. dsi_panel_acquire_panel_lock(display->panel);
  3857. m_ctrl = &display->ctrl[display->clk_master_idx];
  3858. dsi_display_clk_ctrl(display->dsi_clk_handle, DSI_ALL_CLKS, DSI_CLK_ON);
  3859. /* mask PLL unlock, FIFO overflow and underflow errors */
  3860. mask = BIT(DSI_PLL_UNLOCK_ERR) | BIT(DSI_FIFO_UNDERFLOW) |
  3861. BIT(DSI_FIFO_OVERFLOW);
  3862. dsi_display_mask_ctrl_error_interrupts(display, mask, true);
  3863. /* update the phy timings based on new mode */
  3864. display_for_each_ctrl(i, display) {
  3865. ctrl = &display->ctrl[i];
  3866. dsi_phy_update_phy_timings(ctrl->phy, &display->config);
  3867. }
  3868. /* back up existing rates to handle failure case */
  3869. bkp_freq.byte_clk_rate = m_ctrl->ctrl->clk_freq.byte_clk_rate;
  3870. bkp_freq.byte_intf_clk_rate = m_ctrl->ctrl->clk_freq.byte_intf_clk_rate;
  3871. bkp_freq.pix_clk_rate = m_ctrl->ctrl->clk_freq.pix_clk_rate;
  3872. bkp_freq.esc_clk_rate = m_ctrl->ctrl->clk_freq.esc_clk_rate;
  3873. rc = dsi_display_update_dsi_bitrate(display, mode->timing.clk_rate_hz);
  3874. if (rc) {
  3875. DSI_ERR("failed set link frequencies %d\n", rc);
  3876. goto exit;
  3877. }
  3878. /* calculate pipe delays */
  3879. _dsi_display_calc_pipe_delay(display, &delay, mode);
  3880. /* configure dynamic refresh ctrl registers */
  3881. display_for_each_ctrl(i, display) {
  3882. ctrl = &display->ctrl[i];
  3883. if (!ctrl->phy)
  3884. continue;
  3885. if (ctrl == m_ctrl)
  3886. dsi_phy_config_dynamic_refresh(ctrl->phy, &delay, true);
  3887. else
  3888. dsi_phy_config_dynamic_refresh(ctrl->phy, &delay,
  3889. false);
  3890. }
  3891. rc = _dsi_display_dyn_update_clks(display, &bkp_freq);
  3892. exit:
  3893. dsi_display_mask_ctrl_error_interrupts(display, mask, false);
  3894. dsi_display_clk_ctrl(display->dsi_clk_handle, DSI_ALL_CLKS,
  3895. DSI_CLK_OFF);
  3896. /* store newly calculated phy timings in mode private info */
  3897. dsi_phy_dyn_refresh_cache_phy_timings(m_ctrl->phy,
  3898. mode->priv_info->phy_timing_val,
  3899. mode->priv_info->phy_timing_len);
  3900. dsi_panel_release_panel_lock(display->panel);
  3901. return rc;
  3902. }
  3903. static int dsi_display_dynamic_clk_configure_cmd(struct dsi_display *display,
  3904. int clk_rate)
  3905. {
  3906. int rc = 0;
  3907. if (clk_rate <= 0) {
  3908. DSI_ERR("%s: bitrate should be greater than 0\n", __func__);
  3909. return -EINVAL;
  3910. }
  3911. if (clk_rate == display->cached_clk_rate) {
  3912. DSI_INFO("%s: ignore duplicated DSI clk setting\n", __func__);
  3913. return rc;
  3914. }
  3915. display->cached_clk_rate = clk_rate;
  3916. rc = dsi_display_update_dsi_bitrate(display, clk_rate);
  3917. if (!rc) {
  3918. DSI_DEBUG("%s: bit clk is ready to be configured to '%d'\n",
  3919. __func__, clk_rate);
  3920. atomic_set(&display->clkrate_change_pending, 1);
  3921. } else {
  3922. DSI_ERR("%s: Failed to prepare to configure '%d'. rc = %d\n",
  3923. __func__, clk_rate, rc);
  3924. /* Caching clock failed, so don't go on doing so. */
  3925. atomic_set(&display->clkrate_change_pending, 0);
  3926. display->cached_clk_rate = 0;
  3927. }
  3928. return rc;
  3929. }
  3930. static int dsi_display_dfps_update(struct dsi_display *display,
  3931. struct dsi_display_mode *dsi_mode)
  3932. {
  3933. struct dsi_mode_info *timing;
  3934. struct dsi_display_ctrl *m_ctrl, *ctrl;
  3935. struct dsi_display_mode *panel_mode;
  3936. struct dsi_dfps_capabilities dfps_caps;
  3937. int rc = 0;
  3938. int i = 0;
  3939. struct dsi_dyn_clk_caps *dyn_clk_caps;
  3940. if (!display || !dsi_mode || !display->panel) {
  3941. DSI_ERR("Invalid params\n");
  3942. return -EINVAL;
  3943. }
  3944. timing = &dsi_mode->timing;
  3945. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  3946. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  3947. if (!dfps_caps.dfps_support && !dyn_clk_caps->maintain_const_fps) {
  3948. DSI_ERR("dfps or constant fps not supported\n");
  3949. return -ENOTSUPP;
  3950. }
  3951. if (dfps_caps.type == DSI_DFPS_IMMEDIATE_CLK) {
  3952. DSI_ERR("dfps clock method not supported\n");
  3953. return -ENOTSUPP;
  3954. }
  3955. /* For split DSI, update the clock master first */
  3956. DSI_DEBUG("configuring seamless dynamic fps\n\n");
  3957. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  3958. m_ctrl = &display->ctrl[display->clk_master_idx];
  3959. rc = dsi_ctrl_async_timing_update(m_ctrl->ctrl, timing);
  3960. if (rc) {
  3961. DSI_ERR("[%s] failed to dfps update host_%d, rc=%d\n",
  3962. display->name, i, rc);
  3963. goto error;
  3964. }
  3965. /* Update the rest of the controllers */
  3966. display_for_each_ctrl(i, display) {
  3967. ctrl = &display->ctrl[i];
  3968. if (!ctrl->ctrl || (ctrl == m_ctrl))
  3969. continue;
  3970. rc = dsi_ctrl_async_timing_update(ctrl->ctrl, timing);
  3971. if (rc) {
  3972. DSI_ERR("[%s] failed to dfps update host_%d, rc=%d\n",
  3973. display->name, i, rc);
  3974. goto error;
  3975. }
  3976. }
  3977. panel_mode = display->panel->cur_mode;
  3978. memcpy(panel_mode, dsi_mode, sizeof(*panel_mode));
  3979. /*
  3980. * dsi_mode_flags flags are used to communicate with other drm driver
  3981. * components, and are transient. They aren't inherently part of the
  3982. * display panel's mode and shouldn't be saved into the cached currently
  3983. * active mode.
  3984. */
  3985. panel_mode->dsi_mode_flags = 0;
  3986. error:
  3987. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  3988. return rc;
  3989. }
  3990. static int dsi_display_dfps_calc_front_porch(
  3991. u32 old_fps,
  3992. u32 new_fps,
  3993. u32 a_total,
  3994. u32 b_total,
  3995. u32 b_fp,
  3996. u32 *b_fp_out)
  3997. {
  3998. s32 b_fp_new;
  3999. int add_porches, diff;
  4000. if (!b_fp_out) {
  4001. DSI_ERR("Invalid params\n");
  4002. return -EINVAL;
  4003. }
  4004. if (!a_total || !new_fps) {
  4005. DSI_ERR("Invalid pixel total or new fps in mode request\n");
  4006. return -EINVAL;
  4007. }
  4008. /*
  4009. * Keep clock, other porches constant, use new fps, calc front porch
  4010. * new_vtotal = old_vtotal * (old_fps / new_fps )
  4011. * new_vfp - old_vfp = new_vtotal - old_vtotal
  4012. * new_vfp = old_vfp + old_vtotal * ((old_fps - new_fps)/ new_fps)
  4013. */
  4014. diff = abs(old_fps - new_fps);
  4015. add_porches = mult_frac(b_total, diff, new_fps);
  4016. if (old_fps > new_fps)
  4017. b_fp_new = b_fp + add_porches;
  4018. else
  4019. b_fp_new = b_fp - add_porches;
  4020. DSI_DEBUG("fps %u a %u b %u b_fp %u new_fp %d\n",
  4021. new_fps, a_total, b_total, b_fp, b_fp_new);
  4022. if (b_fp_new < 0) {
  4023. DSI_ERR("Invalid new_hfp calcluated%d\n", b_fp_new);
  4024. return -EINVAL;
  4025. }
  4026. /**
  4027. * TODO: To differentiate from clock method when communicating to the
  4028. * other components, perhaps we should set clk here to original value
  4029. */
  4030. *b_fp_out = b_fp_new;
  4031. return 0;
  4032. }
  4033. /**
  4034. * dsi_display_get_dfps_timing() - Get the new dfps values.
  4035. * @display: DSI display handle.
  4036. * @adj_mode: Mode value structure to be changed.
  4037. * It contains old timing values and latest fps value.
  4038. * New timing values are updated based on new fps.
  4039. * @curr_refresh_rate: Current fps rate.
  4040. * If zero , current fps rate is taken from
  4041. * display->panel->cur_mode.
  4042. * Return: error code.
  4043. */
  4044. static int dsi_display_get_dfps_timing(struct dsi_display *display,
  4045. struct dsi_display_mode *adj_mode,
  4046. u32 curr_refresh_rate)
  4047. {
  4048. struct dsi_dfps_capabilities dfps_caps;
  4049. struct dsi_display_mode per_ctrl_mode;
  4050. struct dsi_mode_info *timing;
  4051. struct dsi_ctrl *m_ctrl;
  4052. int rc = 0;
  4053. if (!display || !adj_mode) {
  4054. DSI_ERR("Invalid params\n");
  4055. return -EINVAL;
  4056. }
  4057. m_ctrl = display->ctrl[display->clk_master_idx].ctrl;
  4058. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  4059. if (!dfps_caps.dfps_support) {
  4060. DSI_ERR("dfps not supported by panel\n");
  4061. return -EINVAL;
  4062. }
  4063. per_ctrl_mode = *adj_mode;
  4064. adjust_timing_by_ctrl_count(display, &per_ctrl_mode);
  4065. if (!curr_refresh_rate) {
  4066. if (!dsi_display_is_seamless_dfps_possible(display,
  4067. &per_ctrl_mode, dfps_caps.type)) {
  4068. DSI_ERR("seamless dynamic fps not supported for mode\n");
  4069. return -EINVAL;
  4070. }
  4071. if (display->panel->cur_mode) {
  4072. curr_refresh_rate =
  4073. display->panel->cur_mode->timing.refresh_rate;
  4074. } else {
  4075. DSI_ERR("cur_mode is not initialized\n");
  4076. return -EINVAL;
  4077. }
  4078. }
  4079. /* TODO: Remove this direct reference to the dsi_ctrl */
  4080. timing = &per_ctrl_mode.timing;
  4081. switch (dfps_caps.type) {
  4082. case DSI_DFPS_IMMEDIATE_VFP:
  4083. rc = dsi_display_dfps_calc_front_porch(
  4084. curr_refresh_rate,
  4085. timing->refresh_rate,
  4086. dsi_h_total_dce(timing),
  4087. DSI_V_TOTAL(timing),
  4088. timing->v_front_porch,
  4089. &adj_mode->timing.v_front_porch);
  4090. SDE_EVT32(SDE_EVTLOG_FUNC_CASE1, DSI_DFPS_IMMEDIATE_VFP,
  4091. curr_refresh_rate, timing->refresh_rate,
  4092. timing->v_front_porch, adj_mode->timing.v_front_porch);
  4093. break;
  4094. case DSI_DFPS_IMMEDIATE_HFP:
  4095. rc = dsi_display_dfps_calc_front_porch(
  4096. curr_refresh_rate,
  4097. timing->refresh_rate,
  4098. DSI_V_TOTAL(timing),
  4099. dsi_h_total_dce(timing),
  4100. timing->h_front_porch,
  4101. &adj_mode->timing.h_front_porch);
  4102. SDE_EVT32(SDE_EVTLOG_FUNC_CASE2, DSI_DFPS_IMMEDIATE_HFP,
  4103. curr_refresh_rate, timing->refresh_rate,
  4104. timing->h_front_porch, adj_mode->timing.h_front_porch);
  4105. if (!rc)
  4106. adj_mode->timing.h_front_porch *= display->ctrl_count;
  4107. break;
  4108. default:
  4109. DSI_ERR("Unsupported DFPS mode %d\n", dfps_caps.type);
  4110. rc = -ENOTSUPP;
  4111. }
  4112. return rc;
  4113. }
  4114. static bool dsi_display_validate_mode_seamless(struct dsi_display *display,
  4115. struct dsi_display_mode *adj_mode)
  4116. {
  4117. int rc = 0;
  4118. if (!display || !adj_mode) {
  4119. DSI_ERR("Invalid params\n");
  4120. return false;
  4121. }
  4122. /* Currently the only seamless transition is dynamic fps */
  4123. rc = dsi_display_get_dfps_timing(display, adj_mode, 0);
  4124. if (rc) {
  4125. DSI_DEBUG("Dynamic FPS not supported for seamless\n");
  4126. } else {
  4127. DSI_DEBUG("Mode switch is seamless Dynamic FPS\n");
  4128. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_DFPS |
  4129. DSI_MODE_FLAG_VBLANK_PRE_MODESET;
  4130. }
  4131. return rc;
  4132. }
  4133. static void dsi_display_validate_dms_fps(struct dsi_display_mode *cur_mode,
  4134. struct dsi_display_mode *to_mode)
  4135. {
  4136. u32 cur_fps, to_fps;
  4137. u32 cur_h_active, to_h_active;
  4138. u32 cur_v_active, to_v_active;
  4139. cur_fps = cur_mode->timing.refresh_rate;
  4140. to_fps = to_mode->timing.refresh_rate;
  4141. cur_h_active = cur_mode->timing.h_active;
  4142. cur_v_active = cur_mode->timing.v_active;
  4143. to_h_active = to_mode->timing.h_active;
  4144. to_v_active = to_mode->timing.v_active;
  4145. if ((cur_h_active == to_h_active) && (cur_v_active == to_v_active) &&
  4146. (cur_fps != to_fps)) {
  4147. to_mode->dsi_mode_flags |= DSI_MODE_FLAG_DMS_FPS;
  4148. DSI_DEBUG("DMS Modeset with FPS change\n");
  4149. } else {
  4150. to_mode->dsi_mode_flags &= ~DSI_MODE_FLAG_DMS_FPS;
  4151. }
  4152. }
  4153. static int dsi_display_set_mode_sub(struct dsi_display *display,
  4154. struct dsi_display_mode *mode,
  4155. u32 flags)
  4156. {
  4157. int rc = 0, clk_rate = 0;
  4158. int i;
  4159. struct dsi_display_ctrl *ctrl;
  4160. struct dsi_display_ctrl *mctrl;
  4161. struct dsi_display_mode_priv_info *priv_info;
  4162. bool commit_phy_timing = false;
  4163. struct dsi_dyn_clk_caps *dyn_clk_caps;
  4164. priv_info = mode->priv_info;
  4165. if (!priv_info) {
  4166. DSI_ERR("[%s] failed to get private info of the display mode\n",
  4167. display->name);
  4168. return -EINVAL;
  4169. }
  4170. SDE_EVT32(mode->dsi_mode_flags, display->panel->panel_mode);
  4171. if (mode->dsi_mode_flags & DSI_MODE_FLAG_POMS_TO_VID)
  4172. display->panel->panel_mode = DSI_OP_VIDEO_MODE;
  4173. else if (mode->dsi_mode_flags & DSI_MODE_FLAG_POMS_TO_CMD)
  4174. display->panel->panel_mode = DSI_OP_CMD_MODE;
  4175. rc = dsi_panel_get_host_cfg_for_mode(display->panel,
  4176. mode,
  4177. &display->config);
  4178. if (rc) {
  4179. DSI_ERR("[%s] failed to get host config for mode, rc=%d\n",
  4180. display->name, rc);
  4181. goto error;
  4182. }
  4183. memcpy(&display->config.lane_map, &display->lane_map,
  4184. sizeof(display->lane_map));
  4185. mctrl = &display->ctrl[display->clk_master_idx];
  4186. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  4187. if (mode->dsi_mode_flags &
  4188. (DSI_MODE_FLAG_DFPS | DSI_MODE_FLAG_VRR)) {
  4189. display_for_each_ctrl(i, display) {
  4190. ctrl = &display->ctrl[i];
  4191. if (!ctrl->ctrl || (ctrl != mctrl))
  4192. continue;
  4193. ctrl->ctrl->hw.ops.set_timing_db(&ctrl->ctrl->hw,
  4194. true);
  4195. dsi_phy_dynamic_refresh_clear(ctrl->phy);
  4196. if ((ctrl->ctrl->version >= DSI_CTRL_VERSION_2_5) &&
  4197. (dyn_clk_caps->maintain_const_fps)) {
  4198. dsi_phy_dynamic_refresh_trigger_sel(ctrl->phy,
  4199. true);
  4200. }
  4201. }
  4202. rc = dsi_display_dfps_update(display, mode);
  4203. if (rc) {
  4204. DSI_ERR("[%s]DSI dfps update failed, rc=%d\n",
  4205. display->name, rc);
  4206. goto error;
  4207. }
  4208. display_for_each_ctrl(i, display) {
  4209. ctrl = &display->ctrl[i];
  4210. rc = dsi_ctrl_update_host_config(ctrl->ctrl,
  4211. &display->config, mode, mode->dsi_mode_flags,
  4212. display->dsi_clk_handle);
  4213. if (rc) {
  4214. DSI_ERR("failed to update ctrl config\n");
  4215. goto error;
  4216. }
  4217. }
  4218. if (priv_info->phy_timing_len) {
  4219. display_for_each_ctrl(i, display) {
  4220. ctrl = &display->ctrl[i];
  4221. rc = dsi_phy_set_timing_params(ctrl->phy,
  4222. priv_info->phy_timing_val,
  4223. priv_info->phy_timing_len,
  4224. commit_phy_timing);
  4225. if (rc)
  4226. DSI_ERR("Fail to add timing params\n");
  4227. }
  4228. }
  4229. if (!(mode->dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK))
  4230. return rc;
  4231. }
  4232. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK) {
  4233. if (display->panel->panel_mode == DSI_OP_VIDEO_MODE) {
  4234. rc = dsi_display_dynamic_clk_switch_vid(display, mode);
  4235. if (rc)
  4236. DSI_ERR("dynamic clk change failed %d\n", rc);
  4237. /*
  4238. * skip rest of the opearations since
  4239. * dsi_display_dynamic_clk_switch_vid() already takes
  4240. * care of them.
  4241. */
  4242. return rc;
  4243. } else if (display->panel->panel_mode == DSI_OP_CMD_MODE) {
  4244. clk_rate = mode->timing.clk_rate_hz;
  4245. rc = dsi_display_dynamic_clk_configure_cmd(display,
  4246. clk_rate);
  4247. if (rc) {
  4248. DSI_ERR("Failed to configure dynamic clk\n");
  4249. return rc;
  4250. }
  4251. }
  4252. }
  4253. display_for_each_ctrl(i, display) {
  4254. ctrl = &display->ctrl[i];
  4255. rc = dsi_ctrl_update_host_config(ctrl->ctrl, &display->config,
  4256. mode, mode->dsi_mode_flags,
  4257. display->dsi_clk_handle);
  4258. if (rc) {
  4259. DSI_ERR("[%s] failed to update ctrl config, rc=%d\n",
  4260. display->name, rc);
  4261. goto error;
  4262. }
  4263. }
  4264. if ((mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) &&
  4265. (display->panel->panel_mode == DSI_OP_CMD_MODE)) {
  4266. u64 cur_bitclk = display->panel->cur_mode->timing.clk_rate_hz;
  4267. u64 to_bitclk = mode->timing.clk_rate_hz;
  4268. commit_phy_timing = true;
  4269. /* No need to set clkrate pending flag if clocks are same */
  4270. if ((!cur_bitclk && !to_bitclk) || (cur_bitclk != to_bitclk))
  4271. atomic_set(&display->clkrate_change_pending, 1);
  4272. dsi_display_validate_dms_fps(display->panel->cur_mode, mode);
  4273. }
  4274. if (priv_info->phy_timing_len) {
  4275. display_for_each_ctrl(i, display) {
  4276. ctrl = &display->ctrl[i];
  4277. rc = dsi_phy_set_timing_params(ctrl->phy,
  4278. priv_info->phy_timing_val,
  4279. priv_info->phy_timing_len,
  4280. commit_phy_timing);
  4281. if (rc)
  4282. DSI_ERR("failed to add DSI PHY timing params\n");
  4283. }
  4284. }
  4285. error:
  4286. return rc;
  4287. }
  4288. /**
  4289. * _dsi_display_dev_init - initializes the display device
  4290. * Initialization will acquire references to the resources required for the
  4291. * display hardware to function.
  4292. * @display: Handle to the display
  4293. * Returns: Zero on success
  4294. */
  4295. static int _dsi_display_dev_init(struct dsi_display *display)
  4296. {
  4297. int rc = 0;
  4298. if (!display) {
  4299. DSI_ERR("invalid display\n");
  4300. return -EINVAL;
  4301. }
  4302. if (!display->panel_node && !display->fw)
  4303. return 0;
  4304. mutex_lock(&display->display_lock);
  4305. display->parser = dsi_parser_get(&display->pdev->dev);
  4306. if (display->fw && display->parser)
  4307. display->parser_node = dsi_parser_get_head_node(
  4308. display->parser, display->fw->data,
  4309. display->fw->size);
  4310. rc = dsi_display_res_init(display);
  4311. if (rc) {
  4312. DSI_ERR("[%s] failed to initialize resources, rc=%d\n",
  4313. display->name, rc);
  4314. goto error;
  4315. }
  4316. error:
  4317. mutex_unlock(&display->display_lock);
  4318. return rc;
  4319. }
  4320. /**
  4321. * _dsi_display_dev_deinit - deinitializes the display device
  4322. * All the resources acquired during device init will be released.
  4323. * @display: Handle to the display
  4324. * Returns: Zero on success
  4325. */
  4326. static int _dsi_display_dev_deinit(struct dsi_display *display)
  4327. {
  4328. int rc = 0;
  4329. if (!display) {
  4330. DSI_ERR("invalid display\n");
  4331. return -EINVAL;
  4332. }
  4333. mutex_lock(&display->display_lock);
  4334. rc = dsi_display_res_deinit(display);
  4335. if (rc)
  4336. DSI_ERR("[%s] failed to deinitialize resource, rc=%d\n",
  4337. display->name, rc);
  4338. mutex_unlock(&display->display_lock);
  4339. return rc;
  4340. }
  4341. /**
  4342. * dsi_display_cont_splash_res_disable() - Disable resource votes added in probe
  4343. * @dsi_display: Pointer to dsi display
  4344. * Returns: Zero on success
  4345. */
  4346. int dsi_display_cont_splash_res_disable(void *dsi_display)
  4347. {
  4348. struct dsi_display *display = dsi_display;
  4349. int rc = 0;
  4350. /* Remove the panel vote that was added during dsi display probe */
  4351. rc = dsi_pwr_enable_regulator(&display->panel->power_info, false);
  4352. if (rc)
  4353. DSI_ERR("[%s] failed to disable vregs, rc=%d\n",
  4354. display->panel->name, rc);
  4355. return rc;
  4356. }
  4357. /**
  4358. * dsi_display_cont_splash_config() - Initialize resources for continuous splash
  4359. * @dsi_display: Pointer to dsi display
  4360. * Returns: Zero on success
  4361. */
  4362. int dsi_display_cont_splash_config(void *dsi_display)
  4363. {
  4364. struct dsi_display *display = dsi_display;
  4365. int rc = 0;
  4366. /* Vote for gdsc required to read register address space */
  4367. if (!display) {
  4368. DSI_ERR("invalid input display param\n");
  4369. return -EINVAL;
  4370. }
  4371. rc = pm_runtime_get_sync(display->drm_dev->dev);
  4372. if (rc < 0) {
  4373. DSI_ERR("failed to vote gdsc for continuous splash, rc=%d\n",
  4374. rc);
  4375. return rc;
  4376. }
  4377. mutex_lock(&display->display_lock);
  4378. display->is_cont_splash_enabled = true;
  4379. /* Update splash status for clock manager */
  4380. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  4381. display->is_cont_splash_enabled);
  4382. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY, display->is_cont_splash_enabled);
  4383. /* Set up ctrl isr before enabling core clk */
  4384. dsi_display_ctrl_isr_configure(display, true);
  4385. /* Vote for Core clk and link clk. Votes on ctrl and phy
  4386. * regulator are inplicit from pre clk on callback
  4387. */
  4388. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  4389. DSI_ALL_CLKS, DSI_CLK_ON);
  4390. if (rc) {
  4391. DSI_ERR("[%s] failed to enable DSI link clocks, rc=%d\n",
  4392. display->name, rc);
  4393. goto clk_manager_update;
  4394. }
  4395. mutex_unlock(&display->display_lock);
  4396. /* Set the current brightness level */
  4397. dsi_panel_bl_handoff(display->panel);
  4398. return rc;
  4399. clk_manager_update:
  4400. dsi_display_ctrl_isr_configure(display, false);
  4401. /* Update splash status for clock manager */
  4402. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  4403. false);
  4404. pm_runtime_put_sync(display->drm_dev->dev);
  4405. display->is_cont_splash_enabled = false;
  4406. mutex_unlock(&display->display_lock);
  4407. return rc;
  4408. }
  4409. /**
  4410. * dsi_display_splash_res_cleanup() - cleanup for continuous splash
  4411. * @display: Pointer to dsi display
  4412. * Returns: Zero on success
  4413. */
  4414. int dsi_display_splash_res_cleanup(struct dsi_display *display)
  4415. {
  4416. int rc = 0;
  4417. if (!display->is_cont_splash_enabled)
  4418. return 0;
  4419. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  4420. DSI_ALL_CLKS, DSI_CLK_OFF);
  4421. if (rc)
  4422. DSI_ERR("[%s] failed to disable DSI link clocks, rc=%d\n",
  4423. display->name, rc);
  4424. pm_runtime_put_sync(display->drm_dev->dev);
  4425. display->is_cont_splash_enabled = false;
  4426. /* Update splash status for clock manager */
  4427. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  4428. display->is_cont_splash_enabled);
  4429. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT, display->is_cont_splash_enabled);
  4430. return rc;
  4431. }
  4432. static int dsi_display_force_update_dsi_clk(struct dsi_display *display)
  4433. {
  4434. int rc = 0;
  4435. rc = dsi_display_link_clk_force_update_ctrl(display->dsi_clk_handle);
  4436. if (!rc) {
  4437. DSI_DEBUG("dsi bit clk has been configured to %d\n",
  4438. display->cached_clk_rate);
  4439. atomic_set(&display->clkrate_change_pending, 0);
  4440. } else {
  4441. DSI_ERR("Failed to configure dsi bit clock '%d'. rc = %d\n",
  4442. display->cached_clk_rate, rc);
  4443. }
  4444. return rc;
  4445. }
  4446. static int dsi_display_validate_split_link(struct dsi_display *display)
  4447. {
  4448. int i, rc = 0;
  4449. struct dsi_display_ctrl *ctrl;
  4450. struct dsi_host_common_cfg *host = &display->panel->host_config;
  4451. if (!host->split_link.split_link_enabled)
  4452. return 0;
  4453. if (display->panel->panel_mode == DSI_OP_CMD_MODE) {
  4454. DSI_ERR("[%s] split link is not supported in command mode\n",
  4455. display->name);
  4456. rc = -ENOTSUPP;
  4457. goto error;
  4458. }
  4459. display_for_each_ctrl(i, display) {
  4460. ctrl = &display->ctrl[i];
  4461. if (!ctrl->ctrl->split_link_supported) {
  4462. DSI_ERR("[%s] split link is not supported by hw\n",
  4463. display->name);
  4464. rc = -ENOTSUPP;
  4465. goto error;
  4466. }
  4467. set_bit(DSI_PHY_SPLIT_LINK, ctrl->phy->hw.feature_map);
  4468. }
  4469. DSI_DEBUG("Split link is enabled\n");
  4470. return 0;
  4471. error:
  4472. host->split_link.split_link_enabled = false;
  4473. return rc;
  4474. }
  4475. static int dsi_display_get_io_resources(struct msm_io_res *io_res, void *data)
  4476. {
  4477. int rc = 0;
  4478. struct dsi_display *display;
  4479. if (!data)
  4480. return -EINVAL;
  4481. rc = dsi_ctrl_get_io_resources(io_res);
  4482. if (rc)
  4483. goto end;
  4484. rc = dsi_phy_get_io_resources(io_res);
  4485. if (rc)
  4486. goto end;
  4487. display = (struct dsi_display *)data;
  4488. rc = dsi_panel_get_io_resources(display->panel, io_res);
  4489. end:
  4490. return rc;
  4491. }
  4492. static int dsi_display_pre_release(void *data)
  4493. {
  4494. if (!data)
  4495. return -EINVAL;
  4496. dsi_display_ctrl_irq_update((struct dsi_display *)data, false);
  4497. return 0;
  4498. }
  4499. static int dsi_display_pre_acquire(void *data)
  4500. {
  4501. if (!data)
  4502. return -EINVAL;
  4503. dsi_display_ctrl_irq_update((struct dsi_display *)data, true);
  4504. return 0;
  4505. }
  4506. /**
  4507. * dsi_display_bind - bind dsi device with controlling device
  4508. * @dev: Pointer to base of platform device
  4509. * @master: Pointer to container of drm device
  4510. * @data: Pointer to private data
  4511. * Returns: Zero on success
  4512. */
  4513. static int dsi_display_bind(struct device *dev,
  4514. struct device *master,
  4515. void *data)
  4516. {
  4517. struct dsi_display_ctrl *display_ctrl;
  4518. struct drm_device *drm;
  4519. struct dsi_display *display;
  4520. struct dsi_clk_info info;
  4521. struct clk_ctrl_cb clk_cb;
  4522. void *handle = NULL;
  4523. struct platform_device *pdev = to_platform_device(dev);
  4524. char *client1 = "dsi_clk_client";
  4525. char *client2 = "mdp_event_client";
  4526. struct msm_vm_ops vm_event_ops = {
  4527. .vm_get_io_resources = dsi_display_get_io_resources,
  4528. .vm_pre_hw_release = dsi_display_pre_release,
  4529. .vm_post_hw_acquire = dsi_display_pre_acquire,
  4530. };
  4531. int i, rc = 0;
  4532. if (!dev || !pdev || !master) {
  4533. DSI_ERR("invalid param(s), dev %pK, pdev %pK, master %pK\n",
  4534. dev, pdev, master);
  4535. return -EINVAL;
  4536. }
  4537. drm = dev_get_drvdata(master);
  4538. display = platform_get_drvdata(pdev);
  4539. if (!drm || !display) {
  4540. DSI_ERR("invalid param(s), drm %pK, display %pK\n",
  4541. drm, display);
  4542. return -EINVAL;
  4543. }
  4544. if (!display->panel_node && !display->fw)
  4545. return 0;
  4546. if (!display->fw)
  4547. display->name = display->panel_node->name;
  4548. /* defer bind if ext bridge driver is not loaded */
  4549. if (display->panel && display->panel->host_config.ext_bridge_mode) {
  4550. for (i = 0; i < display->ext_bridge_cnt; i++) {
  4551. if (!of_drm_find_bridge(
  4552. display->ext_bridge[i].node_of)) {
  4553. DSI_DEBUG("defer for bridge[%d] %s\n", i,
  4554. display->ext_bridge[i].node_of->full_name);
  4555. return -EPROBE_DEFER;
  4556. }
  4557. }
  4558. }
  4559. mutex_lock(&display->display_lock);
  4560. rc = dsi_display_validate_split_link(display);
  4561. if (rc) {
  4562. DSI_ERR("[%s] split link validation failed, rc=%d\n",
  4563. display->name, rc);
  4564. goto error;
  4565. }
  4566. rc = dsi_display_debugfs_init(display);
  4567. if (rc) {
  4568. DSI_ERR("[%s] debugfs init failed, rc=%d\n", display->name, rc);
  4569. goto error;
  4570. }
  4571. atomic_set(&display->clkrate_change_pending, 0);
  4572. display->cached_clk_rate = 0;
  4573. memset(&info, 0x0, sizeof(info));
  4574. display_for_each_ctrl(i, display) {
  4575. display_ctrl = &display->ctrl[i];
  4576. rc = dsi_ctrl_drv_init(display_ctrl->ctrl, display->root);
  4577. if (rc) {
  4578. DSI_ERR("[%s] failed to initialize ctrl[%d], rc=%d\n",
  4579. display->name, i, rc);
  4580. goto error_ctrl_deinit;
  4581. }
  4582. display_ctrl->ctrl->horiz_index = i;
  4583. rc = dsi_phy_drv_init(display_ctrl->phy);
  4584. if (rc) {
  4585. DSI_ERR("[%s] Failed to initialize phy[%d], rc=%d\n",
  4586. display->name, i, rc);
  4587. (void)dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  4588. goto error_ctrl_deinit;
  4589. }
  4590. display_ctrl->ctrl->dma_cmd_workq = display->dma_cmd_workq;
  4591. memcpy(&info.c_clks[i],
  4592. (&display_ctrl->ctrl->clk_info.core_clks),
  4593. sizeof(struct dsi_core_clk_info));
  4594. memcpy(&info.l_hs_clks[i],
  4595. (&display_ctrl->ctrl->clk_info.hs_link_clks),
  4596. sizeof(struct dsi_link_hs_clk_info));
  4597. memcpy(&info.l_lp_clks[i],
  4598. (&display_ctrl->ctrl->clk_info.lp_link_clks),
  4599. sizeof(struct dsi_link_lp_clk_info));
  4600. info.c_clks[i].drm = drm;
  4601. info.ctrl_index[i] = display_ctrl->ctrl->cell_index;
  4602. }
  4603. info.pre_clkoff_cb = dsi_pre_clkoff_cb;
  4604. info.pre_clkon_cb = dsi_pre_clkon_cb;
  4605. info.post_clkoff_cb = dsi_post_clkoff_cb;
  4606. info.post_clkon_cb = dsi_post_clkon_cb;
  4607. info.phy_config_cb = dsi_display_phy_configure;
  4608. info.phy_pll_toggle_cb = dsi_display_phy_pll_toggle;
  4609. info.priv_data = display;
  4610. info.master_ndx = display->clk_master_idx;
  4611. info.dsi_ctrl_count = display->ctrl_count;
  4612. snprintf(info.name, MAX_STRING_LEN,
  4613. "DSI_MNGR-%s", display->name);
  4614. display->clk_mngr = dsi_display_clk_mngr_register(&info);
  4615. if (IS_ERR_OR_NULL(display->clk_mngr)) {
  4616. rc = PTR_ERR(display->clk_mngr);
  4617. display->clk_mngr = NULL;
  4618. DSI_ERR("dsi clock registration failed, rc = %d\n", rc);
  4619. goto error_ctrl_deinit;
  4620. }
  4621. handle = dsi_register_clk_handle(display->clk_mngr, client1);
  4622. if (IS_ERR_OR_NULL(handle)) {
  4623. rc = PTR_ERR(handle);
  4624. DSI_ERR("failed to register %s client, rc = %d\n",
  4625. client1, rc);
  4626. goto error_clk_deinit;
  4627. } else {
  4628. display->dsi_clk_handle = handle;
  4629. }
  4630. handle = dsi_register_clk_handle(display->clk_mngr, client2);
  4631. if (IS_ERR_OR_NULL(handle)) {
  4632. rc = PTR_ERR(handle);
  4633. DSI_ERR("failed to register %s client, rc = %d\n",
  4634. client2, rc);
  4635. goto error_clk_client_deinit;
  4636. } else {
  4637. display->mdp_clk_handle = handle;
  4638. }
  4639. clk_cb.priv = display;
  4640. clk_cb.dsi_clk_cb = dsi_display_clk_ctrl_cb;
  4641. display_for_each_ctrl(i, display) {
  4642. display_ctrl = &display->ctrl[i];
  4643. rc = dsi_ctrl_clk_cb_register(display_ctrl->ctrl, &clk_cb);
  4644. if (rc) {
  4645. DSI_ERR("[%s] failed to register ctrl clk_cb[%d], rc=%d\n",
  4646. display->name, i, rc);
  4647. goto error_ctrl_deinit;
  4648. }
  4649. rc = dsi_phy_clk_cb_register(display_ctrl->phy, &clk_cb);
  4650. if (rc) {
  4651. DSI_ERR("[%s] failed to register phy clk_cb[%d], rc=%d\n",
  4652. display->name, i, rc);
  4653. goto error_ctrl_deinit;
  4654. }
  4655. }
  4656. dsi_display_update_byte_intf_div(display);
  4657. rc = dsi_display_mipi_host_init(display);
  4658. if (rc) {
  4659. DSI_ERR("[%s] failed to initialize mipi host, rc=%d\n",
  4660. display->name, rc);
  4661. goto error_ctrl_deinit;
  4662. }
  4663. rc = dsi_panel_drv_init(display->panel, &display->host);
  4664. if (rc) {
  4665. if (rc != -EPROBE_DEFER)
  4666. DSI_ERR("[%s] failed to initialize panel driver, rc=%d\n",
  4667. display->name, rc);
  4668. goto error_host_deinit;
  4669. }
  4670. DSI_INFO("Successfully bind display panel '%s'\n", display->name);
  4671. display->drm_dev = drm;
  4672. display_for_each_ctrl(i, display) {
  4673. display_ctrl = &display->ctrl[i];
  4674. if (!display_ctrl->phy || !display_ctrl->ctrl)
  4675. continue;
  4676. display_ctrl->ctrl->drm_dev = drm;
  4677. rc = dsi_phy_set_clk_freq(display_ctrl->phy,
  4678. &display_ctrl->ctrl->clk_freq);
  4679. if (rc) {
  4680. DSI_ERR("[%s] failed to set phy clk freq, rc=%d\n",
  4681. display->name, rc);
  4682. goto error;
  4683. }
  4684. }
  4685. /* register te irq handler */
  4686. dsi_display_register_te_irq(display);
  4687. msm_register_vm_event(master, dev, &vm_event_ops, (void *)display);
  4688. goto error;
  4689. error_host_deinit:
  4690. (void)dsi_display_mipi_host_deinit(display);
  4691. error_clk_client_deinit:
  4692. (void)dsi_deregister_clk_handle(display->dsi_clk_handle);
  4693. error_clk_deinit:
  4694. (void)dsi_display_clk_mngr_deregister(display->clk_mngr);
  4695. error_ctrl_deinit:
  4696. for (i = i - 1; i >= 0; i--) {
  4697. display_ctrl = &display->ctrl[i];
  4698. (void)dsi_phy_drv_deinit(display_ctrl->phy);
  4699. (void)dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  4700. }
  4701. (void)dsi_display_debugfs_deinit(display);
  4702. error:
  4703. mutex_unlock(&display->display_lock);
  4704. return rc;
  4705. }
  4706. /**
  4707. * dsi_display_unbind - unbind dsi from controlling device
  4708. * @dev: Pointer to base of platform device
  4709. * @master: Pointer to container of drm device
  4710. * @data: Pointer to private data
  4711. */
  4712. static void dsi_display_unbind(struct device *dev,
  4713. struct device *master, void *data)
  4714. {
  4715. struct dsi_display_ctrl *display_ctrl;
  4716. struct dsi_display *display;
  4717. struct platform_device *pdev = to_platform_device(dev);
  4718. int i, rc = 0;
  4719. if (!dev || !pdev || !master) {
  4720. DSI_ERR("invalid param(s)\n");
  4721. return;
  4722. }
  4723. display = platform_get_drvdata(pdev);
  4724. if (!display || !display->panel_node) {
  4725. DSI_ERR("invalid display\n");
  4726. return;
  4727. }
  4728. mutex_lock(&display->display_lock);
  4729. rc = dsi_display_mipi_host_deinit(display);
  4730. if (rc)
  4731. DSI_ERR("[%s] failed to deinit mipi hosts, rc=%d\n",
  4732. display->name,
  4733. rc);
  4734. display_for_each_ctrl(i, display) {
  4735. display_ctrl = &display->ctrl[i];
  4736. rc = dsi_phy_drv_deinit(display_ctrl->phy);
  4737. if (rc)
  4738. DSI_ERR("[%s] failed to deinit phy%d driver, rc=%d\n",
  4739. display->name, i, rc);
  4740. display->ctrl->ctrl->dma_cmd_workq = NULL;
  4741. rc = dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  4742. if (rc)
  4743. DSI_ERR("[%s] failed to deinit ctrl%d driver, rc=%d\n",
  4744. display->name, i, rc);
  4745. }
  4746. atomic_set(&display->clkrate_change_pending, 0);
  4747. (void)dsi_display_debugfs_deinit(display);
  4748. mutex_unlock(&display->display_lock);
  4749. }
  4750. static const struct component_ops dsi_display_comp_ops = {
  4751. .bind = dsi_display_bind,
  4752. .unbind = dsi_display_unbind,
  4753. };
  4754. static struct platform_driver dsi_display_driver = {
  4755. .probe = dsi_display_dev_probe,
  4756. .remove = dsi_display_dev_remove,
  4757. .driver = {
  4758. .name = "msm-dsi-display",
  4759. .of_match_table = dsi_display_dt_match,
  4760. .suppress_bind_attrs = true,
  4761. },
  4762. };
  4763. static int dsi_display_init(struct dsi_display *display)
  4764. {
  4765. int rc = 0;
  4766. struct platform_device *pdev = display->pdev;
  4767. rc = _dsi_display_dev_init(display);
  4768. if (rc) {
  4769. DSI_ERR("device init failed, rc=%d\n", rc);
  4770. goto end;
  4771. }
  4772. /*
  4773. * Vote on panel regulator is added to make sure panel regulators
  4774. * are ON for cont-splash enabled usecase.
  4775. * This panel regulator vote will be removed only in:
  4776. * 1) device suspend when cont-splash is enabled.
  4777. * 2) cont_splash_res_disable() when cont-splash is disabled.
  4778. * For GKI, adding this vote will make sure that sync_state
  4779. * kernel driver doesn't disable the panel regulators after
  4780. * dsi probe is complete.
  4781. */
  4782. if (display->panel) {
  4783. rc = dsi_pwr_enable_regulator(&display->panel->power_info,
  4784. true);
  4785. if (rc) {
  4786. DSI_ERR("[%s] failed to enable vregs, rc=%d\n",
  4787. display->panel->name, rc);
  4788. return rc;
  4789. }
  4790. }
  4791. rc = component_add(&pdev->dev, &dsi_display_comp_ops);
  4792. if (rc)
  4793. DSI_ERR("component add failed, rc=%d\n", rc);
  4794. DSI_DEBUG("component add success: %s\n", display->name);
  4795. end:
  4796. return rc;
  4797. }
  4798. static void dsi_display_firmware_display(const struct firmware *fw,
  4799. void *context)
  4800. {
  4801. struct dsi_display *display = context;
  4802. if (fw) {
  4803. DSI_INFO("reading data from firmware, size=%zd\n",
  4804. fw->size);
  4805. display->fw = fw;
  4806. if (!strcmp(display->display_type, "primary"))
  4807. display->name = "dsi_firmware_display";
  4808. else if (!strcmp(display->display_type, "secondary"))
  4809. display->name = "dsi_firmware_display_secondary";
  4810. } else {
  4811. DSI_INFO("no firmware available, fallback to device node\n");
  4812. }
  4813. if (dsi_display_init(display))
  4814. return;
  4815. DSI_DEBUG("success\n");
  4816. }
  4817. int dsi_display_dev_probe(struct platform_device *pdev)
  4818. {
  4819. struct dsi_display *display = NULL;
  4820. struct device_node *node = NULL, *panel_node = NULL, *mdp_node = NULL;
  4821. int rc = 0, index = DSI_PRIMARY;
  4822. bool firm_req = false;
  4823. struct dsi_display_boot_param *boot_disp;
  4824. if (!pdev || !pdev->dev.of_node) {
  4825. DSI_ERR("pdev not found\n");
  4826. rc = -ENODEV;
  4827. goto end;
  4828. }
  4829. display = devm_kzalloc(&pdev->dev, sizeof(*display), GFP_KERNEL);
  4830. if (!display) {
  4831. rc = -ENOMEM;
  4832. goto end;
  4833. }
  4834. mutex_init(&display->display_lock);
  4835. display->dma_cmd_workq = create_singlethread_workqueue(
  4836. "dsi_dma_cmd_workq");
  4837. if (!display->dma_cmd_workq) {
  4838. DSI_ERR("failed to create work queue\n");
  4839. rc = -EINVAL;
  4840. goto end;
  4841. }
  4842. mdp_node = of_parse_phandle(pdev->dev.of_node, "qcom,mdp", 0);
  4843. if (!mdp_node) {
  4844. DSI_ERR("mdp_node not found\n");
  4845. rc = -ENODEV;
  4846. goto end;
  4847. }
  4848. display->trusted_vm_env = of_property_read_bool(mdp_node,
  4849. "qcom,sde-trusted-vm-env");
  4850. if (display->trusted_vm_env)
  4851. DSI_INFO("Display enabled with trusted vm path\n");
  4852. /* initialize panel id to UINT64_MAX */
  4853. display->panel_id = ~0x0;
  4854. display->display_type = of_get_property(pdev->dev.of_node,
  4855. "label", NULL);
  4856. if (!display->display_type)
  4857. display->display_type = "primary";
  4858. if (!strcmp(display->display_type, "secondary"))
  4859. index = DSI_SECONDARY;
  4860. boot_disp = &boot_displays[index];
  4861. node = pdev->dev.of_node;
  4862. if (boot_disp->boot_disp_en) {
  4863. /* The panel name should be same as UEFI name index */
  4864. panel_node = of_find_node_by_name(mdp_node, boot_disp->name);
  4865. if (!panel_node)
  4866. DSI_WARN("panel_node %s not found\n", boot_disp->name);
  4867. } else {
  4868. panel_node = of_parse_phandle(node,
  4869. "qcom,dsi-default-panel", 0);
  4870. if (!panel_node)
  4871. DSI_WARN("default panel not found\n");
  4872. }
  4873. boot_disp->node = pdev->dev.of_node;
  4874. boot_disp->disp = display;
  4875. display->panel_node = panel_node;
  4876. display->pdev = pdev;
  4877. display->boot_disp = boot_disp;
  4878. dsi_display_parse_cmdline_topology(display, index);
  4879. platform_set_drvdata(pdev, display);
  4880. rc = dsi_display_parse_dt(display);
  4881. if (rc) {
  4882. DSI_ERR("[%s] failed to parse dt, rc=%d\n", display->name, rc);
  4883. goto end;
  4884. }
  4885. rc = dsi_display_validate_resources(display);
  4886. if (rc) {
  4887. DSI_ERR("[%s] needed resources not probed yet, rc=%d\n",
  4888. display->name, rc);
  4889. goto end;
  4890. }
  4891. /* initialize display in firmware callback */
  4892. if (!boot_disp->boot_disp_en &&
  4893. IS_ENABLED(CONFIG_DSI_PARSER) &&
  4894. !display->trusted_vm_env) {
  4895. if (!strcmp(display->display_type, "primary"))
  4896. firm_req = !request_firmware_nowait(
  4897. THIS_MODULE, 1, "dsi_prop",
  4898. &pdev->dev, GFP_KERNEL, display,
  4899. dsi_display_firmware_display);
  4900. else if (!strcmp(display->display_type, "secondary"))
  4901. firm_req = !request_firmware_nowait(
  4902. THIS_MODULE, 1, "dsi_prop_sec",
  4903. &pdev->dev, GFP_KERNEL, display,
  4904. dsi_display_firmware_display);
  4905. }
  4906. if (!firm_req) {
  4907. rc = dsi_display_init(display);
  4908. if (rc)
  4909. goto end;
  4910. }
  4911. return 0;
  4912. end:
  4913. if (display) {
  4914. mutex_destroy(&display->display_lock);
  4915. devm_kfree(&pdev->dev, display);
  4916. }
  4917. return rc;
  4918. }
  4919. int dsi_display_dev_remove(struct platform_device *pdev)
  4920. {
  4921. int rc = 0, i = 0;
  4922. struct dsi_display *display;
  4923. struct dsi_display_ctrl *ctrl;
  4924. if (!pdev) {
  4925. DSI_ERR("Invalid device\n");
  4926. return -EINVAL;
  4927. }
  4928. display = platform_get_drvdata(pdev);
  4929. /* decrement ref count */
  4930. of_node_put(display->panel_node);
  4931. if (display->dma_cmd_workq) {
  4932. flush_workqueue(display->dma_cmd_workq);
  4933. destroy_workqueue(display->dma_cmd_workq);
  4934. display->dma_cmd_workq = NULL;
  4935. display_for_each_ctrl(i, display) {
  4936. ctrl = &display->ctrl[i];
  4937. if (!ctrl->ctrl)
  4938. continue;
  4939. ctrl->ctrl->dma_cmd_workq = NULL;
  4940. }
  4941. }
  4942. (void)_dsi_display_dev_deinit(display);
  4943. platform_set_drvdata(pdev, NULL);
  4944. devm_kfree(&pdev->dev, display);
  4945. return rc;
  4946. }
  4947. int dsi_display_get_num_of_displays(void)
  4948. {
  4949. int i, count = 0;
  4950. for (i = 0; i < MAX_DSI_ACTIVE_DISPLAY; i++) {
  4951. struct dsi_display *display = boot_displays[i].disp;
  4952. if ((display && display->panel_node) ||
  4953. (display && display->fw))
  4954. count++;
  4955. }
  4956. return count;
  4957. }
  4958. int dsi_display_get_active_displays(void **display_array, u32 max_display_count)
  4959. {
  4960. int index = 0, count = 0;
  4961. if (!display_array || !max_display_count) {
  4962. DSI_ERR("invalid params\n");
  4963. return 0;
  4964. }
  4965. for (index = 0; index < MAX_DSI_ACTIVE_DISPLAY; index++) {
  4966. struct dsi_display *display = boot_displays[index].disp;
  4967. if ((display && display->panel_node) ||
  4968. (display && display->fw))
  4969. display_array[count++] = display;
  4970. }
  4971. return count;
  4972. }
  4973. void dsi_display_set_active_state(struct dsi_display *display, bool is_active)
  4974. {
  4975. if (!display)
  4976. return;
  4977. mutex_lock(&display->display_lock);
  4978. display->is_active = is_active;
  4979. mutex_unlock(&display->display_lock);
  4980. }
  4981. int dsi_display_drm_bridge_init(struct dsi_display *display,
  4982. struct drm_encoder *enc)
  4983. {
  4984. int rc = 0;
  4985. struct dsi_bridge *bridge;
  4986. struct msm_drm_private *priv = NULL;
  4987. if (!display || !display->drm_dev || !enc) {
  4988. DSI_ERR("invalid param(s)\n");
  4989. return -EINVAL;
  4990. }
  4991. mutex_lock(&display->display_lock);
  4992. priv = display->drm_dev->dev_private;
  4993. if (!priv) {
  4994. DSI_ERR("Private data is not present\n");
  4995. rc = -EINVAL;
  4996. goto error;
  4997. }
  4998. if (display->bridge) {
  4999. DSI_ERR("display is already initialize\n");
  5000. goto error;
  5001. }
  5002. bridge = dsi_drm_bridge_init(display, display->drm_dev, enc);
  5003. if (IS_ERR_OR_NULL(bridge)) {
  5004. rc = PTR_ERR(bridge);
  5005. DSI_ERR("[%s] brige init failed, %d\n", display->name, rc);
  5006. goto error;
  5007. }
  5008. display->bridge = bridge;
  5009. priv->bridges[priv->num_bridges++] = &bridge->base;
  5010. if (display->tx_cmd_buf == NULL) {
  5011. rc = dsi_host_alloc_cmd_tx_buffer(display);
  5012. if (rc)
  5013. DSI_ERR("failed to allocate cmd tx buffer memory\n");
  5014. }
  5015. error:
  5016. mutex_unlock(&display->display_lock);
  5017. return rc;
  5018. }
  5019. int dsi_display_drm_bridge_deinit(struct dsi_display *display)
  5020. {
  5021. int rc = 0;
  5022. if (!display) {
  5023. DSI_ERR("Invalid params\n");
  5024. return -EINVAL;
  5025. }
  5026. mutex_lock(&display->display_lock);
  5027. dsi_drm_bridge_cleanup(display->bridge);
  5028. display->bridge = NULL;
  5029. mutex_unlock(&display->display_lock);
  5030. return rc;
  5031. }
  5032. /* Hook functions to call external connector, pointer validation is
  5033. * done in dsi_display_drm_ext_bridge_init.
  5034. */
  5035. static enum drm_connector_status dsi_display_drm_ext_detect(
  5036. struct drm_connector *connector,
  5037. bool force,
  5038. void *disp)
  5039. {
  5040. struct dsi_display *display = disp;
  5041. return display->ext_conn->funcs->detect(display->ext_conn, force);
  5042. }
  5043. static int dsi_display_drm_ext_get_modes(
  5044. struct drm_connector *connector, void *disp,
  5045. const struct msm_resource_caps_info *avail_res)
  5046. {
  5047. struct dsi_display *display = disp;
  5048. struct drm_display_mode *pmode, *pt;
  5049. int count;
  5050. /* if there are modes defined in panel, ignore external modes */
  5051. if (display->panel->num_timing_nodes)
  5052. return dsi_connector_get_modes(connector, disp, avail_res);
  5053. count = display->ext_conn->helper_private->get_modes(
  5054. display->ext_conn);
  5055. list_for_each_entry_safe(pmode, pt,
  5056. &display->ext_conn->probed_modes, head) {
  5057. list_move_tail(&pmode->head, &connector->probed_modes);
  5058. }
  5059. connector->display_info = display->ext_conn->display_info;
  5060. return count;
  5061. }
  5062. static enum drm_mode_status dsi_display_drm_ext_mode_valid(
  5063. struct drm_connector *connector,
  5064. struct drm_display_mode *mode,
  5065. void *disp, const struct msm_resource_caps_info *avail_res)
  5066. {
  5067. struct dsi_display *display = disp;
  5068. enum drm_mode_status status;
  5069. /* always do internal mode_valid check */
  5070. status = dsi_conn_mode_valid(connector, mode, disp, avail_res);
  5071. if (status != MODE_OK)
  5072. return status;
  5073. return display->ext_conn->helper_private->mode_valid(
  5074. display->ext_conn, mode);
  5075. }
  5076. static int dsi_display_drm_ext_atomic_check(struct drm_connector *connector,
  5077. void *disp,
  5078. struct drm_atomic_state *state)
  5079. {
  5080. struct dsi_display *display = disp;
  5081. struct drm_connector_state *c_state;
  5082. c_state = drm_atomic_get_new_connector_state(state, connector);
  5083. return display->ext_conn->helper_private->atomic_check(
  5084. display->ext_conn, state);
  5085. }
  5086. static int dsi_display_ext_get_info(struct drm_connector *connector,
  5087. struct msm_display_info *info, void *disp)
  5088. {
  5089. struct dsi_display *display;
  5090. int i;
  5091. if (!info || !disp) {
  5092. DSI_ERR("invalid params\n");
  5093. return -EINVAL;
  5094. }
  5095. display = disp;
  5096. if (!display->panel) {
  5097. DSI_ERR("invalid display panel\n");
  5098. return -EINVAL;
  5099. }
  5100. mutex_lock(&display->display_lock);
  5101. memset(info, 0, sizeof(struct msm_display_info));
  5102. info->intf_type = DRM_MODE_CONNECTOR_DSI;
  5103. info->num_of_h_tiles = display->ctrl_count;
  5104. for (i = 0; i < info->num_of_h_tiles; i++)
  5105. info->h_tile_instance[i] = display->ctrl[i].ctrl->cell_index;
  5106. info->is_connected = connector->status != connector_status_disconnected;
  5107. if (!strcmp(display->display_type, "primary"))
  5108. info->display_type = SDE_CONNECTOR_PRIMARY;
  5109. else if (!strcmp(display->display_type, "secondary"))
  5110. info->display_type = SDE_CONNECTOR_SECONDARY;
  5111. info->capabilities |= (MSM_DISPLAY_CAP_VID_MODE |
  5112. MSM_DISPLAY_CAP_EDID | MSM_DISPLAY_CAP_HOT_PLUG);
  5113. info->curr_panel_mode = MSM_DISPLAY_VIDEO_MODE;
  5114. mutex_unlock(&display->display_lock);
  5115. return 0;
  5116. }
  5117. static int dsi_display_ext_get_mode_info(struct drm_connector *connector,
  5118. const struct drm_display_mode *drm_mode,
  5119. struct msm_mode_info *mode_info,
  5120. void *display, const struct msm_resource_caps_info *avail_res)
  5121. {
  5122. struct msm_display_topology *topology;
  5123. if (!drm_mode || !mode_info ||
  5124. !avail_res || !avail_res->max_mixer_width)
  5125. return -EINVAL;
  5126. memset(mode_info, 0, sizeof(*mode_info));
  5127. mode_info->frame_rate = drm_mode_vrefresh(drm_mode);
  5128. mode_info->vtotal = drm_mode->vtotal;
  5129. topology = &mode_info->topology;
  5130. topology->num_lm = (avail_res->max_mixer_width
  5131. <= drm_mode->hdisplay) ? 2 : 1;
  5132. topology->num_enc = 0;
  5133. topology->num_intf = topology->num_lm;
  5134. mode_info->comp_info.comp_type = MSM_DISPLAY_COMPRESSION_NONE;
  5135. return 0;
  5136. }
  5137. static struct dsi_display_ext_bridge *dsi_display_ext_get_bridge(
  5138. struct drm_bridge *bridge)
  5139. {
  5140. struct msm_drm_private *priv;
  5141. struct sde_kms *sde_kms;
  5142. struct drm_connector *conn;
  5143. struct drm_connector_list_iter conn_iter;
  5144. struct sde_connector *sde_conn;
  5145. struct dsi_display *display;
  5146. struct dsi_display_ext_bridge *dsi_bridge = NULL;
  5147. int i;
  5148. if (!bridge || !bridge->encoder) {
  5149. SDE_ERROR("invalid argument\n");
  5150. return NULL;
  5151. }
  5152. priv = bridge->dev->dev_private;
  5153. sde_kms = to_sde_kms(priv->kms);
  5154. drm_connector_list_iter_begin(sde_kms->dev, &conn_iter);
  5155. drm_for_each_connector_iter(conn, &conn_iter) {
  5156. sde_conn = to_sde_connector(conn);
  5157. if (sde_conn->encoder == bridge->encoder) {
  5158. display = sde_conn->display;
  5159. display_for_each_ctrl(i, display) {
  5160. if (display->ext_bridge[i].bridge == bridge) {
  5161. dsi_bridge = &display->ext_bridge[i];
  5162. break;
  5163. }
  5164. }
  5165. }
  5166. }
  5167. drm_connector_list_iter_end(&conn_iter);
  5168. return dsi_bridge;
  5169. }
  5170. static void dsi_display_drm_ext_adjust_timing(
  5171. const struct dsi_display *display,
  5172. struct drm_display_mode *mode)
  5173. {
  5174. mode->hdisplay /= display->ctrl_count;
  5175. mode->hsync_start /= display->ctrl_count;
  5176. mode->hsync_end /= display->ctrl_count;
  5177. mode->htotal /= display->ctrl_count;
  5178. mode->hskew /= display->ctrl_count;
  5179. mode->clock /= display->ctrl_count;
  5180. }
  5181. static enum drm_mode_status dsi_display_drm_ext_bridge_mode_valid(
  5182. struct drm_bridge *bridge,
  5183. const struct drm_display_info *info,
  5184. const struct drm_display_mode *mode)
  5185. {
  5186. struct dsi_display_ext_bridge *ext_bridge;
  5187. struct drm_display_mode tmp;
  5188. ext_bridge = dsi_display_ext_get_bridge(bridge);
  5189. if (!ext_bridge)
  5190. return MODE_ERROR;
  5191. tmp = *mode;
  5192. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  5193. return ext_bridge->orig_funcs->mode_valid(bridge, info, &tmp);
  5194. }
  5195. static bool dsi_display_drm_ext_bridge_mode_fixup(
  5196. struct drm_bridge *bridge,
  5197. const struct drm_display_mode *mode,
  5198. struct drm_display_mode *adjusted_mode)
  5199. {
  5200. struct dsi_display_ext_bridge *ext_bridge;
  5201. struct drm_display_mode tmp;
  5202. ext_bridge = dsi_display_ext_get_bridge(bridge);
  5203. if (!ext_bridge)
  5204. return false;
  5205. tmp = *mode;
  5206. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  5207. return ext_bridge->orig_funcs->mode_fixup(bridge, &tmp, &tmp);
  5208. }
  5209. static void dsi_display_drm_ext_bridge_mode_set(
  5210. struct drm_bridge *bridge,
  5211. const struct drm_display_mode *mode,
  5212. const struct drm_display_mode *adjusted_mode)
  5213. {
  5214. struct dsi_display_ext_bridge *ext_bridge;
  5215. struct drm_display_mode tmp;
  5216. ext_bridge = dsi_display_ext_get_bridge(bridge);
  5217. if (!ext_bridge)
  5218. return;
  5219. tmp = *mode;
  5220. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  5221. ext_bridge->orig_funcs->mode_set(bridge, &tmp, &tmp);
  5222. }
  5223. static int dsi_host_ext_attach(struct mipi_dsi_host *host,
  5224. struct mipi_dsi_device *dsi)
  5225. {
  5226. struct dsi_display *display = to_dsi_display(host);
  5227. struct dsi_panel *panel;
  5228. if (!host || !dsi || !display->panel) {
  5229. DSI_ERR("Invalid param\n");
  5230. return -EINVAL;
  5231. }
  5232. DSI_DEBUG("DSI[%s]: channel=%d, lanes=%d, format=%d, mode_flags=%lx\n",
  5233. dsi->name, dsi->channel, dsi->lanes,
  5234. dsi->format, dsi->mode_flags);
  5235. panel = display->panel;
  5236. panel->host_config.data_lanes = 0;
  5237. if (dsi->lanes > 0)
  5238. panel->host_config.data_lanes |= DSI_DATA_LANE_0;
  5239. if (dsi->lanes > 1)
  5240. panel->host_config.data_lanes |= DSI_DATA_LANE_1;
  5241. if (dsi->lanes > 2)
  5242. panel->host_config.data_lanes |= DSI_DATA_LANE_2;
  5243. if (dsi->lanes > 3)
  5244. panel->host_config.data_lanes |= DSI_DATA_LANE_3;
  5245. switch (dsi->format) {
  5246. case MIPI_DSI_FMT_RGB888:
  5247. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB888;
  5248. break;
  5249. case MIPI_DSI_FMT_RGB666:
  5250. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB666_LOOSE;
  5251. break;
  5252. case MIPI_DSI_FMT_RGB666_PACKED:
  5253. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB666;
  5254. break;
  5255. case MIPI_DSI_FMT_RGB565:
  5256. default:
  5257. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB565;
  5258. break;
  5259. }
  5260. if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) {
  5261. panel->panel_mode = DSI_OP_VIDEO_MODE;
  5262. if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST)
  5263. panel->video_config.traffic_mode =
  5264. DSI_VIDEO_TRAFFIC_BURST_MODE;
  5265. else if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE)
  5266. panel->video_config.traffic_mode =
  5267. DSI_VIDEO_TRAFFIC_SYNC_PULSES;
  5268. else
  5269. panel->video_config.traffic_mode =
  5270. DSI_VIDEO_TRAFFIC_SYNC_START_EVENTS;
  5271. panel->video_config.hsa_lp11_en =
  5272. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSA;
  5273. panel->video_config.hbp_lp11_en =
  5274. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HBP;
  5275. panel->video_config.hfp_lp11_en =
  5276. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HFP;
  5277. panel->video_config.pulse_mode_hsa_he =
  5278. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSE;
  5279. } else {
  5280. panel->panel_mode = DSI_OP_CMD_MODE;
  5281. DSI_ERR("command mode not supported by ext bridge\n");
  5282. return -ENOTSUPP;
  5283. }
  5284. panel->bl_config.type = DSI_BACKLIGHT_UNKNOWN;
  5285. return 0;
  5286. }
  5287. static struct mipi_dsi_host_ops dsi_host_ext_ops = {
  5288. .attach = dsi_host_ext_attach,
  5289. .detach = dsi_host_detach,
  5290. .transfer = dsi_host_transfer,
  5291. };
  5292. struct drm_panel *dsi_display_get_drm_panel(struct dsi_display *display)
  5293. {
  5294. if (!display || !display->panel) {
  5295. pr_err("invalid param(s)\n");
  5296. return NULL;
  5297. }
  5298. return &display->panel->drm_panel;
  5299. }
  5300. int dsi_display_drm_ext_bridge_init(struct dsi_display *display,
  5301. struct drm_encoder *encoder, struct drm_connector *connector)
  5302. {
  5303. struct drm_device *drm;
  5304. struct drm_bridge *bridge;
  5305. struct drm_bridge *ext_bridge;
  5306. struct drm_connector *ext_conn;
  5307. struct sde_connector *sde_conn;
  5308. struct drm_bridge *prev_bridge;
  5309. int rc = 0, i;
  5310. if (!display || !encoder || !connector)
  5311. return -EINVAL;
  5312. drm = encoder->dev;
  5313. bridge = drm_bridge_chain_get_first_bridge(encoder);
  5314. sde_conn = to_sde_connector(connector);
  5315. prev_bridge = bridge;
  5316. if (display->panel && !display->panel->host_config.ext_bridge_mode)
  5317. return 0;
  5318. if (!bridge)
  5319. return -EINVAL;
  5320. for (i = 0; i < display->ext_bridge_cnt; i++) {
  5321. struct dsi_display_ext_bridge *ext_bridge_info =
  5322. &display->ext_bridge[i];
  5323. struct drm_encoder *c_encoder;
  5324. /* return if ext bridge is already initialized */
  5325. if (ext_bridge_info->bridge)
  5326. return 0;
  5327. ext_bridge = of_drm_find_bridge(ext_bridge_info->node_of);
  5328. if (IS_ERR_OR_NULL(ext_bridge)) {
  5329. rc = PTR_ERR(ext_bridge);
  5330. DSI_ERR("failed to find ext bridge\n");
  5331. goto error;
  5332. }
  5333. /* override functions for mode adjustment */
  5334. if (display->ext_bridge_cnt > 1) {
  5335. ext_bridge_info->bridge_funcs = *ext_bridge->funcs;
  5336. if (ext_bridge->funcs->mode_fixup)
  5337. ext_bridge_info->bridge_funcs.mode_fixup =
  5338. dsi_display_drm_ext_bridge_mode_fixup;
  5339. if (ext_bridge->funcs->mode_valid)
  5340. ext_bridge_info->bridge_funcs.mode_valid =
  5341. dsi_display_drm_ext_bridge_mode_valid;
  5342. if (ext_bridge->funcs->mode_set)
  5343. ext_bridge_info->bridge_funcs.mode_set =
  5344. dsi_display_drm_ext_bridge_mode_set;
  5345. ext_bridge_info->orig_funcs = ext_bridge->funcs;
  5346. ext_bridge->funcs = &ext_bridge_info->bridge_funcs;
  5347. }
  5348. rc = drm_bridge_attach(encoder, ext_bridge, prev_bridge, 0);
  5349. if (rc) {
  5350. DSI_ERR("[%s] ext brige attach failed, %d\n",
  5351. display->name, rc);
  5352. goto error;
  5353. }
  5354. ext_bridge_info->display = display;
  5355. ext_bridge_info->bridge = ext_bridge;
  5356. prev_bridge = ext_bridge;
  5357. /* ext bridge will init its own connector during attach,
  5358. * we need to extract it out of the connector list
  5359. */
  5360. spin_lock_irq(&drm->mode_config.connector_list_lock);
  5361. ext_conn = list_last_entry(&drm->mode_config.connector_list,
  5362. struct drm_connector, head);
  5363. if (!ext_conn) {
  5364. DSI_ERR("failed to get external connector\n");
  5365. rc = PTR_ERR(ext_conn);
  5366. spin_unlock_irq(&drm->mode_config.connector_list_lock);
  5367. goto error;
  5368. }
  5369. drm_connector_for_each_possible_encoder(ext_conn, c_encoder)
  5370. break;
  5371. if (!c_encoder) {
  5372. DSI_ERR("failed to get encoder\n");
  5373. rc = PTR_ERR(c_encoder);
  5374. spin_unlock_irq(&drm->mode_config.connector_list_lock);
  5375. goto error;
  5376. }
  5377. if (ext_conn && ext_conn != connector &&
  5378. c_encoder->base.id == bridge->encoder->base.id) {
  5379. list_del_init(&ext_conn->head);
  5380. display->ext_conn = ext_conn;
  5381. }
  5382. spin_unlock_irq(&drm->mode_config.connector_list_lock);
  5383. /* if there is no valid external connector created, or in split
  5384. * mode, default setting is used from panel defined in DT file.
  5385. */
  5386. if (!display->ext_conn ||
  5387. !display->ext_conn->funcs ||
  5388. !display->ext_conn->helper_private ||
  5389. display->ext_bridge_cnt > 1) {
  5390. display->ext_conn = NULL;
  5391. continue;
  5392. }
  5393. /* otherwise, hook up the functions to use external connector */
  5394. if (display->ext_conn->funcs->detect)
  5395. sde_conn->ops.detect = dsi_display_drm_ext_detect;
  5396. if (display->ext_conn->helper_private->get_modes)
  5397. sde_conn->ops.get_modes =
  5398. dsi_display_drm_ext_get_modes;
  5399. if (display->ext_conn->helper_private->mode_valid)
  5400. sde_conn->ops.mode_valid =
  5401. dsi_display_drm_ext_mode_valid;
  5402. if (display->ext_conn->helper_private->atomic_check)
  5403. sde_conn->ops.atomic_check =
  5404. dsi_display_drm_ext_atomic_check;
  5405. sde_conn->ops.get_info =
  5406. dsi_display_ext_get_info;
  5407. sde_conn->ops.get_mode_info =
  5408. dsi_display_ext_get_mode_info;
  5409. /* add support to attach/detach */
  5410. display->host.ops = &dsi_host_ext_ops;
  5411. }
  5412. return 0;
  5413. error:
  5414. return rc;
  5415. }
  5416. int dsi_display_get_info(struct drm_connector *connector,
  5417. struct msm_display_info *info, void *disp)
  5418. {
  5419. struct dsi_display *display;
  5420. struct dsi_panel_phy_props phy_props;
  5421. struct dsi_host_common_cfg *host;
  5422. int i, rc;
  5423. if (!info || !disp) {
  5424. DSI_ERR("invalid params\n");
  5425. return -EINVAL;
  5426. }
  5427. display = disp;
  5428. if (!display->panel) {
  5429. DSI_ERR("invalid display panel\n");
  5430. return -EINVAL;
  5431. }
  5432. mutex_lock(&display->display_lock);
  5433. rc = dsi_panel_get_phy_props(display->panel, &phy_props);
  5434. if (rc) {
  5435. DSI_ERR("[%s] failed to get panel phy props, rc=%d\n",
  5436. display->name, rc);
  5437. goto error;
  5438. }
  5439. memset(info, 0, sizeof(struct msm_display_info));
  5440. info->intf_type = DRM_MODE_CONNECTOR_DSI;
  5441. info->num_of_h_tiles = display->ctrl_count;
  5442. for (i = 0; i < info->num_of_h_tiles; i++)
  5443. info->h_tile_instance[i] = display->ctrl[i].ctrl->cell_index;
  5444. info->is_connected = display->is_active;
  5445. if (!strcmp(display->display_type, "primary"))
  5446. info->display_type = SDE_CONNECTOR_PRIMARY;
  5447. else if (!strcmp(display->display_type, "secondary"))
  5448. info->display_type = SDE_CONNECTOR_SECONDARY;
  5449. info->width_mm = phy_props.panel_width_mm;
  5450. info->height_mm = phy_props.panel_height_mm;
  5451. info->max_width = 1920;
  5452. info->max_height = 1080;
  5453. info->qsync_min_fps =
  5454. display->panel->qsync_caps.qsync_min_fps;
  5455. info->has_qsync_min_fps_list =
  5456. (display->panel->qsync_caps.qsync_min_fps_list_len > 0) ?
  5457. true : false;
  5458. info->poms_align_vsync = display->panel->poms_align_vsync;
  5459. switch (display->panel->panel_mode) {
  5460. case DSI_OP_VIDEO_MODE:
  5461. info->curr_panel_mode = MSM_DISPLAY_VIDEO_MODE;
  5462. info->capabilities |= MSM_DISPLAY_CAP_VID_MODE;
  5463. if (display->panel->panel_mode_switch_enabled)
  5464. info->capabilities |= MSM_DISPLAY_CAP_CMD_MODE;
  5465. break;
  5466. case DSI_OP_CMD_MODE:
  5467. info->curr_panel_mode = MSM_DISPLAY_CMD_MODE;
  5468. info->capabilities |= MSM_DISPLAY_CAP_CMD_MODE;
  5469. if (display->panel->panel_mode_switch_enabled)
  5470. info->capabilities |= MSM_DISPLAY_CAP_VID_MODE;
  5471. info->is_te_using_watchdog_timer =
  5472. display->panel->te_using_watchdog_timer |
  5473. display->sw_te_using_wd;
  5474. break;
  5475. default:
  5476. DSI_ERR("unknwown dsi panel mode %d\n",
  5477. display->panel->panel_mode);
  5478. break;
  5479. }
  5480. if (display->panel->esd_config.esd_enabled &&
  5481. !display->sw_te_using_wd)
  5482. info->capabilities |= MSM_DISPLAY_ESD_ENABLED;
  5483. info->te_source = display->te_source;
  5484. host = &display->panel->host_config;
  5485. if (host->split_link.split_link_enabled)
  5486. info->capabilities |= MSM_DISPLAY_SPLIT_LINK;
  5487. info->dsc_count = display->panel->dsc_count;
  5488. info->lm_count = display->panel->lm_count;
  5489. error:
  5490. mutex_unlock(&display->display_lock);
  5491. return rc;
  5492. }
  5493. int dsi_display_get_mode_count(struct dsi_display *display,
  5494. u32 *count)
  5495. {
  5496. if (!display || !display->panel) {
  5497. DSI_ERR("invalid display:%d panel:%d\n", display != NULL,
  5498. display ? display->panel != NULL : 0);
  5499. return -EINVAL;
  5500. }
  5501. mutex_lock(&display->display_lock);
  5502. *count = display->panel->num_display_modes;
  5503. mutex_unlock(&display->display_lock);
  5504. return 0;
  5505. }
  5506. void dsi_display_adjust_mode_timing(struct dsi_display *display,
  5507. struct dsi_display_mode *dsi_mode,
  5508. int lanes, int bpp)
  5509. {
  5510. u64 new_htotal, new_vtotal, htotal, vtotal, old_htotal, div;
  5511. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5512. u32 bits_per_symbol = 16, num_of_symbols = 7; /* For Cphy */
  5513. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5514. /* Constant FPS is not supported on command mode */
  5515. if (!(dsi_mode->panel_mode_caps & DSI_OP_VIDEO_MODE))
  5516. return;
  5517. if (!dyn_clk_caps->maintain_const_fps)
  5518. return;
  5519. /*
  5520. * When there is a dynamic clock switch, there is small change
  5521. * in FPS. To compensate for this difference in FPS, hfp or vfp
  5522. * is adjusted. It has been assumed that the refined porch values
  5523. * are supported by the panel. This logic can be enhanced further
  5524. * in future by taking min/max porches supported by the panel.
  5525. */
  5526. switch (dyn_clk_caps->type) {
  5527. case DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_HFP:
  5528. vtotal = DSI_V_TOTAL(&dsi_mode->timing);
  5529. old_htotal = dsi_h_total_dce(&dsi_mode->timing);
  5530. do_div(old_htotal, display->ctrl_count);
  5531. new_htotal = dsi_mode->timing.clk_rate_hz * lanes;
  5532. div = bpp * vtotal * dsi_mode->timing.refresh_rate;
  5533. if (dsi_display_is_type_cphy(display)) {
  5534. new_htotal = new_htotal * bits_per_symbol;
  5535. div = div * num_of_symbols;
  5536. }
  5537. do_div(new_htotal, div);
  5538. if (old_htotal > new_htotal)
  5539. dsi_mode->timing.h_front_porch -=
  5540. ((old_htotal - new_htotal) * display->ctrl_count);
  5541. else
  5542. dsi_mode->timing.h_front_porch +=
  5543. ((new_htotal - old_htotal) * display->ctrl_count);
  5544. break;
  5545. case DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_VFP:
  5546. htotal = dsi_h_total_dce(&dsi_mode->timing);
  5547. do_div(htotal, display->ctrl_count);
  5548. new_vtotal = dsi_mode->timing.clk_rate_hz * lanes;
  5549. div = bpp * htotal * dsi_mode->timing.refresh_rate;
  5550. if (dsi_display_is_type_cphy(display)) {
  5551. new_vtotal = new_vtotal * bits_per_symbol;
  5552. div = div * num_of_symbols;
  5553. }
  5554. do_div(new_vtotal, div);
  5555. dsi_mode->timing.v_front_porch = new_vtotal -
  5556. dsi_mode->timing.v_back_porch -
  5557. dsi_mode->timing.v_sync_width -
  5558. dsi_mode->timing.v_active;
  5559. break;
  5560. default:
  5561. break;
  5562. }
  5563. }
  5564. static void _dsi_display_populate_bit_clks(struct dsi_display *display,
  5565. int start, int end, u32 *mode_idx)
  5566. {
  5567. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5568. struct dsi_display_mode *src, *dst;
  5569. struct dsi_host_common_cfg *cfg;
  5570. struct dsi_display_mode_priv_info *priv_info;
  5571. int i, j, total_modes, bpp, lanes = 0;
  5572. size_t size = 0;
  5573. if (!display || !mode_idx)
  5574. return;
  5575. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5576. if (!dyn_clk_caps->dyn_clk_support)
  5577. return;
  5578. cfg = &(display->panel->host_config);
  5579. bpp = dsi_pixel_format_to_bpp(cfg->dst_format);
  5580. if (cfg->data_lanes & DSI_DATA_LANE_0)
  5581. lanes++;
  5582. if (cfg->data_lanes & DSI_DATA_LANE_1)
  5583. lanes++;
  5584. if (cfg->data_lanes & DSI_DATA_LANE_2)
  5585. lanes++;
  5586. if (cfg->data_lanes & DSI_DATA_LANE_3)
  5587. lanes++;
  5588. total_modes = display->panel->num_display_modes;
  5589. for (i = start; i < end; i++) {
  5590. src = &display->modes[i];
  5591. if (!src)
  5592. return;
  5593. /*
  5594. * TODO: currently setting the first bit rate in
  5595. * the list as preferred rate. But ideally should
  5596. * be based on user or device tree preferrence.
  5597. */
  5598. src->timing.clk_rate_hz = dyn_clk_caps->bit_clk_list[0];
  5599. dsi_display_adjust_mode_timing(display, src, lanes, bpp);
  5600. src->pixel_clk_khz =
  5601. div_u64(src->timing.clk_rate_hz * lanes, bpp);
  5602. src->pixel_clk_khz /= 1000;
  5603. src->pixel_clk_khz *= display->ctrl_count;
  5604. }
  5605. for (i = 1; i < dyn_clk_caps->bit_clk_list_len; i++) {
  5606. if (*mode_idx >= total_modes)
  5607. return;
  5608. for (j = start; j < end; j++) {
  5609. src = &display->modes[j];
  5610. dst = &display->modes[*mode_idx];
  5611. if (!src || !dst) {
  5612. DSI_ERR("invalid mode index\n");
  5613. return;
  5614. }
  5615. memcpy(dst, src, sizeof(struct dsi_display_mode));
  5616. size = sizeof(struct dsi_display_mode_priv_info);
  5617. priv_info = kzalloc(size, GFP_KERNEL);
  5618. dst->priv_info = priv_info;
  5619. if (dst->priv_info)
  5620. memcpy(dst->priv_info, src->priv_info, size);
  5621. dst->timing.clk_rate_hz = dyn_clk_caps->bit_clk_list[i];
  5622. dsi_display_adjust_mode_timing(display, dst, lanes,
  5623. bpp);
  5624. dst->panel_mode_caps = DSI_OP_VIDEO_MODE;
  5625. dst->pixel_clk_khz =
  5626. div_u64(dst->timing.clk_rate_hz * lanes, bpp);
  5627. dst->pixel_clk_khz /= 1000;
  5628. dst->pixel_clk_khz *= display->ctrl_count;
  5629. (*mode_idx)++;
  5630. }
  5631. }
  5632. }
  5633. void dsi_display_put_mode(struct dsi_display *display,
  5634. struct dsi_display_mode *mode)
  5635. {
  5636. dsi_panel_put_mode(mode);
  5637. }
  5638. int dsi_display_get_modes(struct dsi_display *display,
  5639. struct dsi_display_mode **out_modes)
  5640. {
  5641. struct dsi_dfps_capabilities dfps_caps;
  5642. struct dsi_display_ctrl *ctrl;
  5643. struct dsi_host_common_cfg *host = &display->panel->host_config;
  5644. bool is_split_link, support_cmd_mode, support_video_mode;
  5645. u32 num_dfps_rates, timing_mode_count, display_mode_count;
  5646. u32 sublinks_count, mode_idx, array_idx = 0;
  5647. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5648. int i, start, end, rc = -EINVAL;
  5649. if (!display || !out_modes) {
  5650. DSI_ERR("Invalid params\n");
  5651. return -EINVAL;
  5652. }
  5653. *out_modes = NULL;
  5654. ctrl = &display->ctrl[0];
  5655. mutex_lock(&display->display_lock);
  5656. if (display->modes)
  5657. goto exit;
  5658. display_mode_count = display->panel->num_display_modes;
  5659. display->modes = kcalloc(display_mode_count, sizeof(*display->modes),
  5660. GFP_KERNEL);
  5661. if (!display->modes) {
  5662. rc = -ENOMEM;
  5663. goto error;
  5664. }
  5665. rc = dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  5666. if (rc) {
  5667. DSI_ERR("[%s] failed to get dfps caps from panel\n",
  5668. display->name);
  5669. goto error;
  5670. }
  5671. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5672. timing_mode_count = display->panel->num_timing_nodes;
  5673. /* Validate command line timing */
  5674. if ((display->cmdline_timing != NO_OVERRIDE) &&
  5675. (display->cmdline_timing >= timing_mode_count))
  5676. display->cmdline_timing = NO_OVERRIDE;
  5677. for (mode_idx = 0; mode_idx < timing_mode_count; mode_idx++) {
  5678. struct dsi_display_mode display_mode;
  5679. int topology_override = NO_OVERRIDE;
  5680. bool is_preferred = false;
  5681. u32 frame_threshold_us = ctrl->ctrl->frame_threshold_time_us;
  5682. if (display->cmdline_timing == mode_idx) {
  5683. topology_override = display->cmdline_topology;
  5684. is_preferred = true;
  5685. }
  5686. memset(&display_mode, 0, sizeof(display_mode));
  5687. rc = dsi_panel_get_mode(display->panel, mode_idx,
  5688. &display_mode,
  5689. topology_override);
  5690. if (rc) {
  5691. DSI_ERR("[%s] failed to get mode idx %d from panel\n",
  5692. display->name, mode_idx);
  5693. goto error;
  5694. }
  5695. support_cmd_mode = display_mode.panel_mode_caps & DSI_OP_CMD_MODE;
  5696. support_video_mode = display_mode.panel_mode_caps & DSI_OP_VIDEO_MODE;
  5697. /* Setup widebus support */
  5698. display_mode.priv_info->widebus_support =
  5699. ctrl->ctrl->hw.widebus_support;
  5700. num_dfps_rates = ((!dfps_caps.dfps_support ||
  5701. !support_video_mode) ? 1 : dfps_caps.dfps_list_len);
  5702. /* Calculate dsi frame transfer time */
  5703. if (support_cmd_mode) {
  5704. dsi_panel_calc_dsi_transfer_time(
  5705. &display->panel->host_config,
  5706. &display_mode, frame_threshold_us);
  5707. display_mode.priv_info->dsi_transfer_time_us =
  5708. display_mode.timing.dsi_transfer_time_us;
  5709. display_mode.priv_info->min_dsi_clk_hz =
  5710. display_mode.timing.min_dsi_clk_hz;
  5711. display_mode.priv_info->mdp_transfer_time_us =
  5712. display_mode.timing.mdp_transfer_time_us;
  5713. }
  5714. is_split_link = host->split_link.split_link_enabled;
  5715. sublinks_count = host->split_link.num_sublinks;
  5716. if (is_split_link && sublinks_count > 1) {
  5717. display_mode.timing.h_active *= sublinks_count;
  5718. display_mode.timing.h_front_porch *= sublinks_count;
  5719. display_mode.timing.h_sync_width *= sublinks_count;
  5720. display_mode.timing.h_back_porch *= sublinks_count;
  5721. display_mode.timing.h_skew *= sublinks_count;
  5722. display_mode.pixel_clk_khz *= sublinks_count;
  5723. } else {
  5724. display_mode.timing.h_active *= display->ctrl_count;
  5725. display_mode.timing.h_front_porch *=
  5726. display->ctrl_count;
  5727. display_mode.timing.h_sync_width *=
  5728. display->ctrl_count;
  5729. display_mode.timing.h_back_porch *=
  5730. display->ctrl_count;
  5731. display_mode.timing.h_skew *= display->ctrl_count;
  5732. display_mode.pixel_clk_khz *= display->ctrl_count;
  5733. }
  5734. start = array_idx;
  5735. for (i = 0; i < num_dfps_rates; i++) {
  5736. struct dsi_display_mode *sub_mode =
  5737. &display->modes[array_idx];
  5738. u32 curr_refresh_rate;
  5739. if (!sub_mode) {
  5740. DSI_ERR("invalid mode data\n");
  5741. rc = -EFAULT;
  5742. goto error;
  5743. }
  5744. memcpy(sub_mode, &display_mode, sizeof(display_mode));
  5745. array_idx++;
  5746. if (!dfps_caps.dfps_support || !support_video_mode)
  5747. continue;
  5748. curr_refresh_rate = sub_mode->timing.refresh_rate;
  5749. sub_mode->timing.refresh_rate = dfps_caps.dfps_list[i];
  5750. dsi_display_get_dfps_timing(display, sub_mode,
  5751. curr_refresh_rate);
  5752. sub_mode->panel_mode_caps = DSI_OP_VIDEO_MODE;
  5753. }
  5754. end = array_idx;
  5755. _dsi_display_populate_bit_clks(display, start, end, &array_idx);
  5756. if (is_preferred) {
  5757. /* Set first timing sub mode as preferred mode */
  5758. display->modes[start].is_preferred = true;
  5759. }
  5760. }
  5761. exit:
  5762. *out_modes = display->modes;
  5763. rc = 0;
  5764. error:
  5765. if (rc)
  5766. kfree(display->modes);
  5767. mutex_unlock(&display->display_lock);
  5768. return rc;
  5769. }
  5770. int dsi_display_get_panel_vfp(void *dsi_display,
  5771. int h_active, int v_active)
  5772. {
  5773. int i, rc = 0;
  5774. u32 count, refresh_rate = 0;
  5775. struct dsi_dfps_capabilities dfps_caps;
  5776. struct dsi_display *display = (struct dsi_display *)dsi_display;
  5777. struct dsi_host_common_cfg *host;
  5778. if (!display || !display->panel)
  5779. return -EINVAL;
  5780. mutex_lock(&display->display_lock);
  5781. count = display->panel->num_display_modes;
  5782. if (display->panel->cur_mode)
  5783. refresh_rate = display->panel->cur_mode->timing.refresh_rate;
  5784. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  5785. if (dfps_caps.dfps_support)
  5786. refresh_rate = dfps_caps.max_refresh_rate;
  5787. if (!refresh_rate) {
  5788. mutex_unlock(&display->display_lock);
  5789. DSI_ERR("Null Refresh Rate\n");
  5790. return -EINVAL;
  5791. }
  5792. host = &display->panel->host_config;
  5793. if (host->split_link.split_link_enabled)
  5794. h_active *= host->split_link.num_sublinks;
  5795. else
  5796. h_active *= display->ctrl_count;
  5797. for (i = 0; i < count; i++) {
  5798. struct dsi_display_mode *m = &display->modes[i];
  5799. if (m && v_active == m->timing.v_active &&
  5800. h_active == m->timing.h_active &&
  5801. refresh_rate == m->timing.refresh_rate) {
  5802. rc = m->timing.v_front_porch;
  5803. break;
  5804. }
  5805. }
  5806. mutex_unlock(&display->display_lock);
  5807. return rc;
  5808. }
  5809. int dsi_display_get_default_lms(void *dsi_display, u32 *num_lm)
  5810. {
  5811. struct dsi_display *display = (struct dsi_display *)dsi_display;
  5812. u32 count, i;
  5813. int rc = 0;
  5814. *num_lm = 0;
  5815. mutex_lock(&display->display_lock);
  5816. count = display->panel->num_display_modes;
  5817. mutex_unlock(&display->display_lock);
  5818. if (!display->modes) {
  5819. struct dsi_display_mode *m;
  5820. rc = dsi_display_get_modes(display, &m);
  5821. if (rc)
  5822. return rc;
  5823. }
  5824. mutex_lock(&display->display_lock);
  5825. for (i = 0; i < count; i++) {
  5826. struct dsi_display_mode *m = &display->modes[i];
  5827. *num_lm = max(m->priv_info->topology.num_lm, *num_lm);
  5828. }
  5829. mutex_unlock(&display->display_lock);
  5830. return rc;
  5831. }
  5832. int dsi_display_get_qsync_min_fps(void *display_dsi, u32 mode_fps)
  5833. {
  5834. struct dsi_display *display = (struct dsi_display *)display_dsi;
  5835. struct dsi_panel *panel;
  5836. u32 i;
  5837. if (display == NULL || display->panel == NULL)
  5838. return -EINVAL;
  5839. panel = display->panel;
  5840. for (i = 0; i < panel->dfps_caps.dfps_list_len; i++) {
  5841. if (panel->dfps_caps.dfps_list[i] == mode_fps)
  5842. return panel->qsync_caps.qsync_min_fps_list[i];
  5843. }
  5844. SDE_EVT32(mode_fps);
  5845. DSI_DEBUG("Invalid mode_fps %d\n", mode_fps);
  5846. return -EINVAL;
  5847. }
  5848. int dsi_display_find_mode(struct dsi_display *display,
  5849. const struct dsi_display_mode *cmp,
  5850. struct dsi_display_mode **out_mode)
  5851. {
  5852. u32 count, i;
  5853. int rc;
  5854. if (!display || !out_mode)
  5855. return -EINVAL;
  5856. *out_mode = NULL;
  5857. mutex_lock(&display->display_lock);
  5858. count = display->panel->num_display_modes;
  5859. mutex_unlock(&display->display_lock);
  5860. if (!display->modes) {
  5861. struct dsi_display_mode *m;
  5862. rc = dsi_display_get_modes(display, &m);
  5863. if (rc)
  5864. return rc;
  5865. }
  5866. mutex_lock(&display->display_lock);
  5867. for (i = 0; i < count; i++) {
  5868. struct dsi_display_mode *m = &display->modes[i];
  5869. if (cmp->timing.v_active == m->timing.v_active &&
  5870. cmp->timing.h_active == m->timing.h_active &&
  5871. cmp->timing.refresh_rate == m->timing.refresh_rate) {
  5872. *out_mode = m;
  5873. rc = 0;
  5874. break;
  5875. }
  5876. }
  5877. mutex_unlock(&display->display_lock);
  5878. if (!*out_mode) {
  5879. DSI_ERR("[%s] failed to find mode for v_active %u h_active %u fps %u pclk %u\n",
  5880. display->name, cmp->timing.v_active,
  5881. cmp->timing.h_active, cmp->timing.refresh_rate,
  5882. cmp->pixel_clk_khz);
  5883. rc = -ENOENT;
  5884. }
  5885. return rc;
  5886. }
  5887. static inline bool dsi_display_mode_switch_dfps(struct dsi_display_mode *cur,
  5888. struct dsi_display_mode *adj)
  5889. {
  5890. /*
  5891. * If there is a change in the hfp or vfp of the current and adjoining
  5892. * mode,then either it is a dfps mode switch or dynamic clk change with
  5893. * constant fps.
  5894. */
  5895. if ((cur->timing.h_front_porch != adj->timing.h_front_porch) ||
  5896. (cur->timing.v_front_porch != adj->timing.v_front_porch))
  5897. return true;
  5898. else
  5899. return false;
  5900. }
  5901. /**
  5902. * dsi_display_validate_mode_change() - Validate mode change case.
  5903. * @display: DSI display handle.
  5904. * @cur_mode: Current mode.
  5905. * @adj_mode: Mode to be set.
  5906. * MSM_MODE_FLAG_SEAMLESS_VRR flag is set if there
  5907. * is change in hfp or vfp but vactive and hactive are same.
  5908. * DSI_MODE_FLAG_DYN_CLK flag is set if there
  5909. * is change in clk but vactive and hactive are same.
  5910. * Return: error code.
  5911. */
  5912. int dsi_display_validate_mode_change(struct dsi_display *display,
  5913. struct dsi_display_mode *cur_mode,
  5914. struct dsi_display_mode *adj_mode)
  5915. {
  5916. int rc = 0;
  5917. struct dsi_dfps_capabilities dfps_caps;
  5918. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5919. struct sde_connector *sde_conn;
  5920. if (!display || !adj_mode || !display->drm_conn) {
  5921. DSI_ERR("Invalid params\n");
  5922. return -EINVAL;
  5923. }
  5924. if (!display->panel || !display->panel->cur_mode) {
  5925. DSI_DEBUG("Current panel mode not set\n");
  5926. return rc;
  5927. }
  5928. if ((cur_mode->timing.v_active != adj_mode->timing.v_active) ||
  5929. (cur_mode->timing.h_active != adj_mode->timing.h_active)) {
  5930. DSI_DEBUG("Avoid VRR and POMS when resolution is changed\n");
  5931. return rc;
  5932. }
  5933. sde_conn = to_sde_connector(display->drm_conn);
  5934. mutex_lock(&display->display_lock);
  5935. if (sde_conn->expected_panel_mode == MSM_DISPLAY_VIDEO_MODE &&
  5936. display->config.panel_mode == DSI_OP_CMD_MODE) {
  5937. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_POMS_TO_VID;
  5938. DSI_DEBUG("Panel operating mode change to video detected\n");
  5939. } else if (sde_conn->expected_panel_mode == MSM_DISPLAY_CMD_MODE &&
  5940. display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  5941. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_POMS_TO_CMD;
  5942. DSI_DEBUG("Panel operating mode change to command detected\n");
  5943. } else {
  5944. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5945. /* dfps and dynamic clock with const fps use case */
  5946. if (dsi_display_mode_switch_dfps(cur_mode, adj_mode)) {
  5947. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  5948. if (dfps_caps.dfps_support ||
  5949. dyn_clk_caps->maintain_const_fps) {
  5950. DSI_DEBUG("Mode switch is seamless variable refresh\n");
  5951. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_VRR;
  5952. SDE_EVT32(SDE_EVTLOG_FUNC_CASE1,
  5953. cur_mode->timing.refresh_rate,
  5954. adj_mode->timing.refresh_rate,
  5955. cur_mode->timing.h_front_porch,
  5956. adj_mode->timing.h_front_porch,
  5957. cur_mode->timing.v_front_porch,
  5958. adj_mode->timing.v_front_porch);
  5959. }
  5960. }
  5961. /* dynamic clk change use case */
  5962. if (cur_mode->pixel_clk_khz != adj_mode->pixel_clk_khz) {
  5963. if (dyn_clk_caps->dyn_clk_support) {
  5964. DSI_DEBUG("dynamic clk change detected\n");
  5965. if ((adj_mode->dsi_mode_flags &
  5966. DSI_MODE_FLAG_VRR) &&
  5967. (!dyn_clk_caps->maintain_const_fps)) {
  5968. DSI_ERR("dfps and dyn clk not supported in same commit\n");
  5969. rc = -ENOTSUPP;
  5970. goto error;
  5971. }
  5972. adj_mode->dsi_mode_flags |=
  5973. DSI_MODE_FLAG_DYN_CLK;
  5974. SDE_EVT32(SDE_EVTLOG_FUNC_CASE2,
  5975. cur_mode->pixel_clk_khz,
  5976. adj_mode->pixel_clk_khz);
  5977. }
  5978. }
  5979. }
  5980. error:
  5981. mutex_unlock(&display->display_lock);
  5982. return rc;
  5983. }
  5984. int dsi_display_validate_mode(struct dsi_display *display,
  5985. struct dsi_display_mode *mode,
  5986. u32 flags)
  5987. {
  5988. int rc = 0;
  5989. int i;
  5990. struct dsi_display_ctrl *ctrl;
  5991. struct dsi_display_mode adj_mode;
  5992. if (!display || !mode) {
  5993. DSI_ERR("Invalid params\n");
  5994. return -EINVAL;
  5995. }
  5996. mutex_lock(&display->display_lock);
  5997. adj_mode = *mode;
  5998. adjust_timing_by_ctrl_count(display, &adj_mode);
  5999. rc = dsi_panel_validate_mode(display->panel, &adj_mode);
  6000. if (rc) {
  6001. DSI_ERR("[%s] panel mode validation failed, rc=%d\n",
  6002. display->name, rc);
  6003. goto error;
  6004. }
  6005. display_for_each_ctrl(i, display) {
  6006. ctrl = &display->ctrl[i];
  6007. rc = dsi_ctrl_validate_timing(ctrl->ctrl, &adj_mode.timing);
  6008. if (rc) {
  6009. DSI_ERR("[%s] ctrl mode validation failed, rc=%d\n",
  6010. display->name, rc);
  6011. goto error;
  6012. }
  6013. rc = dsi_phy_validate_mode(ctrl->phy, &adj_mode.timing);
  6014. if (rc) {
  6015. DSI_ERR("[%s] phy mode validation failed, rc=%d\n",
  6016. display->name, rc);
  6017. goto error;
  6018. }
  6019. }
  6020. if ((flags & DSI_VALIDATE_FLAG_ALLOW_ADJUST) &&
  6021. (mode->dsi_mode_flags & DSI_MODE_FLAG_SEAMLESS)) {
  6022. rc = dsi_display_validate_mode_seamless(display, mode);
  6023. if (rc) {
  6024. DSI_ERR("[%s] seamless not possible rc=%d\n",
  6025. display->name, rc);
  6026. goto error;
  6027. }
  6028. }
  6029. error:
  6030. mutex_unlock(&display->display_lock);
  6031. return rc;
  6032. }
  6033. int dsi_display_set_mode(struct dsi_display *display,
  6034. struct dsi_display_mode *mode,
  6035. u32 flags)
  6036. {
  6037. int rc = 0;
  6038. struct dsi_display_mode adj_mode;
  6039. struct dsi_mode_info timing;
  6040. if (!display || !mode || !display->panel) {
  6041. DSI_ERR("Invalid params\n");
  6042. return -EINVAL;
  6043. }
  6044. mutex_lock(&display->display_lock);
  6045. adj_mode = *mode;
  6046. timing = adj_mode.timing;
  6047. adjust_timing_by_ctrl_count(display, &adj_mode);
  6048. if (!display->panel->cur_mode) {
  6049. display->panel->cur_mode =
  6050. kzalloc(sizeof(struct dsi_display_mode), GFP_KERNEL);
  6051. if (!display->panel->cur_mode) {
  6052. rc = -ENOMEM;
  6053. goto error;
  6054. }
  6055. }
  6056. /*For dynamic DSI setting, use specified clock rate */
  6057. if (display->cached_clk_rate > 0)
  6058. adj_mode.priv_info->clk_rate_hz = display->cached_clk_rate;
  6059. rc = dsi_display_validate_mode_set(display, &adj_mode, flags);
  6060. if (rc) {
  6061. DSI_ERR("[%s] mode cannot be set\n", display->name);
  6062. goto error;
  6063. }
  6064. rc = dsi_display_set_mode_sub(display, &adj_mode, flags);
  6065. if (rc) {
  6066. DSI_ERR("[%s] failed to set mode\n", display->name);
  6067. goto error;
  6068. }
  6069. DSI_INFO("mdp_transfer_time=%d, hactive=%d, vactive=%d, fps=%d\n",
  6070. adj_mode.priv_info->mdp_transfer_time_us,
  6071. timing.h_active, timing.v_active, timing.refresh_rate);
  6072. SDE_EVT32(adj_mode.priv_info->mdp_transfer_time_us,
  6073. timing.h_active, timing.v_active, timing.refresh_rate);
  6074. memcpy(display->panel->cur_mode, &adj_mode, sizeof(adj_mode));
  6075. error:
  6076. mutex_unlock(&display->display_lock);
  6077. return rc;
  6078. }
  6079. int dsi_display_set_tpg_state(struct dsi_display *display, bool enable)
  6080. {
  6081. int rc = 0;
  6082. int i;
  6083. struct dsi_display_ctrl *ctrl;
  6084. if (!display) {
  6085. DSI_ERR("Invalid params\n");
  6086. return -EINVAL;
  6087. }
  6088. display_for_each_ctrl(i, display) {
  6089. ctrl = &display->ctrl[i];
  6090. rc = dsi_ctrl_set_tpg_state(ctrl->ctrl, enable);
  6091. if (rc) {
  6092. DSI_ERR("[%s] failed to set tpg state for host_%d\n",
  6093. display->name, i);
  6094. goto error;
  6095. }
  6096. }
  6097. display->is_tpg_enabled = enable;
  6098. error:
  6099. return rc;
  6100. }
  6101. static int dsi_display_pre_switch(struct dsi_display *display)
  6102. {
  6103. int rc = 0;
  6104. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6105. DSI_CORE_CLK, DSI_CLK_ON);
  6106. if (rc) {
  6107. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  6108. display->name, rc);
  6109. goto error;
  6110. }
  6111. rc = dsi_display_ctrl_update(display);
  6112. if (rc) {
  6113. DSI_ERR("[%s] failed to update DSI controller, rc=%d\n",
  6114. display->name, rc);
  6115. goto error_ctrl_clk_off;
  6116. }
  6117. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6118. DSI_LINK_CLK, DSI_CLK_ON);
  6119. if (rc) {
  6120. DSI_ERR("[%s] failed to enable DSI link clocks, rc=%d\n",
  6121. display->name, rc);
  6122. goto error_ctrl_deinit;
  6123. }
  6124. goto error;
  6125. error_ctrl_deinit:
  6126. (void)dsi_display_ctrl_deinit(display);
  6127. error_ctrl_clk_off:
  6128. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  6129. DSI_CORE_CLK, DSI_CLK_OFF);
  6130. error:
  6131. return rc;
  6132. }
  6133. static bool _dsi_display_validate_host_state(struct dsi_display *display)
  6134. {
  6135. int i;
  6136. struct dsi_display_ctrl *ctrl;
  6137. display_for_each_ctrl(i, display) {
  6138. ctrl = &display->ctrl[i];
  6139. if (!ctrl->ctrl)
  6140. continue;
  6141. if (!dsi_ctrl_validate_host_state(ctrl->ctrl))
  6142. return false;
  6143. }
  6144. return true;
  6145. }
  6146. static void dsi_display_handle_fifo_underflow(struct work_struct *work)
  6147. {
  6148. struct dsi_display *display = NULL;
  6149. display = container_of(work, struct dsi_display, fifo_underflow_work);
  6150. if (!display || !display->panel ||
  6151. atomic_read(&display->panel->esd_recovery_pending)) {
  6152. DSI_DEBUG("Invalid recovery use case\n");
  6153. return;
  6154. }
  6155. mutex_lock(&display->display_lock);
  6156. if (!_dsi_display_validate_host_state(display)) {
  6157. mutex_unlock(&display->display_lock);
  6158. return;
  6159. }
  6160. DSI_INFO("handle DSI FIFO underflow error\n");
  6161. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6162. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6163. DSI_ALL_CLKS, DSI_CLK_ON);
  6164. dsi_display_soft_reset(display);
  6165. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6166. DSI_ALL_CLKS, DSI_CLK_OFF);
  6167. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6168. mutex_unlock(&display->display_lock);
  6169. }
  6170. static void dsi_display_handle_fifo_overflow(struct work_struct *work)
  6171. {
  6172. struct dsi_display *display = NULL;
  6173. struct dsi_display_ctrl *ctrl;
  6174. int i, rc;
  6175. int mask = BIT(20); /* clock lane */
  6176. int (*cb_func)(void *event_usr_ptr,
  6177. uint32_t event_idx, uint32_t instance_idx,
  6178. uint32_t data0, uint32_t data1,
  6179. uint32_t data2, uint32_t data3);
  6180. void *data;
  6181. u32 version = 0;
  6182. display = container_of(work, struct dsi_display, fifo_overflow_work);
  6183. if (!display || !display->panel ||
  6184. (display->panel->panel_mode != DSI_OP_VIDEO_MODE) ||
  6185. atomic_read(&display->panel->esd_recovery_pending)) {
  6186. DSI_DEBUG("Invalid recovery use case\n");
  6187. return;
  6188. }
  6189. mutex_lock(&display->display_lock);
  6190. if (!_dsi_display_validate_host_state(display)) {
  6191. mutex_unlock(&display->display_lock);
  6192. return;
  6193. }
  6194. DSI_INFO("handle DSI FIFO overflow error\n");
  6195. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6196. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6197. DSI_ALL_CLKS, DSI_CLK_ON);
  6198. /*
  6199. * below recovery sequence is not applicable to
  6200. * hw version 2.0.0, 2.1.0 and 2.2.0, so return early.
  6201. */
  6202. ctrl = &display->ctrl[display->clk_master_idx];
  6203. version = dsi_ctrl_get_hw_version(ctrl->ctrl);
  6204. if (!version || (version < 0x20020001))
  6205. goto end;
  6206. /* reset ctrl and lanes */
  6207. display_for_each_ctrl(i, display) {
  6208. ctrl = &display->ctrl[i];
  6209. rc = dsi_ctrl_reset(ctrl->ctrl, mask);
  6210. rc = dsi_phy_lane_reset(ctrl->phy);
  6211. }
  6212. /* wait for display line count to be in active area */
  6213. ctrl = &display->ctrl[display->clk_master_idx];
  6214. if (ctrl->ctrl->recovery_cb.event_cb) {
  6215. cb_func = ctrl->ctrl->recovery_cb.event_cb;
  6216. data = ctrl->ctrl->recovery_cb.event_usr_ptr;
  6217. rc = cb_func(data, SDE_CONN_EVENT_VID_FIFO_OVERFLOW,
  6218. display->clk_master_idx, 0, 0, 0, 0);
  6219. if (rc < 0) {
  6220. DSI_DEBUG("sde callback failed\n");
  6221. goto end;
  6222. }
  6223. }
  6224. /* Enable Video mode for DSI controller */
  6225. display_for_each_ctrl(i, display) {
  6226. ctrl = &display->ctrl[i];
  6227. dsi_ctrl_vid_engine_en(ctrl->ctrl, true);
  6228. }
  6229. /*
  6230. * Add sufficient delay to make sure
  6231. * pixel transmission has started
  6232. */
  6233. udelay(200);
  6234. end:
  6235. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6236. DSI_ALL_CLKS, DSI_CLK_OFF);
  6237. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6238. mutex_unlock(&display->display_lock);
  6239. }
  6240. static void dsi_display_handle_lp_rx_timeout(struct work_struct *work)
  6241. {
  6242. struct dsi_display *display = NULL;
  6243. struct dsi_display_ctrl *ctrl;
  6244. int i, rc;
  6245. int mask = (BIT(20) | (0xF << 16)); /* clock lane and 4 data lane */
  6246. int (*cb_func)(void *event_usr_ptr,
  6247. uint32_t event_idx, uint32_t instance_idx,
  6248. uint32_t data0, uint32_t data1,
  6249. uint32_t data2, uint32_t data3);
  6250. void *data;
  6251. u32 version = 0;
  6252. display = container_of(work, struct dsi_display, lp_rx_timeout_work);
  6253. if (!display || !display->panel ||
  6254. (display->panel->panel_mode != DSI_OP_VIDEO_MODE) ||
  6255. atomic_read(&display->panel->esd_recovery_pending)) {
  6256. DSI_DEBUG("Invalid recovery use case\n");
  6257. return;
  6258. }
  6259. mutex_lock(&display->display_lock);
  6260. if (!_dsi_display_validate_host_state(display)) {
  6261. mutex_unlock(&display->display_lock);
  6262. return;
  6263. }
  6264. DSI_INFO("handle DSI LP RX Timeout error\n");
  6265. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6266. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6267. DSI_ALL_CLKS, DSI_CLK_ON);
  6268. /*
  6269. * below recovery sequence is not applicable to
  6270. * hw version 2.0.0, 2.1.0 and 2.2.0, so return early.
  6271. */
  6272. ctrl = &display->ctrl[display->clk_master_idx];
  6273. version = dsi_ctrl_get_hw_version(ctrl->ctrl);
  6274. if (!version || (version < 0x20020001))
  6275. goto end;
  6276. /* reset ctrl and lanes */
  6277. display_for_each_ctrl(i, display) {
  6278. ctrl = &display->ctrl[i];
  6279. rc = dsi_ctrl_reset(ctrl->ctrl, mask);
  6280. rc = dsi_phy_lane_reset(ctrl->phy);
  6281. }
  6282. ctrl = &display->ctrl[display->clk_master_idx];
  6283. if (ctrl->ctrl->recovery_cb.event_cb) {
  6284. cb_func = ctrl->ctrl->recovery_cb.event_cb;
  6285. data = ctrl->ctrl->recovery_cb.event_usr_ptr;
  6286. rc = cb_func(data, SDE_CONN_EVENT_VID_FIFO_OVERFLOW,
  6287. display->clk_master_idx, 0, 0, 0, 0);
  6288. if (rc < 0) {
  6289. DSI_DEBUG("Target is in suspend/shutdown\n");
  6290. goto end;
  6291. }
  6292. }
  6293. /* Enable Video mode for DSI controller */
  6294. display_for_each_ctrl(i, display) {
  6295. ctrl = &display->ctrl[i];
  6296. dsi_ctrl_vid_engine_en(ctrl->ctrl, true);
  6297. }
  6298. /*
  6299. * Add sufficient delay to make sure
  6300. * pixel transmission as started
  6301. */
  6302. udelay(200);
  6303. end:
  6304. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6305. DSI_ALL_CLKS, DSI_CLK_OFF);
  6306. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6307. mutex_unlock(&display->display_lock);
  6308. }
  6309. static int dsi_display_cb_error_handler(void *data,
  6310. uint32_t event_idx, uint32_t instance_idx,
  6311. uint32_t data0, uint32_t data1,
  6312. uint32_t data2, uint32_t data3)
  6313. {
  6314. struct dsi_display *display = data;
  6315. if (!display || !(display->err_workq))
  6316. return -EINVAL;
  6317. switch (event_idx) {
  6318. case DSI_FIFO_UNDERFLOW:
  6319. queue_work(display->err_workq, &display->fifo_underflow_work);
  6320. break;
  6321. case DSI_FIFO_OVERFLOW:
  6322. queue_work(display->err_workq, &display->fifo_overflow_work);
  6323. break;
  6324. case DSI_LP_Rx_TIMEOUT:
  6325. queue_work(display->err_workq, &display->lp_rx_timeout_work);
  6326. break;
  6327. default:
  6328. DSI_WARN("unhandled error interrupt: %d\n", event_idx);
  6329. break;
  6330. }
  6331. return 0;
  6332. }
  6333. static void dsi_display_register_error_handler(struct dsi_display *display)
  6334. {
  6335. int i = 0;
  6336. struct dsi_display_ctrl *ctrl;
  6337. struct dsi_event_cb_info event_info;
  6338. if (!display)
  6339. return;
  6340. display->err_workq = create_singlethread_workqueue("dsi_err_workq");
  6341. if (!display->err_workq) {
  6342. DSI_ERR("failed to create dsi workq!\n");
  6343. return;
  6344. }
  6345. INIT_WORK(&display->fifo_underflow_work,
  6346. dsi_display_handle_fifo_underflow);
  6347. INIT_WORK(&display->fifo_overflow_work,
  6348. dsi_display_handle_fifo_overflow);
  6349. INIT_WORK(&display->lp_rx_timeout_work,
  6350. dsi_display_handle_lp_rx_timeout);
  6351. memset(&event_info, 0, sizeof(event_info));
  6352. event_info.event_cb = dsi_display_cb_error_handler;
  6353. event_info.event_usr_ptr = display;
  6354. display_for_each_ctrl(i, display) {
  6355. ctrl = &display->ctrl[i];
  6356. ctrl->ctrl->irq_info.irq_err_cb = event_info;
  6357. }
  6358. }
  6359. static void dsi_display_unregister_error_handler(struct dsi_display *display)
  6360. {
  6361. int i = 0;
  6362. struct dsi_display_ctrl *ctrl;
  6363. if (!display)
  6364. return;
  6365. display_for_each_ctrl(i, display) {
  6366. ctrl = &display->ctrl[i];
  6367. memset(&ctrl->ctrl->irq_info.irq_err_cb,
  6368. 0, sizeof(struct dsi_event_cb_info));
  6369. }
  6370. if (display->err_workq) {
  6371. destroy_workqueue(display->err_workq);
  6372. display->err_workq = NULL;
  6373. }
  6374. }
  6375. int dsi_display_prepare(struct dsi_display *display)
  6376. {
  6377. int rc = 0;
  6378. struct dsi_display_mode *mode;
  6379. if (!display) {
  6380. DSI_ERR("Invalid params\n");
  6381. return -EINVAL;
  6382. }
  6383. if (!display->panel->cur_mode) {
  6384. DSI_ERR("no valid mode set for the display\n");
  6385. return -EINVAL;
  6386. }
  6387. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6388. mutex_lock(&display->display_lock);
  6389. mode = display->panel->cur_mode;
  6390. dsi_display_set_ctrl_esd_check_flag(display, false);
  6391. /* Set up ctrl isr before enabling core clk */
  6392. if (!display->trusted_vm_env)
  6393. dsi_display_ctrl_isr_configure(display, true);
  6394. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  6395. if (display->is_cont_splash_enabled &&
  6396. display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6397. DSI_ERR("DMS not supported on first frame\n");
  6398. rc = -EINVAL;
  6399. goto error;
  6400. }
  6401. if (!is_skip_op_required(display)) {
  6402. /* update dsi ctrl for new mode */
  6403. rc = dsi_display_pre_switch(display);
  6404. if (rc)
  6405. DSI_ERR("[%s] panel pre-switch failed, rc=%d\n",
  6406. display->name, rc);
  6407. goto error;
  6408. }
  6409. }
  6410. if (!display->poms_pending &&
  6411. (!is_skip_op_required(display))) {
  6412. /*
  6413. * For continuous splash/trusted vm, we skip panel
  6414. * pre prepare since the regulator vote is already
  6415. * taken care in splash resource init
  6416. */
  6417. rc = dsi_panel_pre_prepare(display->panel);
  6418. if (rc) {
  6419. DSI_ERR("[%s] panel pre-prepare failed, rc=%d\n",
  6420. display->name, rc);
  6421. goto error;
  6422. }
  6423. }
  6424. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6425. DSI_CORE_CLK, DSI_CLK_ON);
  6426. if (rc) {
  6427. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  6428. display->name, rc);
  6429. goto error_panel_post_unprep;
  6430. }
  6431. /*
  6432. * If ULPS during suspend feature is enabled, then DSI PHY was
  6433. * left on during suspend. In this case, we do not need to reset/init
  6434. * PHY. This would have already been done when the CORE clocks are
  6435. * turned on. However, if cont splash is disabled, the first time DSI
  6436. * is powered on, phy init needs to be done unconditionally.
  6437. */
  6438. if (!display->panel->ulps_suspend_enabled || !display->ulps_enabled) {
  6439. rc = dsi_display_phy_sw_reset(display);
  6440. if (rc) {
  6441. DSI_ERR("[%s] failed to reset phy, rc=%d\n",
  6442. display->name, rc);
  6443. goto error_ctrl_clk_off;
  6444. }
  6445. rc = dsi_display_phy_enable(display);
  6446. if (rc) {
  6447. DSI_ERR("[%s] failed to enable DSI PHY, rc=%d\n",
  6448. display->name, rc);
  6449. goto error_ctrl_clk_off;
  6450. }
  6451. }
  6452. rc = dsi_display_ctrl_init(display);
  6453. if (rc) {
  6454. DSI_ERR("[%s] failed to setup DSI controller, rc=%d\n",
  6455. display->name, rc);
  6456. goto error_phy_disable;
  6457. }
  6458. /* Set up DSI ERROR event callback */
  6459. dsi_display_register_error_handler(display);
  6460. rc = dsi_display_ctrl_host_enable(display);
  6461. if (rc) {
  6462. DSI_ERR("[%s] failed to enable DSI host, rc=%d\n",
  6463. display->name, rc);
  6464. goto error_ctrl_deinit;
  6465. }
  6466. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6467. DSI_LINK_CLK, DSI_CLK_ON);
  6468. if (rc) {
  6469. DSI_ERR("[%s] failed to enable DSI link clocks, rc=%d\n",
  6470. display->name, rc);
  6471. goto error_host_engine_off;
  6472. }
  6473. if (!is_skip_op_required(display)) {
  6474. /*
  6475. * For continuous splash/trusted vm, skip panel prepare and
  6476. * ctl reset since the pnael and ctrl is already in active
  6477. * state and panel on commands are not needed
  6478. */
  6479. rc = dsi_display_soft_reset(display);
  6480. if (rc) {
  6481. DSI_ERR("[%s] failed soft reset, rc=%d\n",
  6482. display->name, rc);
  6483. goto error_ctrl_link_off;
  6484. }
  6485. if (!display->poms_pending) {
  6486. rc = dsi_panel_prepare(display->panel);
  6487. if (rc) {
  6488. DSI_ERR("[%s] panel prepare failed, rc=%d\n",
  6489. display->name, rc);
  6490. goto error_ctrl_link_off;
  6491. }
  6492. }
  6493. }
  6494. goto error;
  6495. error_ctrl_link_off:
  6496. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  6497. DSI_LINK_CLK, DSI_CLK_OFF);
  6498. error_host_engine_off:
  6499. (void)dsi_display_ctrl_host_disable(display);
  6500. error_ctrl_deinit:
  6501. (void)dsi_display_ctrl_deinit(display);
  6502. error_phy_disable:
  6503. (void)dsi_display_phy_disable(display);
  6504. error_ctrl_clk_off:
  6505. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  6506. DSI_CORE_CLK, DSI_CLK_OFF);
  6507. error_panel_post_unprep:
  6508. (void)dsi_panel_post_unprepare(display->panel);
  6509. error:
  6510. mutex_unlock(&display->display_lock);
  6511. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6512. return rc;
  6513. }
  6514. static int dsi_display_calc_ctrl_roi(const struct dsi_display *display,
  6515. const struct dsi_display_ctrl *ctrl,
  6516. const struct msm_roi_list *req_rois,
  6517. struct dsi_rect *out_roi)
  6518. {
  6519. const struct dsi_rect *bounds = &ctrl->ctrl->mode_bounds;
  6520. struct dsi_display_mode *cur_mode;
  6521. struct msm_roi_caps *roi_caps;
  6522. struct dsi_rect req_roi = { 0 };
  6523. int rc = 0;
  6524. cur_mode = display->panel->cur_mode;
  6525. if (!cur_mode)
  6526. return 0;
  6527. roi_caps = &cur_mode->priv_info->roi_caps;
  6528. if (req_rois->num_rects > roi_caps->num_roi) {
  6529. DSI_ERR("request for %d rois greater than max %d\n",
  6530. req_rois->num_rects,
  6531. roi_caps->num_roi);
  6532. rc = -EINVAL;
  6533. goto exit;
  6534. }
  6535. /**
  6536. * if no rois, user wants to reset back to full resolution
  6537. * note: h_active is already divided by ctrl_count
  6538. */
  6539. if (!req_rois->num_rects) {
  6540. *out_roi = *bounds;
  6541. goto exit;
  6542. }
  6543. /* intersect with the bounds */
  6544. req_roi.x = req_rois->roi[0].x1;
  6545. req_roi.y = req_rois->roi[0].y1;
  6546. req_roi.w = req_rois->roi[0].x2 - req_rois->roi[0].x1;
  6547. req_roi.h = req_rois->roi[0].y2 - req_rois->roi[0].y1;
  6548. dsi_rect_intersect(&req_roi, bounds, out_roi);
  6549. exit:
  6550. /* adjust the ctrl origin to be top left within the ctrl */
  6551. out_roi->x = out_roi->x - bounds->x;
  6552. DSI_DEBUG("ctrl%d:%d: req (%d,%d,%d,%d) bnd (%d,%d,%d,%d) out (%d,%d,%d,%d)\n",
  6553. ctrl->dsi_ctrl_idx, ctrl->ctrl->cell_index,
  6554. req_roi.x, req_roi.y, req_roi.w, req_roi.h,
  6555. bounds->x, bounds->y, bounds->w, bounds->h,
  6556. out_roi->x, out_roi->y, out_roi->w, out_roi->h);
  6557. return rc;
  6558. }
  6559. static int dsi_display_qsync(struct dsi_display *display, bool enable)
  6560. {
  6561. int i;
  6562. int rc = 0;
  6563. if (!display->panel->qsync_caps.qsync_min_fps) {
  6564. DSI_ERR("%s:ERROR: qsync set, but no fps\n", __func__);
  6565. return 0;
  6566. }
  6567. mutex_lock(&display->display_lock);
  6568. display_for_each_ctrl(i, display) {
  6569. if (enable) {
  6570. /* send the commands to enable qsync */
  6571. rc = dsi_panel_send_qsync_on_dcs(display->panel, i);
  6572. if (rc) {
  6573. DSI_ERR("fail qsync ON cmds rc:%d\n", rc);
  6574. goto exit;
  6575. }
  6576. } else {
  6577. /* send the commands to enable qsync */
  6578. rc = dsi_panel_send_qsync_off_dcs(display->panel, i);
  6579. if (rc) {
  6580. DSI_ERR("fail qsync OFF cmds rc:%d\n", rc);
  6581. goto exit;
  6582. }
  6583. }
  6584. dsi_ctrl_setup_avr(display->ctrl[i].ctrl, enable);
  6585. }
  6586. exit:
  6587. SDE_EVT32(enable, display->panel->qsync_caps.qsync_min_fps, rc);
  6588. mutex_unlock(&display->display_lock);
  6589. return rc;
  6590. }
  6591. static int dsi_display_set_roi(struct dsi_display *display,
  6592. struct msm_roi_list *rois)
  6593. {
  6594. struct dsi_display_mode *cur_mode;
  6595. struct msm_roi_caps *roi_caps;
  6596. int rc = 0;
  6597. int i;
  6598. if (!display || !rois || !display->panel)
  6599. return -EINVAL;
  6600. cur_mode = display->panel->cur_mode;
  6601. if (!cur_mode)
  6602. return 0;
  6603. roi_caps = &cur_mode->priv_info->roi_caps;
  6604. if (!roi_caps->enabled)
  6605. return 0;
  6606. display_for_each_ctrl(i, display) {
  6607. struct dsi_display_ctrl *ctrl = &display->ctrl[i];
  6608. struct dsi_rect ctrl_roi;
  6609. bool changed = false;
  6610. rc = dsi_display_calc_ctrl_roi(display, ctrl, rois, &ctrl_roi);
  6611. if (rc) {
  6612. DSI_ERR("dsi_display_calc_ctrl_roi failed rc %d\n", rc);
  6613. return rc;
  6614. }
  6615. rc = dsi_ctrl_set_roi(ctrl->ctrl, &ctrl_roi, &changed);
  6616. if (rc) {
  6617. DSI_ERR("dsi_ctrl_set_roi failed rc %d\n", rc);
  6618. return rc;
  6619. }
  6620. if (!changed)
  6621. continue;
  6622. /* send the new roi to the panel via dcs commands */
  6623. rc = dsi_panel_send_roi_dcs(display->panel, i, &ctrl_roi);
  6624. if (rc) {
  6625. DSI_ERR("dsi_panel_set_roi failed rc %d\n", rc);
  6626. return rc;
  6627. }
  6628. /* re-program the ctrl with the timing based on the new roi */
  6629. rc = dsi_ctrl_timing_setup(ctrl->ctrl);
  6630. if (rc) {
  6631. DSI_ERR("dsi_ctrl_setup failed rc %d\n", rc);
  6632. return rc;
  6633. }
  6634. }
  6635. return rc;
  6636. }
  6637. int dsi_display_pre_kickoff(struct drm_connector *connector,
  6638. struct dsi_display *display,
  6639. struct msm_display_kickoff_params *params)
  6640. {
  6641. int rc = 0, ret = 0;
  6642. int i;
  6643. /* check and setup MISR */
  6644. if (display->misr_enable)
  6645. _dsi_display_setup_misr(display);
  6646. /* dynamic DSI clock setting */
  6647. if (atomic_read(&display->clkrate_change_pending)) {
  6648. mutex_lock(&display->display_lock);
  6649. /*
  6650. * acquire panel_lock to make sure no commands are in progress
  6651. */
  6652. dsi_panel_acquire_panel_lock(display->panel);
  6653. /*
  6654. * Wait for DSI command engine not to be busy sending data
  6655. * from display engine.
  6656. * If waiting fails, return "rc" instead of below "ret" so as
  6657. * not to impact DRM commit. The clock updating would be
  6658. * deferred to the next DRM commit.
  6659. */
  6660. display_for_each_ctrl(i, display) {
  6661. struct dsi_ctrl *ctrl = display->ctrl[i].ctrl;
  6662. ret = dsi_ctrl_wait_for_cmd_mode_mdp_idle(ctrl);
  6663. if (ret)
  6664. goto wait_failure;
  6665. }
  6666. /*
  6667. * Don't check the return value so as not to impact DRM commit
  6668. * when error occurs.
  6669. */
  6670. (void)dsi_display_force_update_dsi_clk(display);
  6671. wait_failure:
  6672. /* release panel_lock */
  6673. dsi_panel_release_panel_lock(display->panel);
  6674. mutex_unlock(&display->display_lock);
  6675. }
  6676. if (!ret)
  6677. rc = dsi_display_set_roi(display, params->rois);
  6678. return rc;
  6679. }
  6680. int dsi_display_config_ctrl_for_cont_splash(struct dsi_display *display)
  6681. {
  6682. int rc = 0;
  6683. if (!display || !display->panel) {
  6684. DSI_ERR("Invalid params\n");
  6685. return -EINVAL;
  6686. }
  6687. if (!display->panel->cur_mode) {
  6688. DSI_ERR("no valid mode set for the display\n");
  6689. return -EINVAL;
  6690. }
  6691. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6692. rc = dsi_display_vid_engine_enable(display);
  6693. if (rc) {
  6694. DSI_ERR("[%s]failed to enable DSI video engine, rc=%d\n",
  6695. display->name, rc);
  6696. goto error_out;
  6697. }
  6698. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  6699. rc = dsi_display_cmd_engine_enable(display);
  6700. if (rc) {
  6701. DSI_ERR("[%s]failed to enable DSI cmd engine, rc=%d\n",
  6702. display->name, rc);
  6703. goto error_out;
  6704. }
  6705. } else {
  6706. DSI_ERR("[%s] Invalid configuration\n", display->name);
  6707. rc = -EINVAL;
  6708. }
  6709. error_out:
  6710. return rc;
  6711. }
  6712. int dsi_display_pre_commit(void *display,
  6713. struct msm_display_conn_params *params)
  6714. {
  6715. bool enable = false;
  6716. int rc = 0;
  6717. if (!display || !params) {
  6718. pr_err("Invalid params\n");
  6719. return -EINVAL;
  6720. }
  6721. if (params->qsync_update) {
  6722. enable = (params->qsync_mode > 0) ? true : false;
  6723. rc = dsi_display_qsync(display, enable);
  6724. if (rc)
  6725. pr_err("%s failed to send qsync commands\n",
  6726. __func__);
  6727. SDE_EVT32(params->qsync_mode, rc);
  6728. }
  6729. return rc;
  6730. }
  6731. static void dsi_display_panel_id_notification(struct dsi_display *display)
  6732. {
  6733. if (display->panel_id != ~0x0 &&
  6734. display->ctrl[0].ctrl->panel_id_cb.event_cb) {
  6735. display->ctrl[0].ctrl->panel_id_cb.event_cb(
  6736. display->ctrl[0].ctrl->panel_id_cb.event_usr_ptr,
  6737. display->ctrl[0].ctrl->panel_id_cb.event_idx,
  6738. 0, ((display->panel_id & 0xffffffff00000000) >> 32),
  6739. (display->panel_id & 0xffffffff), 0, 0);
  6740. }
  6741. }
  6742. int dsi_display_enable(struct dsi_display *display)
  6743. {
  6744. int rc = 0;
  6745. struct dsi_display_mode *mode;
  6746. if (!display || !display->panel) {
  6747. DSI_ERR("Invalid params\n");
  6748. return -EINVAL;
  6749. }
  6750. if (!display->panel->cur_mode) {
  6751. DSI_ERR("no valid mode set for the display\n");
  6752. return -EINVAL;
  6753. }
  6754. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6755. /*
  6756. * Engine states and panel states are populated during splash
  6757. * resource/trusted vm and hence we return early
  6758. */
  6759. if (is_skip_op_required(display)) {
  6760. dsi_display_config_ctrl_for_cont_splash(display);
  6761. rc = dsi_display_splash_res_cleanup(display);
  6762. if (rc) {
  6763. DSI_ERR("Continuous splash res cleanup failed, rc=%d\n",
  6764. rc);
  6765. return -EINVAL;
  6766. }
  6767. display->panel->panel_initialized = true;
  6768. DSI_DEBUG("cont splash enabled, display enable not required\n");
  6769. dsi_display_panel_id_notification(display);
  6770. return 0;
  6771. }
  6772. mutex_lock(&display->display_lock);
  6773. mode = display->panel->cur_mode;
  6774. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  6775. rc = dsi_panel_post_switch(display->panel);
  6776. if (rc) {
  6777. DSI_ERR("[%s] failed to switch DSI panel mode, rc=%d\n",
  6778. display->name, rc);
  6779. goto error;
  6780. }
  6781. } else if (!display->poms_pending) {
  6782. rc = dsi_panel_enable(display->panel);
  6783. if (rc) {
  6784. DSI_ERR("[%s] failed to enable DSI panel, rc=%d\n",
  6785. display->name, rc);
  6786. goto error;
  6787. }
  6788. }
  6789. dsi_display_panel_id_notification(display);
  6790. /* Block sending pps command if modeset is due to fps difference */
  6791. if ((mode->priv_info->dsc_enabled ||
  6792. mode->priv_info->vdc_enabled) &&
  6793. !(mode->dsi_mode_flags & DSI_MODE_FLAG_DMS_FPS)) {
  6794. rc = dsi_panel_update_pps(display->panel);
  6795. if (rc) {
  6796. DSI_ERR("[%s] panel pps cmd update failed, rc=%d\n",
  6797. display->name, rc);
  6798. goto error;
  6799. }
  6800. }
  6801. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  6802. rc = dsi_panel_switch(display->panel);
  6803. if (rc)
  6804. DSI_ERR("[%s] failed to switch DSI panel mode, rc=%d\n",
  6805. display->name, rc);
  6806. goto error;
  6807. }
  6808. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6809. DSI_DEBUG("%s:enable video timing eng\n", __func__);
  6810. rc = dsi_display_vid_engine_enable(display);
  6811. if (rc) {
  6812. DSI_ERR("[%s]failed to enable DSI video engine, rc=%d\n",
  6813. display->name, rc);
  6814. goto error_disable_panel;
  6815. }
  6816. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  6817. DSI_DEBUG("%s:enable command timing eng\n", __func__);
  6818. rc = dsi_display_cmd_engine_enable(display);
  6819. if (rc) {
  6820. DSI_ERR("[%s]failed to enable DSI cmd engine, rc=%d\n",
  6821. display->name, rc);
  6822. goto error_disable_panel;
  6823. }
  6824. } else {
  6825. DSI_ERR("[%s] Invalid configuration\n", display->name);
  6826. rc = -EINVAL;
  6827. goto error_disable_panel;
  6828. }
  6829. goto error;
  6830. error_disable_panel:
  6831. (void)dsi_panel_disable(display->panel);
  6832. error:
  6833. mutex_unlock(&display->display_lock);
  6834. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6835. return rc;
  6836. }
  6837. int dsi_display_post_enable(struct dsi_display *display)
  6838. {
  6839. int rc = 0;
  6840. if (!display) {
  6841. DSI_ERR("Invalid params\n");
  6842. return -EINVAL;
  6843. }
  6844. mutex_lock(&display->display_lock);
  6845. if (display->panel->cur_mode->dsi_mode_flags &
  6846. DSI_MODE_FLAG_POMS_TO_CMD) {
  6847. dsi_panel_switch_cmd_mode_in(display->panel);
  6848. } else if (display->panel->cur_mode->dsi_mode_flags &
  6849. DSI_MODE_FLAG_POMS_TO_VID)
  6850. dsi_panel_switch_video_mode_in(display->panel);
  6851. else {
  6852. rc = dsi_panel_post_enable(display->panel);
  6853. if (rc)
  6854. DSI_ERR("[%s] panel post-enable failed, rc=%d\n",
  6855. display->name, rc);
  6856. }
  6857. /* remove the clk vote for CMD mode panels */
  6858. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  6859. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6860. DSI_ALL_CLKS, DSI_CLK_OFF);
  6861. mutex_unlock(&display->display_lock);
  6862. return rc;
  6863. }
  6864. int dsi_display_pre_disable(struct dsi_display *display)
  6865. {
  6866. int rc = 0;
  6867. if (!display) {
  6868. DSI_ERR("Invalid params\n");
  6869. return -EINVAL;
  6870. }
  6871. mutex_lock(&display->display_lock);
  6872. /* enable the clk vote for CMD mode panels */
  6873. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  6874. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6875. DSI_ALL_CLKS, DSI_CLK_ON);
  6876. if (display->poms_pending) {
  6877. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  6878. dsi_panel_switch_cmd_mode_out(display->panel);
  6879. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6880. /*
  6881. * Add unbalanced vote for clock & cmd engine to enable
  6882. * async trigger of pre video to cmd mode switch.
  6883. */
  6884. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6885. DSI_ALL_CLKS, DSI_CLK_ON);
  6886. if (rc) {
  6887. DSI_ERR("[%s]failed to enable all clocks,rc=%d",
  6888. display->name, rc);
  6889. goto exit;
  6890. }
  6891. rc = dsi_display_cmd_engine_enable(display);
  6892. if (rc) {
  6893. DSI_ERR("[%s]failed to enable cmd engine,rc=%d",
  6894. display->name, rc);
  6895. goto error_disable_clks;
  6896. }
  6897. dsi_panel_switch_video_mode_out(display->panel);
  6898. }
  6899. } else {
  6900. rc = dsi_panel_pre_disable(display->panel);
  6901. if (rc)
  6902. DSI_ERR("[%s] panel pre-disable failed, rc=%d\n",
  6903. display->name, rc);
  6904. }
  6905. goto exit;
  6906. error_disable_clks:
  6907. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6908. DSI_ALL_CLKS, DSI_CLK_OFF);
  6909. if (rc)
  6910. DSI_ERR("[%s] failed to disable all DSI clocks, rc=%d\n",
  6911. display->name, rc);
  6912. exit:
  6913. mutex_unlock(&display->display_lock);
  6914. return rc;
  6915. }
  6916. static void dsi_display_handle_poms_te(struct work_struct *work)
  6917. {
  6918. struct dsi_display *display = NULL;
  6919. struct delayed_work *dw = to_delayed_work(work);
  6920. struct mipi_dsi_device *dsi = NULL;
  6921. struct dsi_panel *panel = NULL;
  6922. int rc = 0;
  6923. display = container_of(dw, struct dsi_display, poms_te_work);
  6924. if (!display || !display->panel) {
  6925. DSI_ERR("Invalid params\n");
  6926. return;
  6927. }
  6928. panel = display->panel;
  6929. mutex_lock(&panel->panel_lock);
  6930. if (!dsi_panel_initialized(panel)) {
  6931. rc = -EINVAL;
  6932. goto error;
  6933. }
  6934. dsi = &panel->mipi_device;
  6935. rc = mipi_dsi_dcs_set_tear_off(dsi);
  6936. error:
  6937. mutex_unlock(&panel->panel_lock);
  6938. if (rc < 0)
  6939. DSI_ERR("failed to set tear off\n");
  6940. }
  6941. int dsi_display_disable(struct dsi_display *display)
  6942. {
  6943. int rc = 0;
  6944. if (!display) {
  6945. DSI_ERR("Invalid params\n");
  6946. return -EINVAL;
  6947. }
  6948. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6949. mutex_lock(&display->display_lock);
  6950. /* cancel delayed work */
  6951. if (display->poms_pending &&
  6952. display->panel->poms_align_vsync)
  6953. cancel_delayed_work_sync(&display->poms_te_work);
  6954. rc = dsi_display_wake_up(display);
  6955. if (rc)
  6956. DSI_ERR("[%s] display wake up failed, rc=%d\n",
  6957. display->name, rc);
  6958. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6959. rc = dsi_display_vid_engine_disable(display);
  6960. if (rc)
  6961. DSI_ERR("[%s]failed to disable DSI vid engine, rc=%d\n",
  6962. display->name, rc);
  6963. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  6964. /**
  6965. * On POMS request , disable panel TE through
  6966. * delayed work queue.
  6967. */
  6968. if (display->poms_pending &&
  6969. display->panel->poms_align_vsync) {
  6970. INIT_DELAYED_WORK(&display->poms_te_work,
  6971. dsi_display_handle_poms_te);
  6972. queue_delayed_work(system_wq,
  6973. &display->poms_te_work,
  6974. msecs_to_jiffies(100));
  6975. }
  6976. rc = dsi_display_cmd_engine_disable(display);
  6977. if (rc)
  6978. DSI_ERR("[%s]failed to disable DSI cmd engine, rc=%d\n",
  6979. display->name, rc);
  6980. } else {
  6981. DSI_ERR("[%s] Invalid configuration\n", display->name);
  6982. rc = -EINVAL;
  6983. }
  6984. if (!display->poms_pending && !is_skip_op_required(display)) {
  6985. rc = dsi_panel_disable(display->panel);
  6986. if (rc)
  6987. DSI_ERR("[%s] failed to disable DSI panel, rc=%d\n",
  6988. display->name, rc);
  6989. }
  6990. if (is_skip_op_required(display)) {
  6991. /* applicable only for trusted vm */
  6992. display->panel->panel_initialized = false;
  6993. display->panel->power_mode = SDE_MODE_DPMS_OFF;
  6994. }
  6995. mutex_unlock(&display->display_lock);
  6996. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6997. return rc;
  6998. }
  6999. int dsi_display_update_pps(char *pps_cmd, void *disp)
  7000. {
  7001. struct dsi_display *display;
  7002. if (pps_cmd == NULL || disp == NULL) {
  7003. DSI_ERR("Invalid parameter\n");
  7004. return -EINVAL;
  7005. }
  7006. display = disp;
  7007. mutex_lock(&display->display_lock);
  7008. memcpy(display->panel->dce_pps_cmd, pps_cmd, DSI_CMD_PPS_SIZE);
  7009. mutex_unlock(&display->display_lock);
  7010. return 0;
  7011. }
  7012. int dsi_display_dump_clks_state(struct dsi_display *display)
  7013. {
  7014. int rc = 0;
  7015. if (!display) {
  7016. DSI_ERR("invalid display argument\n");
  7017. return -EINVAL;
  7018. }
  7019. if (!display->clk_mngr) {
  7020. DSI_ERR("invalid clk manager\n");
  7021. return -EINVAL;
  7022. }
  7023. if (!display->dsi_clk_handle || !display->mdp_clk_handle) {
  7024. DSI_ERR("invalid clk handles\n");
  7025. return -EINVAL;
  7026. }
  7027. mutex_lock(&display->display_lock);
  7028. rc = dsi_display_dump_clk_handle_state(display->dsi_clk_handle);
  7029. if (rc) {
  7030. DSI_ERR("failed to dump dsi clock state\n");
  7031. goto end;
  7032. }
  7033. rc = dsi_display_dump_clk_handle_state(display->mdp_clk_handle);
  7034. if (rc) {
  7035. DSI_ERR("failed to dump mdp clock state\n");
  7036. goto end;
  7037. }
  7038. end:
  7039. mutex_unlock(&display->display_lock);
  7040. return rc;
  7041. }
  7042. int dsi_display_unprepare(struct dsi_display *display)
  7043. {
  7044. int rc = 0, i;
  7045. struct dsi_display_ctrl *ctrl;
  7046. if (!display) {
  7047. DSI_ERR("Invalid params\n");
  7048. return -EINVAL;
  7049. }
  7050. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  7051. mutex_lock(&display->display_lock);
  7052. rc = dsi_display_wake_up(display);
  7053. if (rc)
  7054. DSI_ERR("[%s] display wake up failed, rc=%d\n",
  7055. display->name, rc);
  7056. if (!display->poms_pending && !is_skip_op_required(display)) {
  7057. rc = dsi_panel_unprepare(display->panel);
  7058. if (rc)
  7059. DSI_ERR("[%s] panel unprepare failed, rc=%d\n",
  7060. display->name, rc);
  7061. }
  7062. /* Remove additional vote added for pre_mode_switch_to_cmd */
  7063. if (display->poms_pending &&
  7064. display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  7065. display_for_each_ctrl(i, display) {
  7066. ctrl = &display->ctrl[i];
  7067. if (!ctrl->ctrl || !ctrl->ctrl->dma_wait_queued)
  7068. continue;
  7069. flush_workqueue(display->dma_cmd_workq);
  7070. cancel_work_sync(&ctrl->ctrl->dma_cmd_wait);
  7071. ctrl->ctrl->dma_wait_queued = false;
  7072. }
  7073. dsi_display_cmd_engine_disable(display);
  7074. dsi_display_clk_ctrl(display->dsi_clk_handle,
  7075. DSI_ALL_CLKS, DSI_CLK_OFF);
  7076. }
  7077. rc = dsi_display_ctrl_host_disable(display);
  7078. if (rc)
  7079. DSI_ERR("[%s] failed to disable DSI host, rc=%d\n",
  7080. display->name, rc);
  7081. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  7082. DSI_LINK_CLK, DSI_CLK_OFF);
  7083. if (rc)
  7084. DSI_ERR("[%s] failed to disable Link clocks, rc=%d\n",
  7085. display->name, rc);
  7086. rc = dsi_display_ctrl_deinit(display);
  7087. if (rc)
  7088. DSI_ERR("[%s] failed to deinit controller, rc=%d\n",
  7089. display->name, rc);
  7090. if (!display->panel->ulps_suspend_enabled) {
  7091. rc = dsi_display_phy_disable(display);
  7092. if (rc)
  7093. DSI_ERR("[%s] failed to disable DSI PHY, rc=%d\n",
  7094. display->name, rc);
  7095. }
  7096. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  7097. DSI_CORE_CLK, DSI_CLK_OFF);
  7098. if (rc)
  7099. DSI_ERR("[%s] failed to disable DSI clocks, rc=%d\n",
  7100. display->name, rc);
  7101. /* destrory dsi isr set up */
  7102. dsi_display_ctrl_isr_configure(display, false);
  7103. if (!display->poms_pending && !is_skip_op_required(display)) {
  7104. rc = dsi_panel_post_unprepare(display->panel);
  7105. if (rc)
  7106. DSI_ERR("[%s] panel post-unprepare failed, rc=%d\n",
  7107. display->name, rc);
  7108. }
  7109. mutex_unlock(&display->display_lock);
  7110. /* Free up DSI ERROR event callback */
  7111. dsi_display_unregister_error_handler(display);
  7112. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  7113. return rc;
  7114. }
  7115. void __init dsi_display_register(void)
  7116. {
  7117. dsi_phy_drv_register();
  7118. dsi_ctrl_drv_register();
  7119. dsi_display_parse_boot_display_selection();
  7120. platform_driver_register(&dsi_display_driver);
  7121. }
  7122. void __exit dsi_display_unregister(void)
  7123. {
  7124. platform_driver_unregister(&dsi_display_driver);
  7125. dsi_ctrl_drv_unregister();
  7126. dsi_phy_drv_unregister();
  7127. }
  7128. module_param_string(dsi_display0, dsi_display_primary, MAX_CMDLINE_PARAM_LEN,
  7129. 0600);
  7130. MODULE_PARM_DESC(dsi_display0,
  7131. "msm_drm.dsi_display0=<display node>:<configX> where <display node> is 'primary dsi display node name' and <configX> where x represents index in the topology list");
  7132. module_param_string(dsi_display1, dsi_display_secondary, MAX_CMDLINE_PARAM_LEN,
  7133. 0600);
  7134. MODULE_PARM_DESC(dsi_display1,
  7135. "msm_drm.dsi_display1=<display node>:<configX> where <display node> is 'secondary dsi display node name' and <configX> where x represents index in the topology list");