dsi_display.c 218 KB

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