dsi_display.c 197 KB

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