dsi_display.c 232 KB

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