dsi_display.c 176 KB

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