dsi_display.c 210 KB

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