dsi_display.c 217 KB

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