dsi_display.c 199 KB

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