dsi_display.c 207 KB

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