dsi_display.c 213 KB

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