dsi_display.c 206 KB

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