dsi_display.c 211 KB

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