dsi_display.c 180 KB

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