dsi_display.c 193 KB

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