dsi_display.c 224 KB

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