dsi_display.c 214 KB

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