dsi_display.c 223 KB

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