dsi_display.c 210 KB

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