dsi_display.c 216 KB

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