dsi_display.c 207 KB

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