dsi_display.c 248 KB

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