dsi_display.c 209 KB

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