dsi_display.c 222 KB

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