dsi_display.c 219 KB

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