dsi_display.c 217 KB

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