dsi_display.c 219 KB

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