dsi_display.c 168 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054
  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 (copy_to_user(user_buf, buf, len)) {
  905. kfree(buf);
  906. return -EFAULT;
  907. }
  908. *ppos += len;
  909. kfree(buf);
  910. return len;
  911. }
  912. static ssize_t debugfs_misr_setup(struct file *file,
  913. const char __user *user_buf,
  914. size_t user_len,
  915. loff_t *ppos)
  916. {
  917. struct dsi_display *display = file->private_data;
  918. char *buf;
  919. int rc = 0;
  920. size_t len;
  921. u32 enable, frame_count;
  922. if (!display)
  923. return -ENODEV;
  924. if (*ppos)
  925. return 0;
  926. buf = kzalloc(MISR_BUFF_SIZE, GFP_KERNEL);
  927. if (!buf)
  928. return -ENOMEM;
  929. /* leave room for termination char */
  930. len = min_t(size_t, user_len, MISR_BUFF_SIZE - 1);
  931. if (copy_from_user(buf, user_buf, len)) {
  932. rc = -EINVAL;
  933. goto error;
  934. }
  935. buf[len] = '\0'; /* terminate the string */
  936. if (sscanf(buf, "%u %u", &enable, &frame_count) != 2) {
  937. rc = -EINVAL;
  938. goto error;
  939. }
  940. display->misr_enable = enable;
  941. display->misr_frame_count = frame_count;
  942. mutex_lock(&display->display_lock);
  943. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  944. DSI_CORE_CLK, DSI_CLK_ON);
  945. if (rc) {
  946. pr_err("[%s] failed to enable DSI core clocks, rc=%d\n",
  947. display->name, rc);
  948. goto unlock;
  949. }
  950. _dsi_display_setup_misr(display);
  951. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  952. DSI_CORE_CLK, DSI_CLK_OFF);
  953. if (rc) {
  954. pr_err("[%s] failed to disable DSI core clocks, rc=%d\n",
  955. display->name, rc);
  956. goto unlock;
  957. }
  958. rc = user_len;
  959. unlock:
  960. mutex_unlock(&display->display_lock);
  961. error:
  962. kfree(buf);
  963. return rc;
  964. }
  965. static ssize_t debugfs_misr_read(struct file *file,
  966. char __user *user_buf,
  967. size_t user_len,
  968. loff_t *ppos)
  969. {
  970. struct dsi_display *display = file->private_data;
  971. char *buf;
  972. u32 len = 0;
  973. int rc = 0;
  974. struct dsi_ctrl *dsi_ctrl;
  975. int i;
  976. u32 misr;
  977. size_t max_len = min_t(size_t, user_len, MISR_BUFF_SIZE);
  978. if (!display)
  979. return -ENODEV;
  980. if (*ppos)
  981. return 0;
  982. buf = kzalloc(max_len, GFP_KERNEL);
  983. if (ZERO_OR_NULL_PTR(buf))
  984. return -ENOMEM;
  985. mutex_lock(&display->display_lock);
  986. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  987. DSI_CORE_CLK, DSI_CLK_ON);
  988. if (rc) {
  989. pr_err("[%s] failed to enable DSI core clocks, rc=%d\n",
  990. display->name, rc);
  991. goto error;
  992. }
  993. display_for_each_ctrl(i, display) {
  994. dsi_ctrl = display->ctrl[i].ctrl;
  995. misr = dsi_ctrl_collect_misr(display->ctrl[i].ctrl);
  996. len += snprintf((buf + len), max_len - len,
  997. "DSI_%d MISR: 0x%x\n", dsi_ctrl->cell_index, misr);
  998. if (len >= max_len)
  999. break;
  1000. }
  1001. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  1002. DSI_CORE_CLK, DSI_CLK_OFF);
  1003. if (rc) {
  1004. pr_err("[%s] failed to disable DSI core clocks, rc=%d\n",
  1005. display->name, rc);
  1006. goto error;
  1007. }
  1008. if (copy_to_user(user_buf, buf, max_len)) {
  1009. rc = -EFAULT;
  1010. goto error;
  1011. }
  1012. *ppos += len;
  1013. error:
  1014. mutex_unlock(&display->display_lock);
  1015. kfree(buf);
  1016. return len;
  1017. }
  1018. static ssize_t debugfs_esd_trigger_check(struct file *file,
  1019. const char __user *user_buf,
  1020. size_t user_len,
  1021. loff_t *ppos)
  1022. {
  1023. struct dsi_display *display = file->private_data;
  1024. char *buf;
  1025. int rc = 0;
  1026. u32 esd_trigger;
  1027. size_t len;
  1028. if (!display)
  1029. return -ENODEV;
  1030. if (*ppos)
  1031. return 0;
  1032. if (user_len > sizeof(u32))
  1033. return -EINVAL;
  1034. if (!user_len || !user_buf)
  1035. return -EINVAL;
  1036. if (!display->panel ||
  1037. atomic_read(&display->panel->esd_recovery_pending))
  1038. return user_len;
  1039. buf = kzalloc(ESD_TRIGGER_STRING_MAX_LEN, GFP_KERNEL);
  1040. if (!buf)
  1041. return -ENOMEM;
  1042. len = min_t(size_t, user_len, ESD_TRIGGER_STRING_MAX_LEN - 1);
  1043. if (copy_from_user(buf, user_buf, len)) {
  1044. rc = -EINVAL;
  1045. goto error;
  1046. }
  1047. buf[len] = '\0'; /* terminate the string */
  1048. if (kstrtouint(buf, 10, &esd_trigger)) {
  1049. rc = -EINVAL;
  1050. goto error;
  1051. }
  1052. if (esd_trigger != 1) {
  1053. rc = -EINVAL;
  1054. goto error;
  1055. }
  1056. display->esd_trigger = esd_trigger;
  1057. if (display->esd_trigger) {
  1058. pr_info("ESD attack triggered by user\n");
  1059. rc = dsi_panel_trigger_esd_attack(display->panel);
  1060. if (rc) {
  1061. pr_err("Failed to trigger ESD attack\n");
  1062. goto error;
  1063. }
  1064. }
  1065. rc = len;
  1066. error:
  1067. kfree(buf);
  1068. return rc;
  1069. }
  1070. static ssize_t debugfs_alter_esd_check_mode(struct file *file,
  1071. const char __user *user_buf,
  1072. size_t user_len,
  1073. loff_t *ppos)
  1074. {
  1075. struct dsi_display *display = file->private_data;
  1076. struct drm_panel_esd_config *esd_config;
  1077. char *buf;
  1078. int rc = 0;
  1079. size_t len;
  1080. if (!display)
  1081. return -ENODEV;
  1082. if (*ppos)
  1083. return 0;
  1084. buf = kzalloc(ESD_MODE_STRING_MAX_LEN, GFP_KERNEL);
  1085. if (ZERO_OR_NULL_PTR(buf))
  1086. return -ENOMEM;
  1087. len = min_t(size_t, user_len, ESD_MODE_STRING_MAX_LEN - 1);
  1088. if (copy_from_user(buf, user_buf, len)) {
  1089. rc = -EINVAL;
  1090. goto error;
  1091. }
  1092. buf[len] = '\0'; /* terminate the string */
  1093. if (!display->panel) {
  1094. rc = -EINVAL;
  1095. goto error;
  1096. }
  1097. esd_config = &display->panel->esd_config;
  1098. if (!esd_config) {
  1099. pr_err("Invalid panel esd config\n");
  1100. rc = -EINVAL;
  1101. goto error;
  1102. }
  1103. if (!esd_config->esd_enabled)
  1104. goto error;
  1105. if (!strcmp(buf, "te_signal_check\n")) {
  1106. if (display->panel->panel_mode == DSI_OP_VIDEO_MODE) {
  1107. pr_info("TE based ESD check for Video Mode panels is not allowed\n");
  1108. goto error;
  1109. }
  1110. pr_info("ESD check is switched to TE mode by user\n");
  1111. esd_config->status_mode = ESD_MODE_PANEL_TE;
  1112. dsi_display_change_te_irq_status(display, true);
  1113. }
  1114. if (!strcmp(buf, "reg_read\n")) {
  1115. pr_info("ESD check is switched to reg read by user\n");
  1116. rc = dsi_panel_parse_esd_reg_read_configs(display->panel);
  1117. if (rc) {
  1118. pr_err("failed to alter esd check mode,rc=%d\n",
  1119. rc);
  1120. rc = user_len;
  1121. goto error;
  1122. }
  1123. esd_config->status_mode = ESD_MODE_REG_READ;
  1124. if (dsi_display_is_te_based_esd(display))
  1125. dsi_display_change_te_irq_status(display, false);
  1126. }
  1127. if (!strcmp(buf, "esd_sw_sim_success\n"))
  1128. esd_config->status_mode = ESD_MODE_SW_SIM_SUCCESS;
  1129. if (!strcmp(buf, "esd_sw_sim_failure\n"))
  1130. esd_config->status_mode = ESD_MODE_SW_SIM_FAILURE;
  1131. rc = len;
  1132. error:
  1133. kfree(buf);
  1134. return rc;
  1135. }
  1136. static ssize_t debugfs_read_esd_check_mode(struct file *file,
  1137. char __user *user_buf,
  1138. size_t user_len,
  1139. loff_t *ppos)
  1140. {
  1141. struct dsi_display *display = file->private_data;
  1142. struct drm_panel_esd_config *esd_config;
  1143. char *buf;
  1144. int rc = 0;
  1145. size_t len;
  1146. if (!display)
  1147. return -ENODEV;
  1148. if (*ppos)
  1149. return 0;
  1150. if (!display->panel) {
  1151. pr_err("invalid panel data\n");
  1152. return -EINVAL;
  1153. }
  1154. buf = kzalloc(ESD_MODE_STRING_MAX_LEN, GFP_KERNEL);
  1155. if (ZERO_OR_NULL_PTR(buf))
  1156. return -ENOMEM;
  1157. esd_config = &display->panel->esd_config;
  1158. if (!esd_config) {
  1159. pr_err("Invalid panel esd config\n");
  1160. rc = -EINVAL;
  1161. goto error;
  1162. }
  1163. len = min_t(size_t, user_len, ESD_MODE_STRING_MAX_LEN - 1);
  1164. if (!esd_config->esd_enabled) {
  1165. rc = snprintf(buf, len, "ESD feature not enabled");
  1166. goto output_mode;
  1167. }
  1168. switch (esd_config->status_mode) {
  1169. case ESD_MODE_REG_READ:
  1170. rc = snprintf(buf, len, "reg_read");
  1171. break;
  1172. case ESD_MODE_PANEL_TE:
  1173. rc = snprintf(buf, len, "te_signal_check");
  1174. break;
  1175. case ESD_MODE_SW_SIM_FAILURE:
  1176. rc = snprintf(buf, len, "esd_sw_sim_failure");
  1177. break;
  1178. case ESD_MODE_SW_SIM_SUCCESS:
  1179. rc = snprintf(buf, len, "esd_sw_sim_success");
  1180. break;
  1181. default:
  1182. rc = snprintf(buf, len, "invalid");
  1183. break;
  1184. }
  1185. output_mode:
  1186. if (!rc) {
  1187. rc = -EINVAL;
  1188. goto error;
  1189. }
  1190. if (copy_to_user(user_buf, buf, len)) {
  1191. rc = -EFAULT;
  1192. goto error;
  1193. }
  1194. *ppos += len;
  1195. error:
  1196. kfree(buf);
  1197. return len;
  1198. }
  1199. static const struct file_operations dump_info_fops = {
  1200. .open = simple_open,
  1201. .read = debugfs_dump_info_read,
  1202. };
  1203. static const struct file_operations misr_data_fops = {
  1204. .open = simple_open,
  1205. .read = debugfs_misr_read,
  1206. .write = debugfs_misr_setup,
  1207. };
  1208. static const struct file_operations esd_trigger_fops = {
  1209. .open = simple_open,
  1210. .write = debugfs_esd_trigger_check,
  1211. };
  1212. static const struct file_operations esd_check_mode_fops = {
  1213. .open = simple_open,
  1214. .write = debugfs_alter_esd_check_mode,
  1215. .read = debugfs_read_esd_check_mode,
  1216. };
  1217. static int dsi_display_debugfs_init(struct dsi_display *display)
  1218. {
  1219. int rc = 0;
  1220. struct dentry *dir, *dump_file, *misr_data;
  1221. char name[MAX_NAME_SIZE];
  1222. int i;
  1223. dir = debugfs_create_dir(display->name, NULL);
  1224. if (IS_ERR_OR_NULL(dir)) {
  1225. rc = PTR_ERR(dir);
  1226. pr_err("[%s] debugfs create dir failed, rc = %d\n",
  1227. display->name, rc);
  1228. goto error;
  1229. }
  1230. dump_file = debugfs_create_file("dump_info",
  1231. 0400,
  1232. dir,
  1233. display,
  1234. &dump_info_fops);
  1235. if (IS_ERR_OR_NULL(dump_file)) {
  1236. rc = PTR_ERR(dump_file);
  1237. pr_err("[%s] debugfs create dump info file failed, rc=%d\n",
  1238. display->name, rc);
  1239. goto error_remove_dir;
  1240. }
  1241. dump_file = debugfs_create_file("esd_trigger",
  1242. 0644,
  1243. dir,
  1244. display,
  1245. &esd_trigger_fops);
  1246. if (IS_ERR_OR_NULL(dump_file)) {
  1247. rc = PTR_ERR(dump_file);
  1248. pr_err("[%s] debugfs for esd trigger file failed, rc=%d\n",
  1249. display->name, rc);
  1250. goto error_remove_dir;
  1251. }
  1252. dump_file = debugfs_create_file("esd_check_mode",
  1253. 0644,
  1254. dir,
  1255. display,
  1256. &esd_check_mode_fops);
  1257. if (IS_ERR_OR_NULL(dump_file)) {
  1258. rc = PTR_ERR(dump_file);
  1259. pr_err("[%s] debugfs for esd check mode failed, rc=%d\n",
  1260. display->name, rc);
  1261. goto error_remove_dir;
  1262. }
  1263. misr_data = debugfs_create_file("misr_data",
  1264. 0600,
  1265. dir,
  1266. display,
  1267. &misr_data_fops);
  1268. if (IS_ERR_OR_NULL(misr_data)) {
  1269. rc = PTR_ERR(misr_data);
  1270. pr_err("[%s] debugfs create misr datafile failed, rc=%d\n",
  1271. display->name, rc);
  1272. goto error_remove_dir;
  1273. }
  1274. display_for_each_ctrl(i, display) {
  1275. struct msm_dsi_phy *phy = display->ctrl[i].phy;
  1276. if (!phy || !phy->name)
  1277. continue;
  1278. snprintf(name, ARRAY_SIZE(name),
  1279. "%s_allow_phy_power_off", phy->name);
  1280. dump_file = debugfs_create_bool(name, 0600, dir,
  1281. &phy->allow_phy_power_off);
  1282. if (IS_ERR_OR_NULL(dump_file)) {
  1283. rc = PTR_ERR(dump_file);
  1284. pr_err("[%s] debugfs create %s failed, rc=%d\n",
  1285. display->name, name, rc);
  1286. goto error_remove_dir;
  1287. }
  1288. snprintf(name, ARRAY_SIZE(name),
  1289. "%s_regulator_min_datarate_bps", phy->name);
  1290. dump_file = debugfs_create_u32(name, 0600, dir,
  1291. &phy->regulator_min_datarate_bps);
  1292. if (IS_ERR_OR_NULL(dump_file)) {
  1293. rc = PTR_ERR(dump_file);
  1294. pr_err("[%s] debugfs create %s failed, rc=%d\n",
  1295. display->name, name, rc);
  1296. goto error_remove_dir;
  1297. }
  1298. }
  1299. if (!debugfs_create_bool("ulps_feature_enable", 0600, dir,
  1300. &display->panel->ulps_feature_enabled)) {
  1301. pr_err("[%s] debugfs create ulps feature enable file failed\n",
  1302. display->name);
  1303. goto error_remove_dir;
  1304. }
  1305. if (!debugfs_create_bool("ulps_suspend_feature_enable", 0600, dir,
  1306. &display->panel->ulps_suspend_enabled)) {
  1307. pr_err("[%s] debugfs create ulps-suspend feature enable file failed\n",
  1308. display->name);
  1309. goto error_remove_dir;
  1310. }
  1311. if (!debugfs_create_bool("ulps_status", 0400, dir,
  1312. &display->ulps_enabled)) {
  1313. pr_err("[%s] debugfs create ulps status file failed\n",
  1314. display->name);
  1315. goto error_remove_dir;
  1316. }
  1317. if (!debugfs_create_u32("clk_gating_config", 0600, dir,
  1318. &display->clk_gating_config)) {
  1319. pr_err("[%s] debugfs create clk gating config failed\n",
  1320. display->name);
  1321. goto error_remove_dir;
  1322. }
  1323. display->root = dir;
  1324. dsi_parser_dbg_init(display->parser, dir);
  1325. return rc;
  1326. error_remove_dir:
  1327. debugfs_remove(dir);
  1328. error:
  1329. return rc;
  1330. }
  1331. static int dsi_display_debugfs_deinit(struct dsi_display *display)
  1332. {
  1333. debugfs_remove_recursive(display->root);
  1334. return 0;
  1335. }
  1336. static void adjust_timing_by_ctrl_count(const struct dsi_display *display,
  1337. struct dsi_display_mode *mode)
  1338. {
  1339. if (display->ctrl_count > 1) {
  1340. mode->timing.h_active /= display->ctrl_count;
  1341. mode->timing.h_front_porch /= display->ctrl_count;
  1342. mode->timing.h_sync_width /= display->ctrl_count;
  1343. mode->timing.h_back_porch /= display->ctrl_count;
  1344. mode->timing.h_skew /= display->ctrl_count;
  1345. mode->pixel_clk_khz /= display->ctrl_count;
  1346. }
  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.src_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.src_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. char *dsi_clock_name;
  2451. if (!strcmp(display->display_type, "primary"))
  2452. dsi_clock_name = "qcom,dsi-select-clocks";
  2453. else
  2454. dsi_clock_name = "qcom,dsi-select-sec-clocks";
  2455. num_clk = dsi_display_get_clocks_count(display, dsi_clock_name);
  2456. pr_debug("clk count=%d\n", num_clk);
  2457. for (i = 0; i < num_clk; i++) {
  2458. dsi_display_get_clock_name(display, dsi_clock_name, i,
  2459. &clk_name);
  2460. pr_debug("clock name:%s\n", clk_name);
  2461. dsi_clk = devm_clk_get(&display->pdev->dev, clk_name);
  2462. if (IS_ERR_OR_NULL(dsi_clk)) {
  2463. rc = PTR_ERR(dsi_clk);
  2464. pr_err("failed to get %s, rc=%d\n", clk_name, rc);
  2465. goto error;
  2466. }
  2467. if (dsi_display_check_prefix(src_byte, clk_name)) {
  2468. src->byte_clk = dsi_clk;
  2469. continue;
  2470. }
  2471. if (dsi_display_check_prefix(src_pixel, clk_name)) {
  2472. src->pixel_clk = dsi_clk;
  2473. continue;
  2474. }
  2475. if (dsi_display_check_prefix(mux_byte, clk_name)) {
  2476. mux->byte_clk = dsi_clk;
  2477. continue;
  2478. }
  2479. if (dsi_display_check_prefix(mux_pixel, clk_name)) {
  2480. mux->pixel_clk = dsi_clk;
  2481. continue;
  2482. }
  2483. if (dsi_display_check_prefix(shadow_byte, clk_name)) {
  2484. shadow->byte_clk = dsi_clk;
  2485. continue;
  2486. }
  2487. if (dsi_display_check_prefix(shadow_pixel, clk_name)) {
  2488. shadow->pixel_clk = dsi_clk;
  2489. continue;
  2490. }
  2491. }
  2492. return 0;
  2493. error:
  2494. (void)dsi_display_clocks_deinit(display);
  2495. return rc;
  2496. }
  2497. static int dsi_display_clk_ctrl_cb(void *priv,
  2498. struct dsi_clk_ctrl_info clk_state_info)
  2499. {
  2500. int rc = 0;
  2501. struct dsi_display *display = NULL;
  2502. void *clk_handle = NULL;
  2503. if (!priv) {
  2504. pr_err("Invalid params\n");
  2505. return -EINVAL;
  2506. }
  2507. display = priv;
  2508. if (clk_state_info.client == DSI_CLK_REQ_MDP_CLIENT) {
  2509. clk_handle = display->mdp_clk_handle;
  2510. } else if (clk_state_info.client == DSI_CLK_REQ_DSI_CLIENT) {
  2511. clk_handle = display->dsi_clk_handle;
  2512. } else {
  2513. pr_err("invalid clk handle, return error\n");
  2514. return -EINVAL;
  2515. }
  2516. /*
  2517. * TODO: Wait for CMD_MDP_DONE interrupt if MDP client tries
  2518. * to turn off DSI clocks.
  2519. */
  2520. rc = dsi_display_clk_ctrl(clk_handle,
  2521. clk_state_info.clk_type, clk_state_info.clk_state);
  2522. if (rc) {
  2523. pr_err("[%s] failed to %d DSI %d clocks, rc=%d\n",
  2524. display->name, clk_state_info.clk_state,
  2525. clk_state_info.clk_type, rc);
  2526. return rc;
  2527. }
  2528. return 0;
  2529. }
  2530. static void dsi_display_ctrl_isr_configure(struct dsi_display *display, bool en)
  2531. {
  2532. int i;
  2533. struct dsi_display_ctrl *ctrl;
  2534. if (!display)
  2535. return;
  2536. display_for_each_ctrl(i, display) {
  2537. ctrl = &display->ctrl[i];
  2538. if (!ctrl)
  2539. continue;
  2540. dsi_ctrl_isr_configure(ctrl->ctrl, en);
  2541. }
  2542. }
  2543. int dsi_pre_clkoff_cb(void *priv,
  2544. enum dsi_clk_type clk,
  2545. enum dsi_lclk_type l_type,
  2546. enum dsi_clk_state new_state)
  2547. {
  2548. int rc = 0, i;
  2549. struct dsi_display *display = priv;
  2550. struct dsi_display_ctrl *ctrl;
  2551. if ((clk & DSI_LINK_CLK) && (new_state == DSI_CLK_OFF) &&
  2552. (l_type & DSI_LINK_LP_CLK)) {
  2553. /*
  2554. * If continuous clock is enabled then disable it
  2555. * before entering into ULPS Mode.
  2556. */
  2557. if (display->panel->host_config.force_hs_clk_lane)
  2558. _dsi_display_continuous_clk_ctrl(display, false);
  2559. /*
  2560. * If ULPS feature is enabled, enter ULPS first.
  2561. * However, when blanking the panel, we should enter ULPS
  2562. * only if ULPS during suspend feature is enabled.
  2563. */
  2564. if (!dsi_panel_initialized(display->panel)) {
  2565. if (display->panel->ulps_suspend_enabled)
  2566. rc = dsi_display_set_ulps(display, true);
  2567. } else if (dsi_panel_ulps_feature_enabled(display->panel)) {
  2568. rc = dsi_display_set_ulps(display, true);
  2569. }
  2570. if (rc)
  2571. pr_err("%s: failed enable ulps, rc = %d\n",
  2572. __func__, rc);
  2573. }
  2574. if ((clk & DSI_LINK_CLK) && (new_state == DSI_CLK_OFF) &&
  2575. (l_type & DSI_LINK_HS_CLK)) {
  2576. /*
  2577. * PHY clock gating should be disabled before the PLL and the
  2578. * branch clocks are turned off. Otherwise, it is possible that
  2579. * the clock RCGs may not be turned off correctly resulting
  2580. * in clock warnings.
  2581. */
  2582. rc = dsi_display_config_clk_gating(display, false);
  2583. if (rc)
  2584. pr_err("[%s] failed to disable clk gating, rc=%d\n",
  2585. display->name, rc);
  2586. }
  2587. if ((clk & DSI_CORE_CLK) && (new_state == DSI_CLK_OFF)) {
  2588. /*
  2589. * Enable DSI clamps only if entering idle power collapse or
  2590. * when ULPS during suspend is enabled..
  2591. */
  2592. if (dsi_panel_initialized(display->panel) ||
  2593. display->panel->ulps_suspend_enabled) {
  2594. dsi_display_phy_idle_off(display);
  2595. rc = dsi_display_set_clamp(display, true);
  2596. if (rc)
  2597. pr_err("%s: Failed to enable dsi clamps. rc=%d\n",
  2598. __func__, rc);
  2599. rc = dsi_display_phy_reset_config(display, false);
  2600. if (rc)
  2601. pr_err("%s: Failed to reset phy, rc=%d\n",
  2602. __func__, rc);
  2603. } else {
  2604. /* Make sure that controller is not in ULPS state when
  2605. * the DSI link is not active.
  2606. */
  2607. rc = dsi_display_set_ulps(display, false);
  2608. if (rc)
  2609. pr_err("%s: failed to disable ulps. rc=%d\n",
  2610. __func__, rc);
  2611. }
  2612. /* dsi will not be able to serve irqs from here on */
  2613. dsi_display_ctrl_irq_update(display, false);
  2614. /* cache the MISR values */
  2615. display_for_each_ctrl(i, display) {
  2616. ctrl = &display->ctrl[i];
  2617. if (!ctrl->ctrl)
  2618. continue;
  2619. dsi_ctrl_cache_misr(ctrl->ctrl);
  2620. }
  2621. }
  2622. return rc;
  2623. }
  2624. int dsi_post_clkon_cb(void *priv,
  2625. enum dsi_clk_type clk,
  2626. enum dsi_lclk_type l_type,
  2627. enum dsi_clk_state curr_state)
  2628. {
  2629. int rc = 0;
  2630. struct dsi_display *display = priv;
  2631. bool mmss_clamp = false;
  2632. if ((clk & DSI_LINK_CLK) && (l_type & DSI_LINK_LP_CLK)) {
  2633. mmss_clamp = display->clamp_enabled;
  2634. /*
  2635. * controller setup is needed if coming out of idle
  2636. * power collapse with clamps enabled.
  2637. */
  2638. if (mmss_clamp)
  2639. dsi_display_ctrl_setup(display);
  2640. /*
  2641. * Phy setup is needed if coming out of idle
  2642. * power collapse with clamps enabled.
  2643. */
  2644. if (display->phy_idle_power_off || mmss_clamp)
  2645. dsi_display_phy_idle_on(display, mmss_clamp);
  2646. if (display->ulps_enabled && mmss_clamp) {
  2647. /*
  2648. * ULPS Entry Request. This is needed if the lanes were
  2649. * in ULPS prior to power collapse, since after
  2650. * power collapse and reset, the DSI controller resets
  2651. * back to idle state and not ULPS. This ulps entry
  2652. * request will transition the state of the DSI
  2653. * controller to ULPS which will match the state of the
  2654. * DSI phy. This needs to be done prior to disabling
  2655. * the DSI clamps.
  2656. *
  2657. * Also, reset the ulps flag so that ulps_config
  2658. * function would reconfigure the controller state to
  2659. * ULPS.
  2660. */
  2661. display->ulps_enabled = false;
  2662. rc = dsi_display_set_ulps(display, true);
  2663. if (rc) {
  2664. pr_err("%s: Failed to enter ULPS. rc=%d\n",
  2665. __func__, rc);
  2666. goto error;
  2667. }
  2668. }
  2669. rc = dsi_display_phy_reset_config(display, true);
  2670. if (rc) {
  2671. pr_err("%s: Failed to reset phy, rc=%d\n",
  2672. __func__, rc);
  2673. goto error;
  2674. }
  2675. rc = dsi_display_set_clamp(display, false);
  2676. if (rc) {
  2677. pr_err("%s: Failed to disable dsi clamps. rc=%d\n",
  2678. __func__, rc);
  2679. goto error;
  2680. }
  2681. }
  2682. if ((clk & DSI_LINK_CLK) && (l_type & DSI_LINK_HS_CLK)) {
  2683. /*
  2684. * Toggle the resync FIFO everytime clock changes, except
  2685. * when cont-splash screen transition is going on.
  2686. * Toggling resync FIFO during cont splash transition
  2687. * can lead to blinks on the display.
  2688. */
  2689. if (!display->is_cont_splash_enabled)
  2690. dsi_display_toggle_resync_fifo(display);
  2691. if (display->ulps_enabled) {
  2692. rc = dsi_display_set_ulps(display, false);
  2693. if (rc) {
  2694. pr_err("%s: failed to disable ulps, rc= %d\n",
  2695. __func__, rc);
  2696. goto error;
  2697. }
  2698. }
  2699. if (display->panel->host_config.force_hs_clk_lane)
  2700. _dsi_display_continuous_clk_ctrl(display, true);
  2701. rc = dsi_display_config_clk_gating(display, true);
  2702. if (rc) {
  2703. pr_err("[%s] failed to enable clk gating %d\n",
  2704. display->name, rc);
  2705. goto error;
  2706. }
  2707. }
  2708. /* enable dsi to serve irqs */
  2709. if (clk & DSI_CORE_CLK)
  2710. dsi_display_ctrl_irq_update(display, true);
  2711. error:
  2712. return rc;
  2713. }
  2714. int dsi_post_clkoff_cb(void *priv,
  2715. enum dsi_clk_type clk_type,
  2716. enum dsi_lclk_type l_type,
  2717. enum dsi_clk_state curr_state)
  2718. {
  2719. int rc = 0;
  2720. struct dsi_display *display = priv;
  2721. if (!display) {
  2722. pr_err("%s: Invalid arg\n", __func__);
  2723. return -EINVAL;
  2724. }
  2725. if ((clk_type & DSI_CORE_CLK) &&
  2726. (curr_state == DSI_CLK_OFF)) {
  2727. rc = dsi_display_phy_power_off(display);
  2728. if (rc)
  2729. pr_err("[%s] failed to power off PHY, rc=%d\n",
  2730. display->name, rc);
  2731. rc = dsi_display_ctrl_power_off(display);
  2732. if (rc)
  2733. pr_err("[%s] failed to power DSI vregs, rc=%d\n",
  2734. display->name, rc);
  2735. }
  2736. return rc;
  2737. }
  2738. int dsi_pre_clkon_cb(void *priv,
  2739. enum dsi_clk_type clk_type,
  2740. enum dsi_lclk_type l_type,
  2741. enum dsi_clk_state new_state)
  2742. {
  2743. int rc = 0;
  2744. struct dsi_display *display = priv;
  2745. if (!display) {
  2746. pr_err("%s: invalid input\n", __func__);
  2747. return -EINVAL;
  2748. }
  2749. if ((clk_type & DSI_CORE_CLK) && (new_state == DSI_CLK_ON)) {
  2750. /*
  2751. * Enable DSI core power
  2752. * 1.> PANEL_PM are controlled as part of
  2753. * panel_power_ctrl. Needed not be handled here.
  2754. * 2.> CORE_PM are controlled by dsi clk manager.
  2755. * 3.> CTRL_PM need to be enabled/disabled
  2756. * only during unblank/blank. Their state should
  2757. * not be changed during static screen.
  2758. */
  2759. pr_debug("updating power states for ctrl and phy\n");
  2760. rc = dsi_display_ctrl_power_on(display);
  2761. if (rc) {
  2762. pr_err("[%s] failed to power on dsi controllers, rc=%d\n",
  2763. display->name, rc);
  2764. return rc;
  2765. }
  2766. rc = dsi_display_phy_power_on(display);
  2767. if (rc) {
  2768. pr_err("[%s] failed to power on dsi phy, rc = %d\n",
  2769. display->name, rc);
  2770. return rc;
  2771. }
  2772. pr_debug("%s: Enable DSI core power\n", __func__);
  2773. }
  2774. return rc;
  2775. }
  2776. static void __set_lane_map_v2(u8 *lane_map_v2,
  2777. enum dsi_phy_data_lanes lane0,
  2778. enum dsi_phy_data_lanes lane1,
  2779. enum dsi_phy_data_lanes lane2,
  2780. enum dsi_phy_data_lanes lane3)
  2781. {
  2782. lane_map_v2[DSI_LOGICAL_LANE_0] = lane0;
  2783. lane_map_v2[DSI_LOGICAL_LANE_1] = lane1;
  2784. lane_map_v2[DSI_LOGICAL_LANE_2] = lane2;
  2785. lane_map_v2[DSI_LOGICAL_LANE_3] = lane3;
  2786. }
  2787. static int dsi_display_parse_lane_map(struct dsi_display *display)
  2788. {
  2789. int rc = 0, i = 0;
  2790. const char *data;
  2791. u8 temp[DSI_LANE_MAX - 1];
  2792. if (!display) {
  2793. pr_err("invalid params\n");
  2794. return -EINVAL;
  2795. }
  2796. /* lane-map-v2 supersedes lane-map-v1 setting */
  2797. rc = of_property_read_u8_array(display->pdev->dev.of_node,
  2798. "qcom,lane-map-v2", temp, (DSI_LANE_MAX - 1));
  2799. if (!rc) {
  2800. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++)
  2801. display->lane_map.lane_map_v2[i] = BIT(temp[i]);
  2802. return 0;
  2803. } else if (rc != EINVAL) {
  2804. pr_debug("Incorrect mapping, configure default\n");
  2805. goto set_default;
  2806. }
  2807. /* lane-map older version, for DSI controller version < 2.0 */
  2808. data = of_get_property(display->pdev->dev.of_node,
  2809. "qcom,lane-map", NULL);
  2810. if (!data)
  2811. goto set_default;
  2812. if (!strcmp(data, "lane_map_3012")) {
  2813. display->lane_map.lane_map_v1 = DSI_LANE_MAP_3012;
  2814. __set_lane_map_v2(display->lane_map.lane_map_v2,
  2815. DSI_PHYSICAL_LANE_1,
  2816. DSI_PHYSICAL_LANE_2,
  2817. DSI_PHYSICAL_LANE_3,
  2818. DSI_PHYSICAL_LANE_0);
  2819. } else if (!strcmp(data, "lane_map_2301")) {
  2820. display->lane_map.lane_map_v1 = DSI_LANE_MAP_2301;
  2821. __set_lane_map_v2(display->lane_map.lane_map_v2,
  2822. DSI_PHYSICAL_LANE_2,
  2823. DSI_PHYSICAL_LANE_3,
  2824. DSI_PHYSICAL_LANE_0,
  2825. DSI_PHYSICAL_LANE_1);
  2826. } else if (!strcmp(data, "lane_map_1230")) {
  2827. display->lane_map.lane_map_v1 = DSI_LANE_MAP_1230;
  2828. __set_lane_map_v2(display->lane_map.lane_map_v2,
  2829. DSI_PHYSICAL_LANE_3,
  2830. DSI_PHYSICAL_LANE_0,
  2831. DSI_PHYSICAL_LANE_1,
  2832. DSI_PHYSICAL_LANE_2);
  2833. } else if (!strcmp(data, "lane_map_0321")) {
  2834. display->lane_map.lane_map_v1 = DSI_LANE_MAP_0321;
  2835. __set_lane_map_v2(display->lane_map.lane_map_v2,
  2836. DSI_PHYSICAL_LANE_0,
  2837. DSI_PHYSICAL_LANE_3,
  2838. DSI_PHYSICAL_LANE_2,
  2839. DSI_PHYSICAL_LANE_1);
  2840. } else if (!strcmp(data, "lane_map_1032")) {
  2841. display->lane_map.lane_map_v1 = DSI_LANE_MAP_1032;
  2842. __set_lane_map_v2(display->lane_map.lane_map_v2,
  2843. DSI_PHYSICAL_LANE_1,
  2844. DSI_PHYSICAL_LANE_0,
  2845. DSI_PHYSICAL_LANE_3,
  2846. DSI_PHYSICAL_LANE_2);
  2847. } else if (!strcmp(data, "lane_map_2103")) {
  2848. display->lane_map.lane_map_v1 = DSI_LANE_MAP_2103;
  2849. __set_lane_map_v2(display->lane_map.lane_map_v2,
  2850. DSI_PHYSICAL_LANE_2,
  2851. DSI_PHYSICAL_LANE_1,
  2852. DSI_PHYSICAL_LANE_0,
  2853. DSI_PHYSICAL_LANE_3);
  2854. } else if (!strcmp(data, "lane_map_3210")) {
  2855. display->lane_map.lane_map_v1 = DSI_LANE_MAP_3210;
  2856. __set_lane_map_v2(display->lane_map.lane_map_v2,
  2857. DSI_PHYSICAL_LANE_3,
  2858. DSI_PHYSICAL_LANE_2,
  2859. DSI_PHYSICAL_LANE_1,
  2860. DSI_PHYSICAL_LANE_0);
  2861. } else {
  2862. pr_warn("%s: invalid lane map %s specified. defaulting to lane_map0123\n",
  2863. __func__, data);
  2864. goto set_default;
  2865. }
  2866. return 0;
  2867. set_default:
  2868. /* default lane mapping */
  2869. __set_lane_map_v2(display->lane_map.lane_map_v2, DSI_PHYSICAL_LANE_0,
  2870. DSI_PHYSICAL_LANE_1, DSI_PHYSICAL_LANE_2, DSI_PHYSICAL_LANE_3);
  2871. display->lane_map.lane_map_v1 = DSI_LANE_MAP_0123;
  2872. return 0;
  2873. }
  2874. static int dsi_display_get_phandle_index(
  2875. struct dsi_display *display,
  2876. const char *propname, int count, int index)
  2877. {
  2878. struct device_node *disp_node = display->panel_node;
  2879. u32 *val = NULL;
  2880. int rc = 0;
  2881. val = kcalloc(count, sizeof(*val), GFP_KERNEL);
  2882. if (ZERO_OR_NULL_PTR(val)) {
  2883. rc = -ENOMEM;
  2884. goto end;
  2885. }
  2886. if (index >= count)
  2887. goto end;
  2888. if (display->fw)
  2889. rc = dsi_parser_read_u32_array(display->parser_node,
  2890. propname, val, count);
  2891. else
  2892. rc = of_property_read_u32_array(disp_node, propname,
  2893. val, count);
  2894. if (rc)
  2895. goto end;
  2896. rc = val[index];
  2897. pr_debug("%s index=%d\n", propname, rc);
  2898. end:
  2899. kfree(val);
  2900. return rc;
  2901. }
  2902. static int dsi_display_get_phandle_count(struct dsi_display *display,
  2903. const char *propname)
  2904. {
  2905. if (display->fw)
  2906. return dsi_parser_count_u32_elems(display->parser_node,
  2907. propname);
  2908. else
  2909. return of_property_count_u32_elems(display->panel_node,
  2910. propname);
  2911. }
  2912. static int dsi_display_parse_dt(struct dsi_display *display)
  2913. {
  2914. int i, rc = 0;
  2915. u32 phy_count = 0;
  2916. struct device_node *of_node = display->pdev->dev.of_node;
  2917. char *dsi_ctrl_name, *dsi_phy_name;
  2918. if (!strcmp(display->display_type, "primary")) {
  2919. dsi_ctrl_name = "qcom,dsi-ctrl-num";
  2920. dsi_phy_name = "qcom,dsi-phy-num";
  2921. } else {
  2922. dsi_ctrl_name = "qcom,dsi-sec-ctrl-num";
  2923. dsi_phy_name = "qcom,dsi-sec-phy-num";
  2924. }
  2925. display->ctrl_count = dsi_display_get_phandle_count(display,
  2926. dsi_ctrl_name);
  2927. phy_count = dsi_display_get_phandle_count(display, dsi_phy_name);
  2928. pr_debug("ctrl count=%d, phy count=%d\n",
  2929. display->ctrl_count, phy_count);
  2930. if (!phy_count || !display->ctrl_count) {
  2931. pr_err("no ctrl/phys found\n");
  2932. rc = -ENODEV;
  2933. goto error;
  2934. }
  2935. if (phy_count != display->ctrl_count) {
  2936. pr_err("different ctrl and phy counts\n");
  2937. rc = -ENODEV;
  2938. goto error;
  2939. }
  2940. display_for_each_ctrl(i, display) {
  2941. struct dsi_display_ctrl *ctrl = &display->ctrl[i];
  2942. int index;
  2943. index = dsi_display_get_phandle_index(display, dsi_ctrl_name,
  2944. display->ctrl_count, i);
  2945. ctrl->ctrl_of_node = of_parse_phandle(of_node,
  2946. "qcom,dsi-ctrl", index);
  2947. of_node_put(ctrl->ctrl_of_node);
  2948. index = dsi_display_get_phandle_index(display, dsi_phy_name,
  2949. display->ctrl_count, i);
  2950. ctrl->phy_of_node = of_parse_phandle(of_node,
  2951. "qcom,dsi-phy", index);
  2952. of_node_put(ctrl->phy_of_node);
  2953. }
  2954. /* Parse TE data */
  2955. dsi_display_parse_te_data(display);
  2956. /* Parse all external bridges from port 0 */
  2957. display_for_each_ctrl(i, display) {
  2958. display->ext_bridge[i].node_of =
  2959. of_graph_get_remote_node(of_node, 0, i);
  2960. if (display->ext_bridge[i].node_of)
  2961. display->ext_bridge_cnt++;
  2962. else
  2963. break;
  2964. }
  2965. pr_debug("success\n");
  2966. error:
  2967. return rc;
  2968. }
  2969. static int dsi_display_res_init(struct dsi_display *display)
  2970. {
  2971. int rc = 0;
  2972. int i;
  2973. struct dsi_display_ctrl *ctrl;
  2974. display_for_each_ctrl(i, display) {
  2975. ctrl = &display->ctrl[i];
  2976. ctrl->ctrl = dsi_ctrl_get(ctrl->ctrl_of_node);
  2977. if (IS_ERR_OR_NULL(ctrl->ctrl)) {
  2978. rc = PTR_ERR(ctrl->ctrl);
  2979. pr_err("failed to get dsi controller, rc=%d\n", rc);
  2980. ctrl->ctrl = NULL;
  2981. goto error_ctrl_put;
  2982. }
  2983. ctrl->phy = dsi_phy_get(ctrl->phy_of_node);
  2984. if (IS_ERR_OR_NULL(ctrl->phy)) {
  2985. rc = PTR_ERR(ctrl->phy);
  2986. pr_err("failed to get phy controller, rc=%d\n", rc);
  2987. dsi_ctrl_put(ctrl->ctrl);
  2988. ctrl->phy = NULL;
  2989. goto error_ctrl_put;
  2990. }
  2991. }
  2992. display->panel = dsi_panel_get(&display->pdev->dev,
  2993. display->panel_node,
  2994. display->parser_node,
  2995. display->display_type,
  2996. display->cmdline_topology);
  2997. if (IS_ERR_OR_NULL(display->panel)) {
  2998. rc = PTR_ERR(display->panel);
  2999. pr_err("failed to get panel, rc=%d\n", rc);
  3000. display->panel = NULL;
  3001. goto error_ctrl_put;
  3002. }
  3003. rc = dsi_display_parse_lane_map(display);
  3004. if (rc) {
  3005. pr_err("Lane map not found, rc=%d\n", rc);
  3006. goto error_ctrl_put;
  3007. }
  3008. rc = dsi_display_clocks_init(display);
  3009. if (rc) {
  3010. pr_err("Failed to parse clock data, rc=%d\n", rc);
  3011. goto error_ctrl_put;
  3012. }
  3013. return 0;
  3014. error_ctrl_put:
  3015. for (i = i - 1; i >= 0; i--) {
  3016. ctrl = &display->ctrl[i];
  3017. dsi_ctrl_put(ctrl->ctrl);
  3018. dsi_phy_put(ctrl->phy);
  3019. }
  3020. return rc;
  3021. }
  3022. static int dsi_display_res_deinit(struct dsi_display *display)
  3023. {
  3024. int rc = 0;
  3025. int i;
  3026. struct dsi_display_ctrl *ctrl;
  3027. rc = dsi_display_clocks_deinit(display);
  3028. if (rc)
  3029. pr_err("clocks deinit failed, rc=%d\n", rc);
  3030. display_for_each_ctrl(i, display) {
  3031. ctrl = &display->ctrl[i];
  3032. dsi_phy_put(ctrl->phy);
  3033. dsi_ctrl_put(ctrl->ctrl);
  3034. }
  3035. if (display->panel)
  3036. dsi_panel_put(display->panel);
  3037. return rc;
  3038. }
  3039. static int dsi_display_validate_mode_set(struct dsi_display *display,
  3040. struct dsi_display_mode *mode,
  3041. u32 flags)
  3042. {
  3043. int rc = 0;
  3044. int i;
  3045. struct dsi_display_ctrl *ctrl;
  3046. /*
  3047. * To set a mode:
  3048. * 1. Controllers should be turned off.
  3049. * 2. Link clocks should be off.
  3050. * 3. Phy should be disabled.
  3051. */
  3052. display_for_each_ctrl(i, display) {
  3053. ctrl = &display->ctrl[i];
  3054. if ((ctrl->power_state > DSI_CTRL_POWER_VREG_ON) ||
  3055. (ctrl->phy_enabled)) {
  3056. rc = -EINVAL;
  3057. goto error;
  3058. }
  3059. }
  3060. error:
  3061. return rc;
  3062. }
  3063. static bool dsi_display_is_seamless_dfps_possible(
  3064. const struct dsi_display *display,
  3065. const struct dsi_display_mode *tgt,
  3066. const enum dsi_dfps_type dfps_type)
  3067. {
  3068. struct dsi_display_mode *cur;
  3069. if (!display || !tgt || !display->panel) {
  3070. pr_err("Invalid params\n");
  3071. return false;
  3072. }
  3073. cur = display->panel->cur_mode;
  3074. if (cur->timing.h_active != tgt->timing.h_active) {
  3075. pr_debug("timing.h_active differs %d %d\n",
  3076. cur->timing.h_active, tgt->timing.h_active);
  3077. return false;
  3078. }
  3079. if (cur->timing.h_back_porch != tgt->timing.h_back_porch) {
  3080. pr_debug("timing.h_back_porch differs %d %d\n",
  3081. cur->timing.h_back_porch,
  3082. tgt->timing.h_back_porch);
  3083. return false;
  3084. }
  3085. if (cur->timing.h_sync_width != tgt->timing.h_sync_width) {
  3086. pr_debug("timing.h_sync_width differs %d %d\n",
  3087. cur->timing.h_sync_width,
  3088. tgt->timing.h_sync_width);
  3089. return false;
  3090. }
  3091. if (cur->timing.h_front_porch != tgt->timing.h_front_porch) {
  3092. pr_debug("timing.h_front_porch differs %d %d\n",
  3093. cur->timing.h_front_porch,
  3094. tgt->timing.h_front_porch);
  3095. if (dfps_type != DSI_DFPS_IMMEDIATE_HFP)
  3096. return false;
  3097. }
  3098. if (cur->timing.h_skew != tgt->timing.h_skew) {
  3099. pr_debug("timing.h_skew differs %d %d\n",
  3100. cur->timing.h_skew,
  3101. tgt->timing.h_skew);
  3102. return false;
  3103. }
  3104. /* skip polarity comparison */
  3105. if (cur->timing.v_active != tgt->timing.v_active) {
  3106. pr_debug("timing.v_active differs %d %d\n",
  3107. cur->timing.v_active,
  3108. tgt->timing.v_active);
  3109. return false;
  3110. }
  3111. if (cur->timing.v_back_porch != tgt->timing.v_back_porch) {
  3112. pr_debug("timing.v_back_porch differs %d %d\n",
  3113. cur->timing.v_back_porch,
  3114. tgt->timing.v_back_porch);
  3115. return false;
  3116. }
  3117. if (cur->timing.v_sync_width != tgt->timing.v_sync_width) {
  3118. pr_debug("timing.v_sync_width differs %d %d\n",
  3119. cur->timing.v_sync_width,
  3120. tgt->timing.v_sync_width);
  3121. return false;
  3122. }
  3123. if (cur->timing.v_front_porch != tgt->timing.v_front_porch) {
  3124. pr_debug("timing.v_front_porch differs %d %d\n",
  3125. cur->timing.v_front_porch,
  3126. tgt->timing.v_front_porch);
  3127. if (dfps_type != DSI_DFPS_IMMEDIATE_VFP)
  3128. return false;
  3129. }
  3130. /* skip polarity comparison */
  3131. if (cur->timing.refresh_rate == tgt->timing.refresh_rate)
  3132. pr_debug("timing.refresh_rate identical %d %d\n",
  3133. cur->timing.refresh_rate,
  3134. tgt->timing.refresh_rate);
  3135. if (cur->pixel_clk_khz != tgt->pixel_clk_khz)
  3136. pr_debug("pixel_clk_khz differs %d %d\n",
  3137. cur->pixel_clk_khz, tgt->pixel_clk_khz);
  3138. if (cur->dsi_mode_flags != tgt->dsi_mode_flags)
  3139. pr_debug("flags differs %d %d\n",
  3140. cur->dsi_mode_flags, tgt->dsi_mode_flags);
  3141. return true;
  3142. }
  3143. static int dsi_display_dfps_update(struct dsi_display *display,
  3144. struct dsi_display_mode *dsi_mode)
  3145. {
  3146. struct dsi_mode_info *timing;
  3147. struct dsi_display_ctrl *m_ctrl, *ctrl;
  3148. struct dsi_display_mode *panel_mode;
  3149. struct dsi_dfps_capabilities dfps_caps;
  3150. int rc = 0;
  3151. int i = 0;
  3152. if (!display || !dsi_mode || !display->panel) {
  3153. pr_err("Invalid params\n");
  3154. return -EINVAL;
  3155. }
  3156. timing = &dsi_mode->timing;
  3157. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  3158. if (!dfps_caps.dfps_support) {
  3159. pr_err("dfps not supported\n");
  3160. return -ENOTSUPP;
  3161. }
  3162. if (dfps_caps.type == DSI_DFPS_IMMEDIATE_CLK) {
  3163. pr_err("dfps clock method not supported\n");
  3164. return -ENOTSUPP;
  3165. }
  3166. /* For split DSI, update the clock master first */
  3167. pr_debug("configuring seamless dynamic fps\n\n");
  3168. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  3169. m_ctrl = &display->ctrl[display->clk_master_idx];
  3170. rc = dsi_ctrl_async_timing_update(m_ctrl->ctrl, timing);
  3171. if (rc) {
  3172. pr_err("[%s] failed to dfps update host_%d, rc=%d\n",
  3173. display->name, i, rc);
  3174. goto error;
  3175. }
  3176. /* Update the rest of the controllers */
  3177. display_for_each_ctrl(i, display) {
  3178. ctrl = &display->ctrl[i];
  3179. if (!ctrl->ctrl || (ctrl == m_ctrl))
  3180. continue;
  3181. rc = dsi_ctrl_async_timing_update(ctrl->ctrl, timing);
  3182. if (rc) {
  3183. pr_err("[%s] failed to dfps update host_%d, rc=%d\n",
  3184. display->name, i, rc);
  3185. goto error;
  3186. }
  3187. }
  3188. panel_mode = display->panel->cur_mode;
  3189. memcpy(panel_mode, dsi_mode, sizeof(*panel_mode));
  3190. /*
  3191. * dsi_mode_flags flags are used to communicate with other drm driver
  3192. * components, and are transient. They aren't inherently part of the
  3193. * display panel's mode and shouldn't be saved into the cached currently
  3194. * active mode.
  3195. */
  3196. panel_mode->dsi_mode_flags = 0;
  3197. error:
  3198. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  3199. return rc;
  3200. }
  3201. static int dsi_display_dfps_calc_front_porch(
  3202. u32 old_fps,
  3203. u32 new_fps,
  3204. u32 a_total,
  3205. u32 b_total,
  3206. u32 b_fp,
  3207. u32 *b_fp_out)
  3208. {
  3209. s32 b_fp_new;
  3210. int add_porches, diff;
  3211. if (!b_fp_out) {
  3212. pr_err("Invalid params\n");
  3213. return -EINVAL;
  3214. }
  3215. if (!a_total || !new_fps) {
  3216. pr_err("Invalid pixel total or new fps in mode request\n");
  3217. return -EINVAL;
  3218. }
  3219. /*
  3220. * Keep clock, other porches constant, use new fps, calc front porch
  3221. * new_vtotal = old_vtotal * (old_fps / new_fps )
  3222. * new_vfp - old_vfp = new_vtotal - old_vtotal
  3223. * new_vfp = old_vfp + old_vtotal * ((old_fps - new_fps)/ new_fps)
  3224. */
  3225. diff = abs(old_fps - new_fps);
  3226. add_porches = mult_frac(b_total, diff, new_fps);
  3227. if (old_fps > new_fps)
  3228. b_fp_new = b_fp + add_porches;
  3229. else
  3230. b_fp_new = b_fp - add_porches;
  3231. pr_debug("fps %u a %u b %u b_fp %u new_fp %d\n",
  3232. new_fps, a_total, b_total, b_fp, b_fp_new);
  3233. if (b_fp_new < 0) {
  3234. pr_err("Invalid new_hfp calcluated%d\n", b_fp_new);
  3235. return -EINVAL;
  3236. }
  3237. /**
  3238. * TODO: To differentiate from clock method when communicating to the
  3239. * other components, perhaps we should set clk here to original value
  3240. */
  3241. *b_fp_out = b_fp_new;
  3242. return 0;
  3243. }
  3244. /**
  3245. * dsi_display_get_dfps_timing() - Get the new dfps values.
  3246. * @display: DSI display handle.
  3247. * @adj_mode: Mode value structure to be changed.
  3248. * It contains old timing values and latest fps value.
  3249. * New timing values are updated based on new fps.
  3250. * @curr_refresh_rate: Current fps rate.
  3251. * If zero , current fps rate is taken from
  3252. * display->panel->cur_mode.
  3253. * Return: error code.
  3254. */
  3255. static int dsi_display_get_dfps_timing(struct dsi_display *display,
  3256. struct dsi_display_mode *adj_mode,
  3257. u32 curr_refresh_rate)
  3258. {
  3259. struct dsi_dfps_capabilities dfps_caps;
  3260. struct dsi_display_mode per_ctrl_mode;
  3261. struct dsi_mode_info *timing;
  3262. struct dsi_ctrl *m_ctrl;
  3263. int rc = 0;
  3264. if (!display || !adj_mode) {
  3265. pr_err("Invalid params\n");
  3266. return -EINVAL;
  3267. }
  3268. m_ctrl = display->ctrl[display->clk_master_idx].ctrl;
  3269. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  3270. if (!dfps_caps.dfps_support) {
  3271. pr_err("dfps not supported by panel\n");
  3272. return -EINVAL;
  3273. }
  3274. per_ctrl_mode = *adj_mode;
  3275. adjust_timing_by_ctrl_count(display, &per_ctrl_mode);
  3276. if (!curr_refresh_rate) {
  3277. if (!dsi_display_is_seamless_dfps_possible(display,
  3278. &per_ctrl_mode, dfps_caps.type)) {
  3279. pr_err("seamless dynamic fps not supported for mode\n");
  3280. return -EINVAL;
  3281. }
  3282. if (display->panel->cur_mode) {
  3283. curr_refresh_rate =
  3284. display->panel->cur_mode->timing.refresh_rate;
  3285. } else {
  3286. pr_err("cur_mode is not initialized\n");
  3287. return -EINVAL;
  3288. }
  3289. }
  3290. /* TODO: Remove this direct reference to the dsi_ctrl */
  3291. timing = &per_ctrl_mode.timing;
  3292. switch (dfps_caps.type) {
  3293. case DSI_DFPS_IMMEDIATE_VFP:
  3294. rc = dsi_display_dfps_calc_front_porch(
  3295. curr_refresh_rate,
  3296. timing->refresh_rate,
  3297. DSI_H_TOTAL_DSC(timing),
  3298. DSI_V_TOTAL(timing),
  3299. timing->v_front_porch,
  3300. &adj_mode->timing.v_front_porch);
  3301. break;
  3302. case DSI_DFPS_IMMEDIATE_HFP:
  3303. rc = dsi_display_dfps_calc_front_porch(
  3304. curr_refresh_rate,
  3305. timing->refresh_rate,
  3306. DSI_V_TOTAL(timing),
  3307. DSI_H_TOTAL_DSC(timing),
  3308. timing->h_front_porch,
  3309. &adj_mode->timing.h_front_porch);
  3310. if (!rc)
  3311. adj_mode->timing.h_front_porch *= display->ctrl_count;
  3312. break;
  3313. default:
  3314. pr_err("Unsupported DFPS mode %d\n", dfps_caps.type);
  3315. rc = -ENOTSUPP;
  3316. }
  3317. return rc;
  3318. }
  3319. static bool dsi_display_validate_mode_seamless(struct dsi_display *display,
  3320. struct dsi_display_mode *adj_mode)
  3321. {
  3322. int rc = 0;
  3323. if (!display || !adj_mode) {
  3324. pr_err("Invalid params\n");
  3325. return false;
  3326. }
  3327. /* Currently the only seamless transition is dynamic fps */
  3328. rc = dsi_display_get_dfps_timing(display, adj_mode, 0);
  3329. if (rc) {
  3330. pr_debug("Dynamic FPS not supported for seamless\n");
  3331. } else {
  3332. pr_debug("Mode switch is seamless Dynamic FPS\n");
  3333. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_DFPS |
  3334. DSI_MODE_FLAG_VBLANK_PRE_MODESET;
  3335. }
  3336. return rc;
  3337. }
  3338. static int dsi_display_set_mode_sub(struct dsi_display *display,
  3339. struct dsi_display_mode *mode,
  3340. u32 flags)
  3341. {
  3342. int rc = 0;
  3343. int i;
  3344. struct dsi_display_ctrl *ctrl;
  3345. struct dsi_display_mode_priv_info *priv_info;
  3346. priv_info = mode->priv_info;
  3347. if (!priv_info) {
  3348. pr_err("[%s] failed to get private info of the display mode\n",
  3349. display->name);
  3350. return -EINVAL;
  3351. }
  3352. if (mode->dsi_mode_flags & DSI_MODE_FLAG_POMS) {
  3353. display->config.panel_mode = mode->panel_mode;
  3354. display->panel->panel_mode = mode->panel_mode;
  3355. }
  3356. rc = dsi_panel_get_host_cfg_for_mode(display->panel,
  3357. mode,
  3358. &display->config);
  3359. if (rc) {
  3360. pr_err("[%s] failed to get host config for mode, rc=%d\n",
  3361. display->name, rc);
  3362. goto error;
  3363. }
  3364. memcpy(&display->config.lane_map, &display->lane_map,
  3365. sizeof(display->lane_map));
  3366. if (mode->dsi_mode_flags &
  3367. (DSI_MODE_FLAG_DFPS | DSI_MODE_FLAG_VRR)) {
  3368. rc = dsi_display_dfps_update(display, mode);
  3369. if (rc) {
  3370. pr_err("[%s]DSI dfps update failed, rc=%d\n",
  3371. display->name, rc);
  3372. goto error;
  3373. }
  3374. }
  3375. display_for_each_ctrl(i, display) {
  3376. ctrl = &display->ctrl[i];
  3377. rc = dsi_ctrl_update_host_config(ctrl->ctrl, &display->config,
  3378. mode, mode->dsi_mode_flags,
  3379. display->dsi_clk_handle);
  3380. if (rc) {
  3381. pr_err("[%s] failed to update ctrl config, rc=%d\n",
  3382. display->name, rc);
  3383. goto error;
  3384. }
  3385. }
  3386. if (priv_info->phy_timing_len) {
  3387. display_for_each_ctrl(i, display) {
  3388. ctrl = &display->ctrl[i];
  3389. rc = dsi_phy_set_timing_params(ctrl->phy,
  3390. priv_info->phy_timing_val,
  3391. priv_info->phy_timing_len);
  3392. if (rc)
  3393. pr_err("failed to add DSI PHY timing params\n");
  3394. }
  3395. }
  3396. error:
  3397. return rc;
  3398. }
  3399. /**
  3400. * _dsi_display_dev_init - initializes the display device
  3401. * Initialization will acquire references to the resources required for the
  3402. * display hardware to function.
  3403. * @display: Handle to the display
  3404. * Returns: Zero on success
  3405. */
  3406. static int _dsi_display_dev_init(struct dsi_display *display)
  3407. {
  3408. int rc = 0;
  3409. if (!display) {
  3410. pr_err("invalid display\n");
  3411. return -EINVAL;
  3412. }
  3413. if (!display->panel_node)
  3414. return 0;
  3415. mutex_lock(&display->display_lock);
  3416. display->parser = dsi_parser_get(&display->pdev->dev);
  3417. if (display->fw && display->parser)
  3418. display->parser_node = dsi_parser_get_head_node(
  3419. display->parser, display->fw->data,
  3420. display->fw->size);
  3421. rc = dsi_display_parse_dt(display);
  3422. if (rc) {
  3423. pr_err("[%s] failed to parse dt, rc=%d\n", display->name, rc);
  3424. goto error;
  3425. }
  3426. rc = dsi_display_res_init(display);
  3427. if (rc) {
  3428. pr_err("[%s] failed to initialize resources, rc=%d\n",
  3429. display->name, rc);
  3430. goto error;
  3431. }
  3432. error:
  3433. mutex_unlock(&display->display_lock);
  3434. return rc;
  3435. }
  3436. /**
  3437. * _dsi_display_dev_deinit - deinitializes the display device
  3438. * All the resources acquired during device init will be released.
  3439. * @display: Handle to the display
  3440. * Returns: Zero on success
  3441. */
  3442. static int _dsi_display_dev_deinit(struct dsi_display *display)
  3443. {
  3444. int rc = 0;
  3445. if (!display) {
  3446. pr_err("invalid display\n");
  3447. return -EINVAL;
  3448. }
  3449. mutex_lock(&display->display_lock);
  3450. rc = dsi_display_res_deinit(display);
  3451. if (rc)
  3452. pr_err("[%s] failed to deinitialize resource, rc=%d\n",
  3453. display->name, rc);
  3454. mutex_unlock(&display->display_lock);
  3455. return rc;
  3456. }
  3457. /**
  3458. * dsi_display_cont_splash_config() - Initialize resources for continuous splash
  3459. * @dsi_display: Pointer to dsi display
  3460. * Returns: Zero on success
  3461. */
  3462. int dsi_display_cont_splash_config(void *dsi_display)
  3463. {
  3464. struct dsi_display *display = dsi_display;
  3465. int rc = 0;
  3466. /* Vote for gdsc required to read register address space */
  3467. if (!display) {
  3468. pr_err("invalid input display param\n");
  3469. return -EINVAL;
  3470. }
  3471. rc = pm_runtime_get_sync(display->drm_dev->dev);
  3472. if (rc < 0) {
  3473. pr_err("failed to vote gdsc for continuous splash, rc=%d\n",
  3474. rc);
  3475. return rc;
  3476. }
  3477. mutex_lock(&display->display_lock);
  3478. display->is_cont_splash_enabled = true;
  3479. /* Update splash status for clock manager */
  3480. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  3481. display->is_cont_splash_enabled);
  3482. /* Set up ctrl isr before enabling core clk */
  3483. dsi_display_ctrl_isr_configure(display, true);
  3484. /* Vote for Core clk and link clk. Votes on ctrl and phy
  3485. * regulator are inplicit from pre clk on callback
  3486. */
  3487. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  3488. DSI_ALL_CLKS, DSI_CLK_ON);
  3489. if (rc) {
  3490. pr_err("[%s] failed to enable DSI link clocks, rc=%d\n",
  3491. display->name, rc);
  3492. goto clk_manager_update;
  3493. }
  3494. /* Vote on panel regulator will be removed during suspend path */
  3495. rc = dsi_pwr_enable_regulator(&display->panel->power_info, true);
  3496. if (rc) {
  3497. pr_err("[%s] failed to enable vregs, rc=%d\n",
  3498. display->panel->name, rc);
  3499. goto clks_disabled;
  3500. }
  3501. dsi_config_host_engine_state_for_cont_splash(display);
  3502. mutex_unlock(&display->display_lock);
  3503. /* Set the current brightness level */
  3504. dsi_panel_bl_handoff(display->panel);
  3505. return rc;
  3506. clks_disabled:
  3507. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  3508. DSI_ALL_CLKS, DSI_CLK_OFF);
  3509. clk_manager_update:
  3510. dsi_display_ctrl_isr_configure(display, false);
  3511. /* Update splash status for clock manager */
  3512. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  3513. false);
  3514. pm_runtime_put_sync(display->drm_dev->dev);
  3515. display->is_cont_splash_enabled = false;
  3516. mutex_unlock(&display->display_lock);
  3517. return rc;
  3518. }
  3519. /**
  3520. * dsi_display_splash_res_cleanup() - cleanup for continuous splash
  3521. * @display: Pointer to dsi display
  3522. * Returns: Zero on success
  3523. */
  3524. int dsi_display_splash_res_cleanup(struct dsi_display *display)
  3525. {
  3526. int rc = 0;
  3527. if (!display->is_cont_splash_enabled)
  3528. return 0;
  3529. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  3530. DSI_ALL_CLKS, DSI_CLK_OFF);
  3531. if (rc)
  3532. pr_err("[%s] failed to disable DSI link clocks, rc=%d\n",
  3533. display->name, rc);
  3534. pm_runtime_put_sync(display->drm_dev->dev);
  3535. display->is_cont_splash_enabled = false;
  3536. /* Update splash status for clock manager */
  3537. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  3538. display->is_cont_splash_enabled);
  3539. return rc;
  3540. }
  3541. static int dsi_display_force_update_dsi_clk(struct dsi_display *display)
  3542. {
  3543. int rc = 0;
  3544. rc = dsi_display_link_clk_force_update_ctrl(display->dsi_clk_handle);
  3545. if (!rc) {
  3546. pr_info("dsi bit clk has been configured to %d\n",
  3547. display->cached_clk_rate);
  3548. atomic_set(&display->clkrate_change_pending, 0);
  3549. } else {
  3550. pr_err("Failed to configure dsi bit clock '%d'. rc = %d\n",
  3551. display->cached_clk_rate, rc);
  3552. }
  3553. return rc;
  3554. }
  3555. static int dsi_display_request_update_dsi_bitrate(struct dsi_display *display,
  3556. u32 bit_clk_rate)
  3557. {
  3558. int rc = 0;
  3559. int i;
  3560. pr_debug("%s:bit rate:%d\n", __func__, bit_clk_rate);
  3561. if (!display->panel) {
  3562. pr_err("Invalid params\n");
  3563. return -EINVAL;
  3564. }
  3565. if (bit_clk_rate == 0) {
  3566. pr_err("Invalid bit clock rate\n");
  3567. return -EINVAL;
  3568. }
  3569. display->config.bit_clk_rate_hz_override = bit_clk_rate;
  3570. display_for_each_ctrl(i, display) {
  3571. struct dsi_display_ctrl *dsi_disp_ctrl = &display->ctrl[i];
  3572. struct dsi_ctrl *ctrl = dsi_disp_ctrl->ctrl;
  3573. u32 num_of_lanes = 0;
  3574. u32 bpp = 3;
  3575. u64 bit_rate, pclk_rate, bit_rate_per_lane, byte_clk_rate;
  3576. struct dsi_host_common_cfg *host_cfg;
  3577. mutex_lock(&ctrl->ctrl_lock);
  3578. host_cfg = &display->panel->host_config;
  3579. if (host_cfg->data_lanes & DSI_DATA_LANE_0)
  3580. num_of_lanes++;
  3581. if (host_cfg->data_lanes & DSI_DATA_LANE_1)
  3582. num_of_lanes++;
  3583. if (host_cfg->data_lanes & DSI_DATA_LANE_2)
  3584. num_of_lanes++;
  3585. if (host_cfg->data_lanes & DSI_DATA_LANE_3)
  3586. num_of_lanes++;
  3587. if (num_of_lanes == 0) {
  3588. pr_err("Invalid lane count\n");
  3589. rc = -EINVAL;
  3590. goto error;
  3591. }
  3592. bit_rate = display->config.bit_clk_rate_hz_override *
  3593. num_of_lanes;
  3594. bit_rate_per_lane = bit_rate;
  3595. do_div(bit_rate_per_lane, num_of_lanes);
  3596. pclk_rate = bit_rate;
  3597. do_div(pclk_rate, (8 * bpp));
  3598. byte_clk_rate = bit_rate_per_lane;
  3599. do_div(byte_clk_rate, 8);
  3600. pr_debug("bit_clk_rate = %llu, bit_clk_rate_per_lane = %llu\n",
  3601. bit_rate, bit_rate_per_lane);
  3602. pr_debug("byte_clk_rate = %llu, pclk_rate = %llu\n",
  3603. byte_clk_rate, pclk_rate);
  3604. ctrl->clk_freq.byte_clk_rate = byte_clk_rate;
  3605. ctrl->clk_freq.pix_clk_rate = pclk_rate;
  3606. rc = dsi_clk_set_link_frequencies(display->dsi_clk_handle,
  3607. ctrl->clk_freq, ctrl->cell_index);
  3608. if (rc) {
  3609. pr_err("Failed to update link frequencies\n");
  3610. goto error;
  3611. }
  3612. ctrl->host_config.bit_clk_rate_hz_override = bit_clk_rate;
  3613. error:
  3614. mutex_unlock(&ctrl->ctrl_lock);
  3615. /* TODO: recover ctrl->clk_freq in case of failure */
  3616. if (rc)
  3617. return rc;
  3618. }
  3619. return 0;
  3620. }
  3621. static ssize_t dynamic_dsi_clock_show(struct device *dev,
  3622. struct device_attribute *attr, char *buf)
  3623. {
  3624. int rc = 0;
  3625. struct dsi_display *display;
  3626. struct dsi_display_ctrl *m_ctrl;
  3627. struct dsi_ctrl *ctrl;
  3628. display = dev_get_drvdata(dev);
  3629. if (!display) {
  3630. pr_err("Invalid display\n");
  3631. return -EINVAL;
  3632. }
  3633. mutex_lock(&display->display_lock);
  3634. m_ctrl = &display->ctrl[display->cmd_master_idx];
  3635. ctrl = m_ctrl->ctrl;
  3636. if (ctrl)
  3637. display->cached_clk_rate = ctrl->clk_freq.byte_clk_rate
  3638. * 8;
  3639. rc = snprintf(buf, PAGE_SIZE, "%d\n", display->cached_clk_rate);
  3640. pr_debug("%s: read dsi clk rate %d\n", __func__,
  3641. display->cached_clk_rate);
  3642. mutex_unlock(&display->display_lock);
  3643. return rc;
  3644. }
  3645. static ssize_t dynamic_dsi_clock_store(struct device *dev,
  3646. struct device_attribute *attr, const char *buf, size_t count)
  3647. {
  3648. int rc = 0;
  3649. int clk_rate;
  3650. struct dsi_display *display;
  3651. display = dev_get_drvdata(dev);
  3652. if (!display) {
  3653. pr_err("Invalid display\n");
  3654. return -EINVAL;
  3655. }
  3656. rc = kstrtoint(buf, DSI_CLOCK_BITRATE_RADIX, &clk_rate);
  3657. if (rc) {
  3658. pr_err("%s: kstrtoint failed. rc=%d\n", __func__, rc);
  3659. return rc;
  3660. }
  3661. if (clk_rate <= 0) {
  3662. pr_err("%s: bitrate should be greater than 0\n", __func__);
  3663. return -EINVAL;
  3664. }
  3665. if (clk_rate == display->cached_clk_rate) {
  3666. pr_info("%s: ignore duplicated DSI clk setting\n", __func__);
  3667. return count;
  3668. }
  3669. pr_info("%s: bitrate param value: '%d'\n", __func__, clk_rate);
  3670. mutex_lock(&display->display_lock);
  3671. display->cached_clk_rate = clk_rate;
  3672. rc = dsi_display_request_update_dsi_bitrate(display, clk_rate);
  3673. if (!rc) {
  3674. pr_info("%s: bit clk is ready to be configured to '%d'\n",
  3675. __func__, clk_rate);
  3676. } else {
  3677. pr_err("%s: Failed to prepare to configure '%d'. rc = %d\n",
  3678. __func__, clk_rate, rc);
  3679. /*Caching clock failed, so don't go on doing so.*/
  3680. atomic_set(&display->clkrate_change_pending, 0);
  3681. display->cached_clk_rate = 0;
  3682. mutex_unlock(&display->display_lock);
  3683. return rc;
  3684. }
  3685. atomic_set(&display->clkrate_change_pending, 1);
  3686. mutex_unlock(&display->display_lock);
  3687. return count;
  3688. }
  3689. static DEVICE_ATTR_RW(dynamic_dsi_clock);
  3690. static struct attribute *dynamic_dsi_clock_fs_attrs[] = {
  3691. &dev_attr_dynamic_dsi_clock.attr,
  3692. NULL,
  3693. };
  3694. static struct attribute_group dynamic_dsi_clock_fs_attrs_group = {
  3695. .attrs = dynamic_dsi_clock_fs_attrs,
  3696. };
  3697. static int dsi_display_sysfs_init(struct dsi_display *display)
  3698. {
  3699. int rc = 0;
  3700. struct device *dev = &display->pdev->dev;
  3701. if (display->panel->panel_mode == DSI_OP_CMD_MODE)
  3702. rc = sysfs_create_group(&dev->kobj,
  3703. &dynamic_dsi_clock_fs_attrs_group);
  3704. return rc;
  3705. }
  3706. static int dsi_display_sysfs_deinit(struct dsi_display *display)
  3707. {
  3708. struct device *dev = &display->pdev->dev;
  3709. if (display->panel->panel_mode == DSI_OP_CMD_MODE)
  3710. sysfs_remove_group(&dev->kobj,
  3711. &dynamic_dsi_clock_fs_attrs_group);
  3712. return 0;
  3713. }
  3714. /**
  3715. * dsi_display_bind - bind dsi device with controlling device
  3716. * @dev: Pointer to base of platform device
  3717. * @master: Pointer to container of drm device
  3718. * @data: Pointer to private data
  3719. * Returns: Zero on success
  3720. */
  3721. static int dsi_display_bind(struct device *dev,
  3722. struct device *master,
  3723. void *data)
  3724. {
  3725. struct dsi_display_ctrl *display_ctrl;
  3726. struct drm_device *drm;
  3727. struct dsi_display *display;
  3728. struct dsi_clk_info info;
  3729. struct clk_ctrl_cb clk_cb;
  3730. void *handle = NULL;
  3731. struct platform_device *pdev = to_platform_device(dev);
  3732. char *client1 = "dsi_clk_client";
  3733. char *client2 = "mdp_event_client";
  3734. int i, rc = 0;
  3735. if (!dev || !pdev || !master) {
  3736. pr_err("invalid param(s), dev %pK, pdev %pK, master %pK\n",
  3737. dev, pdev, master);
  3738. return -EINVAL;
  3739. }
  3740. drm = dev_get_drvdata(master);
  3741. display = platform_get_drvdata(pdev);
  3742. if (!drm || !display) {
  3743. pr_err("invalid param(s), drm %pK, display %pK\n",
  3744. drm, display);
  3745. return -EINVAL;
  3746. }
  3747. if (!display->panel_node)
  3748. return 0;
  3749. if (!display->fw)
  3750. display->name = display->panel_node->name;
  3751. mutex_lock(&display->display_lock);
  3752. rc = dsi_display_debugfs_init(display);
  3753. if (rc) {
  3754. pr_err("[%s] debugfs init failed, rc=%d\n", display->name, rc);
  3755. goto error;
  3756. }
  3757. atomic_set(&display->clkrate_change_pending, 0);
  3758. display->cached_clk_rate = 0;
  3759. rc = dsi_display_sysfs_init(display);
  3760. if (rc) {
  3761. pr_err("[%s] sysfs init failed, rc=%d\n", display->name, rc);
  3762. goto error;
  3763. }
  3764. memset(&info, 0x0, sizeof(info));
  3765. display_for_each_ctrl(i, display) {
  3766. display_ctrl = &display->ctrl[i];
  3767. rc = dsi_ctrl_drv_init(display_ctrl->ctrl, display->root);
  3768. if (rc) {
  3769. pr_err("[%s] failed to initialize ctrl[%d], rc=%d\n",
  3770. display->name, i, rc);
  3771. goto error_ctrl_deinit;
  3772. }
  3773. display_ctrl->ctrl->horiz_index = i;
  3774. rc = dsi_phy_drv_init(display_ctrl->phy);
  3775. if (rc) {
  3776. pr_err("[%s] Failed to initialize phy[%d], rc=%d\n",
  3777. display->name, i, rc);
  3778. (void)dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  3779. goto error_ctrl_deinit;
  3780. }
  3781. memcpy(&info.c_clks[i],
  3782. (&display_ctrl->ctrl->clk_info.core_clks),
  3783. sizeof(struct dsi_core_clk_info));
  3784. memcpy(&info.l_hs_clks[i],
  3785. (&display_ctrl->ctrl->clk_info.hs_link_clks),
  3786. sizeof(struct dsi_link_hs_clk_info));
  3787. memcpy(&info.l_lp_clks[i],
  3788. (&display_ctrl->ctrl->clk_info.lp_link_clks),
  3789. sizeof(struct dsi_link_lp_clk_info));
  3790. info.c_clks[i].drm = drm;
  3791. info.bus_handle[i] =
  3792. display_ctrl->ctrl->axi_bus_info.bus_handle;
  3793. info.ctrl_index[i] = display_ctrl->ctrl->cell_index;
  3794. }
  3795. info.pre_clkoff_cb = dsi_pre_clkoff_cb;
  3796. info.pre_clkon_cb = dsi_pre_clkon_cb;
  3797. info.post_clkoff_cb = dsi_post_clkoff_cb;
  3798. info.post_clkon_cb = dsi_post_clkon_cb;
  3799. info.priv_data = display;
  3800. info.master_ndx = display->clk_master_idx;
  3801. info.dsi_ctrl_count = display->ctrl_count;
  3802. snprintf(info.name, MAX_STRING_LEN,
  3803. "DSI_MNGR-%s", display->name);
  3804. display->clk_mngr = dsi_display_clk_mngr_register(&info);
  3805. if (IS_ERR_OR_NULL(display->clk_mngr)) {
  3806. rc = PTR_ERR(display->clk_mngr);
  3807. display->clk_mngr = NULL;
  3808. pr_err("dsi clock registration failed, rc = %d\n", rc);
  3809. goto error_ctrl_deinit;
  3810. }
  3811. handle = dsi_register_clk_handle(display->clk_mngr, client1);
  3812. if (IS_ERR_OR_NULL(handle)) {
  3813. rc = PTR_ERR(handle);
  3814. pr_err("failed to register %s client, rc = %d\n",
  3815. client1, rc);
  3816. goto error_clk_deinit;
  3817. } else {
  3818. display->dsi_clk_handle = handle;
  3819. }
  3820. handle = dsi_register_clk_handle(display->clk_mngr, client2);
  3821. if (IS_ERR_OR_NULL(handle)) {
  3822. rc = PTR_ERR(handle);
  3823. pr_err("failed to register %s client, rc = %d\n",
  3824. client2, rc);
  3825. goto error_clk_client_deinit;
  3826. } else {
  3827. display->mdp_clk_handle = handle;
  3828. }
  3829. clk_cb.priv = display;
  3830. clk_cb.dsi_clk_cb = dsi_display_clk_ctrl_cb;
  3831. display_for_each_ctrl(i, display) {
  3832. display_ctrl = &display->ctrl[i];
  3833. rc = dsi_ctrl_clk_cb_register(display_ctrl->ctrl, &clk_cb);
  3834. if (rc) {
  3835. pr_err("[%s] failed to register ctrl clk_cb[%d], rc=%d\n",
  3836. display->name, i, rc);
  3837. goto error_ctrl_deinit;
  3838. }
  3839. rc = dsi_phy_clk_cb_register(display_ctrl->phy, &clk_cb);
  3840. if (rc) {
  3841. pr_err("[%s] failed to register phy clk_cb[%d], rc=%d\n",
  3842. display->name, i, rc);
  3843. goto error_ctrl_deinit;
  3844. }
  3845. }
  3846. rc = dsi_display_mipi_host_init(display);
  3847. if (rc) {
  3848. pr_err("[%s] failed to initialize mipi host, rc=%d\n",
  3849. display->name, rc);
  3850. goto error_ctrl_deinit;
  3851. }
  3852. rc = dsi_panel_drv_init(display->panel, &display->host);
  3853. if (rc) {
  3854. if (rc != -EPROBE_DEFER)
  3855. pr_err("[%s] failed to initialize panel driver, rc=%d\n",
  3856. display->name, rc);
  3857. goto error_host_deinit;
  3858. }
  3859. pr_info("Successfully bind display panel '%s'\n", display->name);
  3860. display->drm_dev = drm;
  3861. display_for_each_ctrl(i, display) {
  3862. display_ctrl = &display->ctrl[i];
  3863. if (!display_ctrl->phy || !display_ctrl->ctrl)
  3864. continue;
  3865. rc = dsi_phy_set_clk_freq(display_ctrl->phy,
  3866. &display_ctrl->ctrl->clk_freq);
  3867. if (rc) {
  3868. pr_err("[%s] failed to set phy clk freq, rc=%d\n",
  3869. display->name, rc);
  3870. goto error;
  3871. }
  3872. }
  3873. /* register te irq handler */
  3874. dsi_display_register_te_irq(display);
  3875. goto error;
  3876. error_host_deinit:
  3877. (void)dsi_display_mipi_host_deinit(display);
  3878. error_clk_client_deinit:
  3879. (void)dsi_deregister_clk_handle(display->dsi_clk_handle);
  3880. error_clk_deinit:
  3881. (void)dsi_display_clk_mngr_deregister(display->clk_mngr);
  3882. error_ctrl_deinit:
  3883. for (i = i - 1; i >= 0; i--) {
  3884. display_ctrl = &display->ctrl[i];
  3885. (void)dsi_phy_drv_deinit(display_ctrl->phy);
  3886. (void)dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  3887. }
  3888. (void)dsi_display_sysfs_deinit(display);
  3889. (void)dsi_display_debugfs_deinit(display);
  3890. error:
  3891. mutex_unlock(&display->display_lock);
  3892. return rc;
  3893. }
  3894. /**
  3895. * dsi_display_unbind - unbind dsi from controlling device
  3896. * @dev: Pointer to base of platform device
  3897. * @master: Pointer to container of drm device
  3898. * @data: Pointer to private data
  3899. */
  3900. static void dsi_display_unbind(struct device *dev,
  3901. struct device *master, void *data)
  3902. {
  3903. struct dsi_display_ctrl *display_ctrl;
  3904. struct dsi_display *display;
  3905. struct platform_device *pdev = to_platform_device(dev);
  3906. int i, rc = 0;
  3907. if (!dev || !pdev) {
  3908. pr_err("invalid param(s)\n");
  3909. return;
  3910. }
  3911. display = platform_get_drvdata(pdev);
  3912. if (!display) {
  3913. pr_err("invalid display\n");
  3914. return;
  3915. }
  3916. mutex_lock(&display->display_lock);
  3917. rc = dsi_panel_drv_deinit(display->panel);
  3918. if (rc)
  3919. pr_err("[%s] failed to deinit panel driver, rc=%d\n",
  3920. display->name, rc);
  3921. rc = dsi_display_mipi_host_deinit(display);
  3922. if (rc)
  3923. pr_err("[%s] failed to deinit mipi hosts, rc=%d\n",
  3924. display->name,
  3925. rc);
  3926. display_for_each_ctrl(i, display) {
  3927. display_ctrl = &display->ctrl[i];
  3928. rc = dsi_phy_drv_deinit(display_ctrl->phy);
  3929. if (rc)
  3930. pr_err("[%s] failed to deinit phy%d driver, rc=%d\n",
  3931. display->name, i, rc);
  3932. rc = dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  3933. if (rc)
  3934. pr_err("[%s] failed to deinit ctrl%d driver, rc=%d\n",
  3935. display->name, i, rc);
  3936. }
  3937. atomic_set(&display->clkrate_change_pending, 0);
  3938. (void)dsi_display_sysfs_deinit(display);
  3939. (void)dsi_display_debugfs_deinit(display);
  3940. mutex_unlock(&display->display_lock);
  3941. }
  3942. static const struct component_ops dsi_display_comp_ops = {
  3943. .bind = dsi_display_bind,
  3944. .unbind = dsi_display_unbind,
  3945. };
  3946. static struct platform_driver dsi_display_driver = {
  3947. .probe = dsi_display_dev_probe,
  3948. .remove = dsi_display_dev_remove,
  3949. .driver = {
  3950. .name = "msm-dsi-display",
  3951. .of_match_table = dsi_display_dt_match,
  3952. .suppress_bind_attrs = true,
  3953. },
  3954. };
  3955. static int dsi_display_init(struct dsi_display *display)
  3956. {
  3957. int rc = 0;
  3958. struct platform_device *pdev = display->pdev;
  3959. mutex_init(&display->display_lock);
  3960. rc = _dsi_display_dev_init(display);
  3961. if (rc) {
  3962. pr_err("device init failed, rc=%d\n", rc);
  3963. goto end;
  3964. }
  3965. rc = component_add(&pdev->dev, &dsi_display_comp_ops);
  3966. if (rc)
  3967. pr_err("component add failed, rc=%d\n", rc);
  3968. pr_debug("component add success: %s\n", display->name);
  3969. end:
  3970. return rc;
  3971. }
  3972. static void dsi_display_firmware_display(const struct firmware *fw,
  3973. void *context)
  3974. {
  3975. struct dsi_display *display = context;
  3976. if (fw) {
  3977. pr_debug("reading data from firmware, size=%zd\n",
  3978. fw->size);
  3979. display->fw = fw;
  3980. display->name = "dsi_firmware_display";
  3981. }
  3982. if (dsi_display_init(display))
  3983. return;
  3984. pr_debug("success\n");
  3985. }
  3986. int dsi_display_dev_probe(struct platform_device *pdev)
  3987. {
  3988. struct dsi_display *display = NULL;
  3989. struct device_node *node = NULL, *panel_node = NULL, *mdp_node = NULL;
  3990. int rc = 0, index = DSI_PRIMARY;
  3991. bool firm_req = false;
  3992. struct dsi_display_boot_param *boot_disp;
  3993. if (!pdev || !pdev->dev.of_node) {
  3994. pr_err("pdev not found\n");
  3995. rc = -ENODEV;
  3996. goto end;
  3997. }
  3998. display = devm_kzalloc(&pdev->dev, sizeof(*display), GFP_KERNEL);
  3999. if (!display) {
  4000. rc = -ENOMEM;
  4001. goto end;
  4002. }
  4003. display->display_type = of_get_property(pdev->dev.of_node,
  4004. "label", NULL);
  4005. if (!display->display_type)
  4006. display->display_type = "primary";
  4007. if (!strcmp(display->display_type, "secondary"))
  4008. index = DSI_SECONDARY;
  4009. boot_disp = &boot_displays[index];
  4010. node = pdev->dev.of_node;
  4011. if (boot_disp->boot_disp_en) {
  4012. mdp_node = of_parse_phandle(node, "qcom,mdp", 0);
  4013. if (!mdp_node) {
  4014. pr_err("mdp_node not found\n");
  4015. rc = -ENODEV;
  4016. goto end;
  4017. }
  4018. /* The panel name should be same as UEFI name index */
  4019. panel_node = of_find_node_by_name(mdp_node, boot_disp->name);
  4020. if (!panel_node)
  4021. pr_warn("panel_node %s not found\n", boot_disp->name);
  4022. } else {
  4023. panel_node = of_parse_phandle(node,
  4024. "qcom,dsi-default-panel", 0);
  4025. if (!panel_node)
  4026. pr_warn("default panel not found\n");
  4027. if (IS_ENABLED(CONFIG_DSI_PARSER))
  4028. firm_req = !request_firmware_nowait(
  4029. THIS_MODULE, 1, "dsi_prop",
  4030. &pdev->dev, GFP_KERNEL, display,
  4031. dsi_display_firmware_display);
  4032. }
  4033. boot_disp->node = pdev->dev.of_node;
  4034. boot_disp->disp = display;
  4035. display->panel_node = panel_node;
  4036. display->pdev = pdev;
  4037. display->boot_disp = boot_disp;
  4038. dsi_display_parse_cmdline_topology(display, index);
  4039. platform_set_drvdata(pdev, display);
  4040. /* initialize display in firmware callback */
  4041. if (!firm_req) {
  4042. rc = dsi_display_init(display);
  4043. if (rc)
  4044. goto end;
  4045. }
  4046. return 0;
  4047. end:
  4048. if (display)
  4049. devm_kfree(&pdev->dev, display);
  4050. return rc;
  4051. }
  4052. int dsi_display_dev_remove(struct platform_device *pdev)
  4053. {
  4054. int rc = 0;
  4055. struct dsi_display *display;
  4056. if (!pdev) {
  4057. pr_err("Invalid device\n");
  4058. return -EINVAL;
  4059. }
  4060. display = platform_get_drvdata(pdev);
  4061. /* decrement ref count */
  4062. of_node_put(display->panel_node);
  4063. (void)_dsi_display_dev_deinit(display);
  4064. platform_set_drvdata(pdev, NULL);
  4065. devm_kfree(&pdev->dev, display);
  4066. return rc;
  4067. }
  4068. int dsi_display_get_num_of_displays(void)
  4069. {
  4070. int i, count = 0;
  4071. for (i = 0; i < MAX_DSI_ACTIVE_DISPLAY; i++) {
  4072. struct dsi_display *display = boot_displays[i].disp;
  4073. if (display && display->panel_node)
  4074. count++;
  4075. }
  4076. return count;
  4077. }
  4078. int dsi_display_get_active_displays(void **display_array, u32 max_display_count)
  4079. {
  4080. int index = 0, count = 0;
  4081. if (!display_array || !max_display_count) {
  4082. pr_err("invalid params\n");
  4083. return 0;
  4084. }
  4085. for (index = 0; index < MAX_DSI_ACTIVE_DISPLAY; index++) {
  4086. struct dsi_display *display = boot_displays[index].disp;
  4087. if (display && display->panel_node)
  4088. display_array[count++] = display;
  4089. }
  4090. return count;
  4091. }
  4092. int dsi_display_drm_bridge_init(struct dsi_display *display,
  4093. struct drm_encoder *enc)
  4094. {
  4095. int rc = 0;
  4096. struct dsi_bridge *bridge;
  4097. struct msm_drm_private *priv = NULL;
  4098. if (!display || !display->drm_dev || !enc) {
  4099. pr_err("invalid param(s)\n");
  4100. return -EINVAL;
  4101. }
  4102. mutex_lock(&display->display_lock);
  4103. priv = display->drm_dev->dev_private;
  4104. if (!priv) {
  4105. pr_err("Private data is not present\n");
  4106. rc = -EINVAL;
  4107. goto error;
  4108. }
  4109. if (display->bridge) {
  4110. pr_err("display is already initialize\n");
  4111. goto error;
  4112. }
  4113. bridge = dsi_drm_bridge_init(display, display->drm_dev, enc);
  4114. if (IS_ERR_OR_NULL(bridge)) {
  4115. rc = PTR_ERR(bridge);
  4116. pr_err("[%s] brige init failed, %d\n", display->name, rc);
  4117. goto error;
  4118. }
  4119. display->bridge = bridge;
  4120. priv->bridges[priv->num_bridges++] = &bridge->base;
  4121. error:
  4122. mutex_unlock(&display->display_lock);
  4123. return rc;
  4124. }
  4125. int dsi_display_drm_bridge_deinit(struct dsi_display *display)
  4126. {
  4127. int rc = 0;
  4128. if (!display) {
  4129. pr_err("Invalid params\n");
  4130. return -EINVAL;
  4131. }
  4132. mutex_lock(&display->display_lock);
  4133. dsi_drm_bridge_cleanup(display->bridge);
  4134. display->bridge = NULL;
  4135. mutex_unlock(&display->display_lock);
  4136. return rc;
  4137. }
  4138. /* Hook functions to call external connector, pointer validation is
  4139. * done in dsi_display_drm_ext_bridge_init.
  4140. */
  4141. static enum drm_connector_status dsi_display_drm_ext_detect(
  4142. struct drm_connector *connector,
  4143. bool force,
  4144. void *disp)
  4145. {
  4146. struct dsi_display *display = disp;
  4147. return display->ext_conn->funcs->detect(display->ext_conn, force);
  4148. }
  4149. static int dsi_display_drm_ext_get_modes(
  4150. struct drm_connector *connector, void *disp)
  4151. {
  4152. struct dsi_display *display = disp;
  4153. struct drm_display_mode *pmode, *pt;
  4154. int count;
  4155. /* if there are modes defined in panel, ignore external modes */
  4156. if (display->panel->num_timing_nodes)
  4157. return dsi_connector_get_modes(connector, disp);
  4158. count = display->ext_conn->helper_private->get_modes(
  4159. display->ext_conn);
  4160. list_for_each_entry_safe(pmode, pt,
  4161. &display->ext_conn->probed_modes, head) {
  4162. list_move_tail(&pmode->head, &connector->probed_modes);
  4163. }
  4164. connector->display_info = display->ext_conn->display_info;
  4165. return count;
  4166. }
  4167. static enum drm_mode_status dsi_display_drm_ext_mode_valid(
  4168. struct drm_connector *connector,
  4169. struct drm_display_mode *mode,
  4170. void *disp)
  4171. {
  4172. struct dsi_display *display = disp;
  4173. enum drm_mode_status status;
  4174. /* always do internal mode_valid check */
  4175. status = dsi_conn_mode_valid(connector, mode, disp);
  4176. if (status != MODE_OK)
  4177. return status;
  4178. return display->ext_conn->helper_private->mode_valid(
  4179. display->ext_conn, mode);
  4180. }
  4181. static int dsi_display_drm_ext_atomic_check(struct drm_connector *connector,
  4182. void *disp,
  4183. struct drm_connector_state *c_state)
  4184. {
  4185. struct dsi_display *display = disp;
  4186. return display->ext_conn->helper_private->atomic_check(
  4187. display->ext_conn, c_state);
  4188. }
  4189. static int dsi_display_ext_get_info(struct drm_connector *connector,
  4190. struct msm_display_info *info, void *disp)
  4191. {
  4192. struct dsi_display *display;
  4193. int i;
  4194. if (!info || !disp) {
  4195. pr_err("invalid params\n");
  4196. return -EINVAL;
  4197. }
  4198. display = disp;
  4199. if (!display->panel) {
  4200. pr_err("invalid display panel\n");
  4201. return -EINVAL;
  4202. }
  4203. mutex_lock(&display->display_lock);
  4204. memset(info, 0, sizeof(struct msm_display_info));
  4205. info->intf_type = DRM_MODE_CONNECTOR_DSI;
  4206. info->num_of_h_tiles = display->ctrl_count;
  4207. for (i = 0; i < info->num_of_h_tiles; i++)
  4208. info->h_tile_instance[i] = display->ctrl[i].ctrl->cell_index;
  4209. info->is_connected = connector->status != connector_status_disconnected;
  4210. if (!strcmp(display->display_type, "primary"))
  4211. info->display_type = SDE_CONNECTOR_PRIMARY;
  4212. else if (!strcmp(display->display_type, "secondary"))
  4213. info->display_type = SDE_CONNECTOR_SECONDARY;
  4214. info->capabilities |= (MSM_DISPLAY_CAP_VID_MODE |
  4215. MSM_DISPLAY_CAP_EDID | MSM_DISPLAY_CAP_HOT_PLUG);
  4216. info->curr_panel_mode = MSM_DISPLAY_VIDEO_MODE;
  4217. mutex_unlock(&display->display_lock);
  4218. return 0;
  4219. }
  4220. static int dsi_display_ext_get_mode_info(struct drm_connector *connector,
  4221. const struct drm_display_mode *drm_mode,
  4222. struct msm_mode_info *mode_info,
  4223. u32 max_mixer_width, void *display)
  4224. {
  4225. struct msm_display_topology *topology;
  4226. if (!drm_mode || !mode_info)
  4227. return -EINVAL;
  4228. memset(mode_info, 0, sizeof(*mode_info));
  4229. mode_info->frame_rate = drm_mode->vrefresh;
  4230. mode_info->vtotal = drm_mode->vtotal;
  4231. topology = &mode_info->topology;
  4232. topology->num_lm = (max_mixer_width <= drm_mode->hdisplay) ? 2 : 1;
  4233. topology->num_enc = 0;
  4234. topology->num_intf = topology->num_lm;
  4235. mode_info->comp_info.comp_type = MSM_DISPLAY_COMPRESSION_NONE;
  4236. return 0;
  4237. }
  4238. static struct dsi_display_ext_bridge *dsi_display_ext_get_bridge(
  4239. struct drm_bridge *bridge)
  4240. {
  4241. struct msm_drm_private *priv;
  4242. struct sde_kms *sde_kms;
  4243. struct list_head *connector_list;
  4244. struct drm_connector *conn_iter;
  4245. struct sde_connector *sde_conn;
  4246. struct dsi_display *display;
  4247. int i;
  4248. if (!bridge || !bridge->encoder) {
  4249. SDE_ERROR("invalid argument\n");
  4250. return NULL;
  4251. }
  4252. priv = bridge->dev->dev_private;
  4253. sde_kms = to_sde_kms(priv->kms);
  4254. connector_list = &sde_kms->dev->mode_config.connector_list;
  4255. list_for_each_entry(conn_iter, connector_list, head) {
  4256. sde_conn = to_sde_connector(conn_iter);
  4257. if (sde_conn->encoder == bridge->encoder) {
  4258. display = sde_conn->display;
  4259. for (i = 0; i < display->ctrl_count; i++) {
  4260. if (display->ext_bridge[i].bridge == bridge)
  4261. return &display->ext_bridge[i];
  4262. }
  4263. }
  4264. }
  4265. return NULL;
  4266. }
  4267. static void dsi_display_drm_ext_adjust_timing(
  4268. const struct dsi_display *display,
  4269. struct drm_display_mode *mode)
  4270. {
  4271. mode->hdisplay /= display->ctrl_count;
  4272. mode->hsync_start /= display->ctrl_count;
  4273. mode->hsync_end /= display->ctrl_count;
  4274. mode->htotal /= display->ctrl_count;
  4275. mode->hskew /= display->ctrl_count;
  4276. mode->clock /= display->ctrl_count;
  4277. }
  4278. static enum drm_mode_status dsi_display_drm_ext_bridge_mode_valid(
  4279. struct drm_bridge *bridge,
  4280. const struct drm_display_mode *mode)
  4281. {
  4282. struct dsi_display_ext_bridge *ext_bridge;
  4283. struct drm_display_mode tmp;
  4284. ext_bridge = dsi_display_ext_get_bridge(bridge);
  4285. if (!ext_bridge)
  4286. return MODE_ERROR;
  4287. tmp = *mode;
  4288. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  4289. return ext_bridge->orig_funcs->mode_valid(bridge, &tmp);
  4290. }
  4291. static bool dsi_display_drm_ext_bridge_mode_fixup(
  4292. struct drm_bridge *bridge,
  4293. const struct drm_display_mode *mode,
  4294. struct drm_display_mode *adjusted_mode)
  4295. {
  4296. struct dsi_display_ext_bridge *ext_bridge;
  4297. struct drm_display_mode tmp;
  4298. ext_bridge = dsi_display_ext_get_bridge(bridge);
  4299. if (!ext_bridge)
  4300. return false;
  4301. tmp = *mode;
  4302. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  4303. return ext_bridge->orig_funcs->mode_fixup(bridge, &tmp, &tmp);
  4304. }
  4305. static void dsi_display_drm_ext_bridge_mode_set(
  4306. struct drm_bridge *bridge,
  4307. struct drm_display_mode *mode,
  4308. struct drm_display_mode *adjusted_mode)
  4309. {
  4310. struct dsi_display_ext_bridge *ext_bridge;
  4311. struct drm_display_mode tmp;
  4312. ext_bridge = dsi_display_ext_get_bridge(bridge);
  4313. if (!ext_bridge)
  4314. return;
  4315. tmp = *mode;
  4316. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  4317. ext_bridge->orig_funcs->mode_set(bridge, &tmp, &tmp);
  4318. }
  4319. static int dsi_host_ext_attach(struct mipi_dsi_host *host,
  4320. struct mipi_dsi_device *dsi)
  4321. {
  4322. struct dsi_display *display = to_dsi_display(host);
  4323. struct dsi_panel *panel;
  4324. if (!host || !dsi || !display->panel) {
  4325. pr_err("Invalid param\n");
  4326. return -EINVAL;
  4327. }
  4328. pr_debug("DSI[%s]: channel=%d, lanes=%d, format=%d, mode_flags=%lx\n",
  4329. dsi->name, dsi->channel, dsi->lanes,
  4330. dsi->format, dsi->mode_flags);
  4331. panel = display->panel;
  4332. panel->host_config.data_lanes = 0;
  4333. if (dsi->lanes > 0)
  4334. panel->host_config.data_lanes |= DSI_DATA_LANE_0;
  4335. if (dsi->lanes > 1)
  4336. panel->host_config.data_lanes |= DSI_DATA_LANE_1;
  4337. if (dsi->lanes > 2)
  4338. panel->host_config.data_lanes |= DSI_DATA_LANE_2;
  4339. if (dsi->lanes > 3)
  4340. panel->host_config.data_lanes |= DSI_DATA_LANE_3;
  4341. switch (dsi->format) {
  4342. case MIPI_DSI_FMT_RGB888:
  4343. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB888;
  4344. break;
  4345. case MIPI_DSI_FMT_RGB666:
  4346. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB666_LOOSE;
  4347. break;
  4348. case MIPI_DSI_FMT_RGB666_PACKED:
  4349. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB666;
  4350. break;
  4351. case MIPI_DSI_FMT_RGB565:
  4352. default:
  4353. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB565;
  4354. break;
  4355. }
  4356. if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) {
  4357. panel->panel_mode = DSI_OP_VIDEO_MODE;
  4358. if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST)
  4359. panel->video_config.traffic_mode =
  4360. DSI_VIDEO_TRAFFIC_BURST_MODE;
  4361. else if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE)
  4362. panel->video_config.traffic_mode =
  4363. DSI_VIDEO_TRAFFIC_SYNC_PULSES;
  4364. else
  4365. panel->video_config.traffic_mode =
  4366. DSI_VIDEO_TRAFFIC_SYNC_START_EVENTS;
  4367. panel->video_config.hsa_lp11_en =
  4368. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSA;
  4369. panel->video_config.hbp_lp11_en =
  4370. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HBP;
  4371. panel->video_config.hfp_lp11_en =
  4372. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HFP;
  4373. panel->video_config.pulse_mode_hsa_he =
  4374. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSE;
  4375. panel->video_config.bllp_lp11_en =
  4376. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BLLP;
  4377. panel->video_config.eof_bllp_lp11_en =
  4378. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_EOF_BLLP;
  4379. } else {
  4380. panel->panel_mode = DSI_OP_CMD_MODE;
  4381. pr_err("command mode not supported by ext bridge\n");
  4382. return -ENOTSUPP;
  4383. }
  4384. panel->bl_config.type = DSI_BACKLIGHT_UNKNOWN;
  4385. return 0;
  4386. }
  4387. static struct mipi_dsi_host_ops dsi_host_ext_ops = {
  4388. .attach = dsi_host_ext_attach,
  4389. .detach = dsi_host_detach,
  4390. .transfer = dsi_host_transfer,
  4391. };
  4392. int dsi_display_drm_ext_bridge_init(struct dsi_display *display,
  4393. struct drm_encoder *encoder, struct drm_connector *connector)
  4394. {
  4395. struct drm_device *drm = encoder->dev;
  4396. struct drm_bridge *bridge = encoder->bridge;
  4397. struct drm_bridge *ext_bridge;
  4398. struct drm_connector *ext_conn;
  4399. struct sde_connector *sde_conn = to_sde_connector(connector);
  4400. struct drm_bridge *prev_bridge = bridge;
  4401. int rc = 0, i;
  4402. for (i = 0; i < display->ext_bridge_cnt; i++) {
  4403. struct dsi_display_ext_bridge *ext_bridge_info =
  4404. &display->ext_bridge[i];
  4405. /* return if ext bridge is already initialized */
  4406. if (ext_bridge_info->bridge)
  4407. return 0;
  4408. ext_bridge = of_drm_find_bridge(ext_bridge_info->node_of);
  4409. if (IS_ERR_OR_NULL(ext_bridge)) {
  4410. rc = PTR_ERR(ext_bridge);
  4411. pr_err("failed to find ext bridge\n");
  4412. goto error;
  4413. }
  4414. /* override functions for mode adjustment */
  4415. if (display->ext_bridge_cnt > 1) {
  4416. ext_bridge_info->bridge_funcs = *ext_bridge->funcs;
  4417. if (ext_bridge->funcs->mode_fixup)
  4418. ext_bridge_info->bridge_funcs.mode_fixup =
  4419. dsi_display_drm_ext_bridge_mode_fixup;
  4420. if (ext_bridge->funcs->mode_valid)
  4421. ext_bridge_info->bridge_funcs.mode_valid =
  4422. dsi_display_drm_ext_bridge_mode_valid;
  4423. if (ext_bridge->funcs->mode_set)
  4424. ext_bridge_info->bridge_funcs.mode_set =
  4425. dsi_display_drm_ext_bridge_mode_set;
  4426. ext_bridge_info->orig_funcs = ext_bridge->funcs;
  4427. ext_bridge->funcs = &ext_bridge_info->bridge_funcs;
  4428. }
  4429. rc = drm_bridge_attach(encoder, ext_bridge, prev_bridge);
  4430. if (rc) {
  4431. pr_err("[%s] ext brige attach failed, %d\n",
  4432. display->name, rc);
  4433. goto error;
  4434. }
  4435. ext_bridge_info->display = display;
  4436. ext_bridge_info->bridge = ext_bridge;
  4437. prev_bridge = ext_bridge;
  4438. /* ext bridge will init its own connector during attach,
  4439. * we need to extract it out of the connector list
  4440. */
  4441. spin_lock_irq(&drm->mode_config.connector_list_lock);
  4442. ext_conn = list_last_entry(&drm->mode_config.connector_list,
  4443. struct drm_connector, head);
  4444. if (ext_conn && ext_conn != connector &&
  4445. ext_conn->encoder_ids[0] == bridge->encoder->base.id) {
  4446. list_del_init(&ext_conn->head);
  4447. display->ext_conn = ext_conn;
  4448. }
  4449. spin_unlock_irq(&drm->mode_config.connector_list_lock);
  4450. /* if there is no valid external connector created, or in split
  4451. * mode, default setting is used from panel defined in DT file.
  4452. */
  4453. if (!display->ext_conn ||
  4454. !display->ext_conn->funcs ||
  4455. !display->ext_conn->helper_private ||
  4456. display->ext_bridge_cnt > 1) {
  4457. display->ext_conn = NULL;
  4458. continue;
  4459. }
  4460. /* otherwise, hook up the functions to use external connector */
  4461. if (display->ext_conn->funcs->detect)
  4462. sde_conn->ops.detect = dsi_display_drm_ext_detect;
  4463. if (display->ext_conn->helper_private->get_modes)
  4464. sde_conn->ops.get_modes =
  4465. dsi_display_drm_ext_get_modes;
  4466. if (display->ext_conn->helper_private->mode_valid)
  4467. sde_conn->ops.mode_valid =
  4468. dsi_display_drm_ext_mode_valid;
  4469. if (display->ext_conn->helper_private->atomic_check)
  4470. sde_conn->ops.atomic_check =
  4471. dsi_display_drm_ext_atomic_check;
  4472. sde_conn->ops.get_info =
  4473. dsi_display_ext_get_info;
  4474. sde_conn->ops.get_mode_info =
  4475. dsi_display_ext_get_mode_info;
  4476. /* add support to attach/detach */
  4477. display->host.ops = &dsi_host_ext_ops;
  4478. }
  4479. return 0;
  4480. error:
  4481. return rc;
  4482. }
  4483. int dsi_display_get_info(struct drm_connector *connector,
  4484. struct msm_display_info *info, void *disp)
  4485. {
  4486. struct dsi_display *display;
  4487. struct dsi_panel_phy_props phy_props;
  4488. int i, rc;
  4489. if (!info || !disp) {
  4490. pr_err("invalid params\n");
  4491. return -EINVAL;
  4492. }
  4493. display = disp;
  4494. if (!display->panel) {
  4495. pr_err("invalid display panel\n");
  4496. return -EINVAL;
  4497. }
  4498. mutex_lock(&display->display_lock);
  4499. rc = dsi_panel_get_phy_props(display->panel, &phy_props);
  4500. if (rc) {
  4501. pr_err("[%s] failed to get panel phy props, rc=%d\n",
  4502. display->name, rc);
  4503. goto error;
  4504. }
  4505. memset(info, 0, sizeof(struct msm_display_info));
  4506. info->intf_type = DRM_MODE_CONNECTOR_DSI;
  4507. info->num_of_h_tiles = display->ctrl_count;
  4508. for (i = 0; i < info->num_of_h_tiles; i++)
  4509. info->h_tile_instance[i] = display->ctrl[i].ctrl->cell_index;
  4510. info->is_connected = true;
  4511. if (!strcmp(display->display_type, "primary"))
  4512. info->display_type = SDE_CONNECTOR_PRIMARY;
  4513. else if (!strcmp(display->display_type, "secondary"))
  4514. info->display_type = SDE_CONNECTOR_SECONDARY;
  4515. info->width_mm = phy_props.panel_width_mm;
  4516. info->height_mm = phy_props.panel_height_mm;
  4517. info->max_width = 1920;
  4518. info->max_height = 1080;
  4519. info->qsync_min_fps =
  4520. display->panel->qsync_min_fps;
  4521. switch (display->panel->panel_mode) {
  4522. case DSI_OP_VIDEO_MODE:
  4523. info->curr_panel_mode = MSM_DISPLAY_VIDEO_MODE;
  4524. info->capabilities |= MSM_DISPLAY_CAP_VID_MODE;
  4525. if (display->panel->panel_mode_switch_enabled)
  4526. info->capabilities |= MSM_DISPLAY_CAP_CMD_MODE;
  4527. break;
  4528. case DSI_OP_CMD_MODE:
  4529. info->curr_panel_mode = MSM_DISPLAY_CMD_MODE;
  4530. info->capabilities |= MSM_DISPLAY_CAP_CMD_MODE;
  4531. if (display->panel->panel_mode_switch_enabled)
  4532. info->capabilities |= MSM_DISPLAY_CAP_VID_MODE;
  4533. info->is_te_using_watchdog_timer =
  4534. display->panel->te_using_watchdog_timer |
  4535. display->sw_te_using_wd;
  4536. break;
  4537. default:
  4538. pr_err("unknwown dsi panel mode %d\n",
  4539. display->panel->panel_mode);
  4540. break;
  4541. }
  4542. if (display->panel->esd_config.esd_enabled)
  4543. info->capabilities |= MSM_DISPLAY_ESD_ENABLED;
  4544. info->te_source = display->te_source;
  4545. error:
  4546. mutex_unlock(&display->display_lock);
  4547. return rc;
  4548. }
  4549. static int dsi_display_get_mode_count_no_lock(struct dsi_display *display,
  4550. u32 *count)
  4551. {
  4552. struct dsi_dfps_capabilities dfps_caps;
  4553. int num_dfps_rates, rc = 0;
  4554. if (!display || !display->panel) {
  4555. pr_err("invalid display:%d panel:%d\n", display != NULL,
  4556. display ? display->panel != NULL : 0);
  4557. return -EINVAL;
  4558. }
  4559. *count = display->panel->num_timing_nodes;
  4560. rc = dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  4561. if (rc) {
  4562. pr_err("[%s] failed to get dfps caps from panel\n",
  4563. display->name);
  4564. return rc;
  4565. }
  4566. num_dfps_rates = !dfps_caps.dfps_support ? 1 :
  4567. dfps_caps.max_refresh_rate -
  4568. dfps_caps.min_refresh_rate + 1;
  4569. /* Inflate num_of_modes by fps in dfps */
  4570. *count = display->panel->num_timing_nodes * num_dfps_rates;
  4571. return 0;
  4572. }
  4573. int dsi_display_get_mode_count(struct dsi_display *display,
  4574. u32 *count)
  4575. {
  4576. int rc;
  4577. if (!display || !display->panel) {
  4578. pr_err("invalid display:%d panel:%d\n", display != NULL,
  4579. display ? display->panel != NULL : 0);
  4580. return -EINVAL;
  4581. }
  4582. mutex_lock(&display->display_lock);
  4583. rc = dsi_display_get_mode_count_no_lock(display, count);
  4584. mutex_unlock(&display->display_lock);
  4585. return 0;
  4586. }
  4587. void dsi_display_put_mode(struct dsi_display *display,
  4588. struct dsi_display_mode *mode)
  4589. {
  4590. dsi_panel_put_mode(mode);
  4591. }
  4592. int dsi_display_get_modes(struct dsi_display *display,
  4593. struct dsi_display_mode **out_modes)
  4594. {
  4595. struct dsi_dfps_capabilities dfps_caps;
  4596. u32 num_dfps_rates, panel_mode_count, total_mode_count;
  4597. u32 mode_idx, array_idx = 0;
  4598. int i, rc = -EINVAL;
  4599. if (!display || !out_modes) {
  4600. pr_err("Invalid params\n");
  4601. return -EINVAL;
  4602. }
  4603. *out_modes = NULL;
  4604. mutex_lock(&display->display_lock);
  4605. if (display->modes)
  4606. goto exit;
  4607. rc = dsi_display_get_mode_count_no_lock(display, &total_mode_count);
  4608. if (rc)
  4609. goto error;
  4610. display->modes = kcalloc(total_mode_count, sizeof(*display->modes),
  4611. GFP_KERNEL);
  4612. if (!display->modes) {
  4613. rc = -ENOMEM;
  4614. goto error;
  4615. }
  4616. rc = dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  4617. if (rc) {
  4618. pr_err("[%s] failed to get dfps caps from panel\n",
  4619. display->name);
  4620. goto error;
  4621. }
  4622. num_dfps_rates = !dfps_caps.dfps_support ? 1 :
  4623. dfps_caps.max_refresh_rate -
  4624. dfps_caps.min_refresh_rate + 1;
  4625. panel_mode_count = display->panel->num_timing_nodes;
  4626. for (mode_idx = 0; mode_idx < panel_mode_count; mode_idx++) {
  4627. struct dsi_display_mode panel_mode;
  4628. int topology_override = NO_OVERRIDE;
  4629. if (display->cmdline_timing == mode_idx)
  4630. topology_override = display->cmdline_topology;
  4631. memset(&panel_mode, 0, sizeof(panel_mode));
  4632. rc = dsi_panel_get_mode(display->panel, mode_idx,
  4633. &panel_mode,
  4634. topology_override);
  4635. if (rc) {
  4636. pr_err("[%s] failed to get mode idx %d from panel\n",
  4637. display->name, mode_idx);
  4638. goto error;
  4639. }
  4640. /* Calculate dsi frame transfer time */
  4641. if (display->panel->panel_mode == DSI_OP_CMD_MODE) {
  4642. dsi_panel_calc_dsi_transfer_time(
  4643. &display->panel->host_config,
  4644. &panel_mode.timing);
  4645. panel_mode.priv_info->dsi_transfer_time_us =
  4646. panel_mode.timing.dsi_transfer_time_us;
  4647. panel_mode.priv_info->min_dsi_clk_hz =
  4648. panel_mode.timing.min_dsi_clk_hz;
  4649. panel_mode.priv_info->mdp_transfer_time_us =
  4650. panel_mode.priv_info->dsi_transfer_time_us;
  4651. panel_mode.timing.mdp_transfer_time_us =
  4652. panel_mode.timing.dsi_transfer_time_us;
  4653. }
  4654. if (display->ctrl_count > 1) { /* TODO: remove if */
  4655. panel_mode.timing.h_active *= display->ctrl_count;
  4656. panel_mode.timing.h_front_porch *= display->ctrl_count;
  4657. panel_mode.timing.h_sync_width *= display->ctrl_count;
  4658. panel_mode.timing.h_back_porch *= display->ctrl_count;
  4659. panel_mode.timing.h_skew *= display->ctrl_count;
  4660. panel_mode.pixel_clk_khz *= display->ctrl_count;
  4661. }
  4662. for (i = 0; i < num_dfps_rates; i++) {
  4663. struct dsi_display_mode *sub_mode =
  4664. &display->modes[array_idx];
  4665. u32 curr_refresh_rate;
  4666. if (!sub_mode) {
  4667. pr_err("invalid mode data\n");
  4668. rc = -EFAULT;
  4669. goto error;
  4670. }
  4671. memcpy(sub_mode, &panel_mode, sizeof(panel_mode));
  4672. if (dfps_caps.dfps_support) {
  4673. curr_refresh_rate =
  4674. sub_mode->timing.refresh_rate;
  4675. sub_mode->timing.refresh_rate =
  4676. dfps_caps.min_refresh_rate +
  4677. (i % num_dfps_rates);
  4678. dsi_display_get_dfps_timing(display,
  4679. sub_mode, curr_refresh_rate);
  4680. sub_mode->pixel_clk_khz =
  4681. (DSI_H_TOTAL_DSC(&sub_mode->timing) *
  4682. DSI_V_TOTAL(&sub_mode->timing) *
  4683. sub_mode->timing.refresh_rate) / 1000;
  4684. }
  4685. array_idx++;
  4686. }
  4687. }
  4688. exit:
  4689. *out_modes = display->modes;
  4690. rc = 0;
  4691. error:
  4692. if (rc)
  4693. kfree(display->modes);
  4694. mutex_unlock(&display->display_lock);
  4695. return rc;
  4696. }
  4697. int dsi_display_get_panel_vfp(void *dsi_display,
  4698. int h_active, int v_active)
  4699. {
  4700. int i, rc = 0;
  4701. u32 count, refresh_rate = 0;
  4702. struct dsi_dfps_capabilities dfps_caps;
  4703. struct dsi_display *display = (struct dsi_display *)dsi_display;
  4704. if (!display)
  4705. return -EINVAL;
  4706. rc = dsi_display_get_mode_count(display, &count);
  4707. if (rc)
  4708. return rc;
  4709. mutex_lock(&display->display_lock);
  4710. if (display->panel && display->panel->cur_mode)
  4711. refresh_rate = display->panel->cur_mode->timing.refresh_rate;
  4712. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  4713. if (dfps_caps.dfps_support)
  4714. refresh_rate = dfps_caps.max_refresh_rate;
  4715. if (!refresh_rate) {
  4716. mutex_unlock(&display->display_lock);
  4717. pr_err("Null Refresh Rate\n");
  4718. return -EINVAL;
  4719. }
  4720. h_active *= display->ctrl_count;
  4721. for (i = 0; i < count; i++) {
  4722. struct dsi_display_mode *m = &display->modes[i];
  4723. if (m && v_active == m->timing.v_active &&
  4724. h_active == m->timing.h_active &&
  4725. refresh_rate == m->timing.refresh_rate) {
  4726. rc = m->timing.v_front_porch;
  4727. break;
  4728. }
  4729. }
  4730. mutex_unlock(&display->display_lock);
  4731. return rc;
  4732. }
  4733. int dsi_display_get_default_lms(void *dsi_display, u32 *num_lm)
  4734. {
  4735. struct dsi_display *display = (struct dsi_display *)dsi_display;
  4736. u32 count, i;
  4737. int rc = 0;
  4738. *num_lm = 0;
  4739. rc = dsi_display_get_mode_count(display, &count);
  4740. if (rc)
  4741. return rc;
  4742. if (!display->modes) {
  4743. struct dsi_display_mode *m;
  4744. rc = dsi_display_get_modes(display, &m);
  4745. if (rc)
  4746. return rc;
  4747. }
  4748. mutex_lock(&display->display_lock);
  4749. for (i = 0; i < count; i++) {
  4750. struct dsi_display_mode *m = &display->modes[i];
  4751. *num_lm = max(m->priv_info->topology.num_lm, *num_lm);
  4752. }
  4753. mutex_unlock(&display->display_lock);
  4754. return rc;
  4755. }
  4756. int dsi_display_find_mode(struct dsi_display *display,
  4757. const struct dsi_display_mode *cmp,
  4758. struct dsi_display_mode **out_mode)
  4759. {
  4760. u32 count, i;
  4761. int rc;
  4762. if (!display || !out_mode)
  4763. return -EINVAL;
  4764. *out_mode = NULL;
  4765. rc = dsi_display_get_mode_count(display, &count);
  4766. if (rc)
  4767. return rc;
  4768. if (!display->modes) {
  4769. struct dsi_display_mode *m;
  4770. rc = dsi_display_get_modes(display, &m);
  4771. if (rc)
  4772. return rc;
  4773. }
  4774. mutex_lock(&display->display_lock);
  4775. for (i = 0; i < count; i++) {
  4776. struct dsi_display_mode *m = &display->modes[i];
  4777. if (cmp->timing.v_active == m->timing.v_active &&
  4778. cmp->timing.h_active == m->timing.h_active &&
  4779. cmp->timing.refresh_rate == m->timing.refresh_rate &&
  4780. cmp->panel_mode == m->panel_mode) {
  4781. *out_mode = m;
  4782. rc = 0;
  4783. break;
  4784. }
  4785. }
  4786. mutex_unlock(&display->display_lock);
  4787. if (!*out_mode) {
  4788. pr_err("[%s] failed to find mode for v_active %u h_active %u rate %u\n",
  4789. display->name, cmp->timing.v_active,
  4790. cmp->timing.h_active, cmp->timing.refresh_rate);
  4791. rc = -ENOENT;
  4792. }
  4793. return rc;
  4794. }
  4795. /**
  4796. * dsi_display_validate_mode_vrr() - Validate if varaible refresh case.
  4797. * @display: DSI display handle.
  4798. * @cur_dsi_mode: Current DSI mode.
  4799. * @mode: Mode value structure to be validated.
  4800. * MSM_MODE_FLAG_SEAMLESS_VRR flag is set if there
  4801. * is change in fps but vactive and hactive are same.
  4802. * Return: error code.
  4803. */
  4804. int dsi_display_validate_mode_vrr(struct dsi_display *display,
  4805. struct dsi_display_mode *cur_dsi_mode,
  4806. struct dsi_display_mode *mode)
  4807. {
  4808. int rc = 0;
  4809. struct dsi_display_mode adj_mode, cur_mode;
  4810. struct dsi_dfps_capabilities dfps_caps;
  4811. u32 curr_refresh_rate;
  4812. if (!display || !mode) {
  4813. pr_err("Invalid params\n");
  4814. return -EINVAL;
  4815. }
  4816. if (!display->panel || !display->panel->cur_mode) {
  4817. pr_debug("Current panel mode not set\n");
  4818. return rc;
  4819. }
  4820. mutex_lock(&display->display_lock);
  4821. adj_mode = *mode;
  4822. cur_mode = *cur_dsi_mode;
  4823. if ((cur_mode.timing.refresh_rate != adj_mode.timing.refresh_rate) &&
  4824. (cur_mode.timing.v_active == adj_mode.timing.v_active) &&
  4825. (cur_mode.timing.h_active == adj_mode.timing.h_active)) {
  4826. curr_refresh_rate = cur_mode.timing.refresh_rate;
  4827. rc = dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  4828. if (rc) {
  4829. pr_err("[%s] failed to get dfps caps from panel\n",
  4830. display->name);
  4831. goto error;
  4832. }
  4833. cur_mode.timing.refresh_rate =
  4834. adj_mode.timing.refresh_rate;
  4835. rc = dsi_display_get_dfps_timing(display,
  4836. &cur_mode, curr_refresh_rate);
  4837. if (rc) {
  4838. pr_err("[%s] seamless vrr not possible rc=%d\n",
  4839. display->name, rc);
  4840. goto error;
  4841. }
  4842. switch (dfps_caps.type) {
  4843. /*
  4844. * Ignore any round off factors in porch calculation.
  4845. * Worse case is set to 5.
  4846. */
  4847. case DSI_DFPS_IMMEDIATE_VFP:
  4848. if (abs(DSI_V_TOTAL(&cur_mode.timing) -
  4849. DSI_V_TOTAL(&adj_mode.timing)) > 5)
  4850. pr_err("Mismatch vfp fps:%d new:%d given:%d\n",
  4851. adj_mode.timing.refresh_rate,
  4852. cur_mode.timing.v_front_porch,
  4853. adj_mode.timing.v_front_porch);
  4854. break;
  4855. case DSI_DFPS_IMMEDIATE_HFP:
  4856. if (abs(DSI_H_TOTAL_DSC(&cur_mode.timing) -
  4857. DSI_H_TOTAL_DSC(&adj_mode.timing)) > 5)
  4858. pr_err("Mismatch hfp fps:%d new:%d given:%d\n",
  4859. adj_mode.timing.refresh_rate,
  4860. cur_mode.timing.h_front_porch,
  4861. adj_mode.timing.h_front_porch);
  4862. break;
  4863. default:
  4864. pr_err("Unsupported DFPS mode %d\n",
  4865. dfps_caps.type);
  4866. rc = -ENOTSUPP;
  4867. }
  4868. pr_debug("Mode switch is seamless variable refresh\n");
  4869. mode->dsi_mode_flags |= DSI_MODE_FLAG_VRR;
  4870. SDE_EVT32(curr_refresh_rate, adj_mode.timing.refresh_rate,
  4871. cur_mode.timing.h_front_porch,
  4872. adj_mode.timing.h_front_porch);
  4873. }
  4874. error:
  4875. mutex_unlock(&display->display_lock);
  4876. return rc;
  4877. }
  4878. int dsi_display_validate_mode(struct dsi_display *display,
  4879. struct dsi_display_mode *mode,
  4880. u32 flags)
  4881. {
  4882. int rc = 0;
  4883. int i;
  4884. struct dsi_display_ctrl *ctrl;
  4885. struct dsi_display_mode adj_mode;
  4886. if (!display || !mode) {
  4887. pr_err("Invalid params\n");
  4888. return -EINVAL;
  4889. }
  4890. mutex_lock(&display->display_lock);
  4891. adj_mode = *mode;
  4892. adjust_timing_by_ctrl_count(display, &adj_mode);
  4893. rc = dsi_panel_validate_mode(display->panel, &adj_mode);
  4894. if (rc) {
  4895. pr_err("[%s] panel mode validation failed, rc=%d\n",
  4896. display->name, rc);
  4897. goto error;
  4898. }
  4899. display_for_each_ctrl(i, display) {
  4900. ctrl = &display->ctrl[i];
  4901. rc = dsi_ctrl_validate_timing(ctrl->ctrl, &adj_mode.timing);
  4902. if (rc) {
  4903. pr_err("[%s] ctrl mode validation failed, rc=%d\n",
  4904. display->name, rc);
  4905. goto error;
  4906. }
  4907. rc = dsi_phy_validate_mode(ctrl->phy, &adj_mode.timing);
  4908. if (rc) {
  4909. pr_err("[%s] phy mode validation failed, rc=%d\n",
  4910. display->name, rc);
  4911. goto error;
  4912. }
  4913. }
  4914. if ((flags & DSI_VALIDATE_FLAG_ALLOW_ADJUST) &&
  4915. (mode->dsi_mode_flags & DSI_MODE_FLAG_SEAMLESS)) {
  4916. rc = dsi_display_validate_mode_seamless(display, mode);
  4917. if (rc) {
  4918. pr_err("[%s] seamless not possible rc=%d\n",
  4919. display->name, rc);
  4920. goto error;
  4921. }
  4922. }
  4923. error:
  4924. mutex_unlock(&display->display_lock);
  4925. return rc;
  4926. }
  4927. int dsi_display_set_mode(struct dsi_display *display,
  4928. struct dsi_display_mode *mode,
  4929. u32 flags)
  4930. {
  4931. int rc = 0;
  4932. struct dsi_display_mode adj_mode;
  4933. struct dsi_mode_info timing;
  4934. if (!display || !mode || !display->panel) {
  4935. pr_err("Invalid params\n");
  4936. return -EINVAL;
  4937. }
  4938. mutex_lock(&display->display_lock);
  4939. adj_mode = *mode;
  4940. timing = adj_mode.timing;
  4941. adjust_timing_by_ctrl_count(display, &adj_mode);
  4942. /*For dynamic DSI setting, use specified clock rate */
  4943. if (display->cached_clk_rate > 0)
  4944. adj_mode.priv_info->clk_rate_hz = display->cached_clk_rate;
  4945. rc = dsi_display_validate_mode_set(display, &adj_mode, flags);
  4946. if (rc) {
  4947. pr_err("[%s] mode cannot be set\n", display->name);
  4948. goto error;
  4949. }
  4950. rc = dsi_display_set_mode_sub(display, &adj_mode, flags);
  4951. if (rc) {
  4952. pr_err("[%s] failed to set mode\n", display->name);
  4953. goto error;
  4954. }
  4955. if (!display->panel->cur_mode) {
  4956. display->panel->cur_mode =
  4957. kzalloc(sizeof(struct dsi_display_mode), GFP_KERNEL);
  4958. if (!display->panel->cur_mode) {
  4959. rc = -ENOMEM;
  4960. goto error;
  4961. }
  4962. }
  4963. pr_info("mdp_transfer_time_us=%d us\n",
  4964. adj_mode.priv_info->mdp_transfer_time_us);
  4965. pr_info("hactive= %d,vactive= %d,fps=%d",timing.h_active,
  4966. timing.v_active,timing.refresh_rate);
  4967. memcpy(display->panel->cur_mode, &adj_mode, sizeof(adj_mode));
  4968. error:
  4969. mutex_unlock(&display->display_lock);
  4970. return rc;
  4971. }
  4972. int dsi_display_set_tpg_state(struct dsi_display *display, bool enable)
  4973. {
  4974. int rc = 0;
  4975. int i;
  4976. struct dsi_display_ctrl *ctrl;
  4977. if (!display) {
  4978. pr_err("Invalid params\n");
  4979. return -EINVAL;
  4980. }
  4981. display_for_each_ctrl(i, display) {
  4982. ctrl = &display->ctrl[i];
  4983. rc = dsi_ctrl_set_tpg_state(ctrl->ctrl, enable);
  4984. if (rc) {
  4985. pr_err("[%s] failed to set tpg state for host_%d\n",
  4986. display->name, i);
  4987. goto error;
  4988. }
  4989. }
  4990. display->is_tpg_enabled = enable;
  4991. error:
  4992. return rc;
  4993. }
  4994. static int dsi_display_pre_switch(struct dsi_display *display)
  4995. {
  4996. int rc = 0;
  4997. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  4998. DSI_CORE_CLK, DSI_CLK_ON);
  4999. if (rc) {
  5000. pr_err("[%s] failed to enable DSI core clocks, rc=%d\n",
  5001. display->name, rc);
  5002. goto error;
  5003. }
  5004. rc = dsi_display_ctrl_update(display);
  5005. if (rc) {
  5006. pr_err("[%s] failed to update DSI controller, rc=%d\n",
  5007. display->name, rc);
  5008. goto error_ctrl_clk_off;
  5009. }
  5010. rc = dsi_display_set_clk_src(display);
  5011. if (rc) {
  5012. pr_err("[%s] failed to set DSI link clock source, rc=%d\n",
  5013. display->name, rc);
  5014. goto error_ctrl_deinit;
  5015. }
  5016. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  5017. DSI_LINK_CLK, DSI_CLK_ON);
  5018. if (rc) {
  5019. pr_err("[%s] failed to enable DSI link clocks, rc=%d\n",
  5020. display->name, rc);
  5021. goto error_ctrl_deinit;
  5022. }
  5023. goto error;
  5024. error_ctrl_deinit:
  5025. (void)dsi_display_ctrl_deinit(display);
  5026. error_ctrl_clk_off:
  5027. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  5028. DSI_CORE_CLK, DSI_CLK_OFF);
  5029. error:
  5030. return rc;
  5031. }
  5032. static bool _dsi_display_validate_host_state(struct dsi_display *display)
  5033. {
  5034. int i;
  5035. struct dsi_display_ctrl *ctrl;
  5036. display_for_each_ctrl(i, display) {
  5037. ctrl = &display->ctrl[i];
  5038. if (!ctrl->ctrl)
  5039. continue;
  5040. if (!dsi_ctrl_validate_host_state(ctrl->ctrl))
  5041. return false;
  5042. }
  5043. return true;
  5044. }
  5045. static void dsi_display_handle_fifo_underflow(struct work_struct *work)
  5046. {
  5047. struct dsi_display *display = NULL;
  5048. display = container_of(work, struct dsi_display, fifo_underflow_work);
  5049. if (!display || !display->panel ||
  5050. atomic_read(&display->panel->esd_recovery_pending)) {
  5051. pr_debug("Invalid recovery use case\n");
  5052. return;
  5053. }
  5054. mutex_lock(&display->display_lock);
  5055. if (!_dsi_display_validate_host_state(display)) {
  5056. mutex_unlock(&display->display_lock);
  5057. return;
  5058. }
  5059. pr_debug("handle DSI FIFO underflow error\n");
  5060. dsi_display_clk_ctrl(display->dsi_clk_handle,
  5061. DSI_ALL_CLKS, DSI_CLK_ON);
  5062. dsi_display_soft_reset(display);
  5063. dsi_display_clk_ctrl(display->dsi_clk_handle,
  5064. DSI_ALL_CLKS, DSI_CLK_OFF);
  5065. mutex_unlock(&display->display_lock);
  5066. }
  5067. static void dsi_display_handle_fifo_overflow(struct work_struct *work)
  5068. {
  5069. struct dsi_display *display = NULL;
  5070. struct dsi_display_ctrl *ctrl;
  5071. int i, rc;
  5072. int mask = BIT(20); /* clock lane */
  5073. int (*cb_func)(void *event_usr_ptr,
  5074. uint32_t event_idx, uint32_t instance_idx,
  5075. uint32_t data0, uint32_t data1,
  5076. uint32_t data2, uint32_t data3);
  5077. void *data;
  5078. u32 version = 0;
  5079. display = container_of(work, struct dsi_display, fifo_overflow_work);
  5080. if (!display || !display->panel ||
  5081. (display->panel->panel_mode != DSI_OP_VIDEO_MODE) ||
  5082. atomic_read(&display->panel->esd_recovery_pending)) {
  5083. pr_debug("Invalid recovery use case\n");
  5084. return;
  5085. }
  5086. mutex_lock(&display->display_lock);
  5087. if (!_dsi_display_validate_host_state(display)) {
  5088. mutex_unlock(&display->display_lock);
  5089. return;
  5090. }
  5091. pr_debug("handle DSI FIFO overflow error\n");
  5092. dsi_display_clk_ctrl(display->dsi_clk_handle,
  5093. DSI_ALL_CLKS, DSI_CLK_ON);
  5094. /*
  5095. * below recovery sequence is not applicable to
  5096. * hw version 2.0.0, 2.1.0 and 2.2.0, so return early.
  5097. */
  5098. ctrl = &display->ctrl[display->clk_master_idx];
  5099. version = dsi_ctrl_get_hw_version(ctrl->ctrl);
  5100. if (!version || (version < 0x20020001))
  5101. goto end;
  5102. /* reset ctrl and lanes */
  5103. display_for_each_ctrl(i, display) {
  5104. ctrl = &display->ctrl[i];
  5105. rc = dsi_ctrl_reset(ctrl->ctrl, mask);
  5106. rc = dsi_phy_lane_reset(ctrl->phy);
  5107. }
  5108. /* wait for display line count to be in active area */
  5109. ctrl = &display->ctrl[display->clk_master_idx];
  5110. if (ctrl->ctrl->recovery_cb.event_cb) {
  5111. cb_func = ctrl->ctrl->recovery_cb.event_cb;
  5112. data = ctrl->ctrl->recovery_cb.event_usr_ptr;
  5113. rc = cb_func(data, SDE_CONN_EVENT_VID_FIFO_OVERFLOW,
  5114. display->clk_master_idx, 0, 0, 0, 0);
  5115. if (rc < 0) {
  5116. pr_debug("sde callback failed\n");
  5117. goto end;
  5118. }
  5119. }
  5120. /* Enable Video mode for DSI controller */
  5121. display_for_each_ctrl(i, display) {
  5122. ctrl = &display->ctrl[i];
  5123. dsi_ctrl_vid_engine_en(ctrl->ctrl, true);
  5124. }
  5125. /*
  5126. * Add sufficient delay to make sure
  5127. * pixel transmission has started
  5128. */
  5129. udelay(200);
  5130. end:
  5131. dsi_display_clk_ctrl(display->dsi_clk_handle,
  5132. DSI_ALL_CLKS, DSI_CLK_OFF);
  5133. mutex_unlock(&display->display_lock);
  5134. }
  5135. static void dsi_display_handle_lp_rx_timeout(struct work_struct *work)
  5136. {
  5137. struct dsi_display *display = NULL;
  5138. struct dsi_display_ctrl *ctrl;
  5139. int i, rc;
  5140. int mask = (BIT(20) | (0xF << 16)); /* clock lane and 4 data lane */
  5141. int (*cb_func)(void *event_usr_ptr,
  5142. uint32_t event_idx, uint32_t instance_idx,
  5143. uint32_t data0, uint32_t data1,
  5144. uint32_t data2, uint32_t data3);
  5145. void *data;
  5146. u32 version = 0;
  5147. display = container_of(work, struct dsi_display, lp_rx_timeout_work);
  5148. if (!display || !display->panel ||
  5149. (display->panel->panel_mode != DSI_OP_VIDEO_MODE) ||
  5150. atomic_read(&display->panel->esd_recovery_pending)) {
  5151. pr_debug("Invalid recovery use case\n");
  5152. return;
  5153. }
  5154. mutex_lock(&display->display_lock);
  5155. if (!_dsi_display_validate_host_state(display)) {
  5156. mutex_unlock(&display->display_lock);
  5157. return;
  5158. }
  5159. pr_debug("handle DSI LP RX Timeout error\n");
  5160. dsi_display_clk_ctrl(display->dsi_clk_handle,
  5161. DSI_ALL_CLKS, DSI_CLK_ON);
  5162. /*
  5163. * below recovery sequence is not applicable to
  5164. * hw version 2.0.0, 2.1.0 and 2.2.0, so return early.
  5165. */
  5166. ctrl = &display->ctrl[display->clk_master_idx];
  5167. version = dsi_ctrl_get_hw_version(ctrl->ctrl);
  5168. if (!version || (version < 0x20020001))
  5169. goto end;
  5170. /* reset ctrl and lanes */
  5171. display_for_each_ctrl(i, display) {
  5172. ctrl = &display->ctrl[i];
  5173. rc = dsi_ctrl_reset(ctrl->ctrl, mask);
  5174. rc = dsi_phy_lane_reset(ctrl->phy);
  5175. }
  5176. ctrl = &display->ctrl[display->clk_master_idx];
  5177. if (ctrl->ctrl->recovery_cb.event_cb) {
  5178. cb_func = ctrl->ctrl->recovery_cb.event_cb;
  5179. data = ctrl->ctrl->recovery_cb.event_usr_ptr;
  5180. rc = cb_func(data, SDE_CONN_EVENT_VID_FIFO_OVERFLOW,
  5181. display->clk_master_idx, 0, 0, 0, 0);
  5182. if (rc < 0) {
  5183. pr_debug("Target is in suspend/shutdown\n");
  5184. goto end;
  5185. }
  5186. }
  5187. /* Enable Video mode for DSI controller */
  5188. display_for_each_ctrl(i, display) {
  5189. ctrl = &display->ctrl[i];
  5190. dsi_ctrl_vid_engine_en(ctrl->ctrl, true);
  5191. }
  5192. /*
  5193. * Add sufficient delay to make sure
  5194. * pixel transmission as started
  5195. */
  5196. udelay(200);
  5197. end:
  5198. dsi_display_clk_ctrl(display->dsi_clk_handle,
  5199. DSI_ALL_CLKS, DSI_CLK_OFF);
  5200. mutex_unlock(&display->display_lock);
  5201. }
  5202. static int dsi_display_cb_error_handler(void *data,
  5203. uint32_t event_idx, uint32_t instance_idx,
  5204. uint32_t data0, uint32_t data1,
  5205. uint32_t data2, uint32_t data3)
  5206. {
  5207. struct dsi_display *display = data;
  5208. if (!display || !(display->err_workq))
  5209. return -EINVAL;
  5210. switch (event_idx) {
  5211. case DSI_FIFO_UNDERFLOW:
  5212. queue_work(display->err_workq, &display->fifo_underflow_work);
  5213. break;
  5214. case DSI_FIFO_OVERFLOW:
  5215. queue_work(display->err_workq, &display->fifo_overflow_work);
  5216. break;
  5217. case DSI_LP_Rx_TIMEOUT:
  5218. queue_work(display->err_workq, &display->lp_rx_timeout_work);
  5219. break;
  5220. default:
  5221. pr_warn("unhandled error interrupt: %d\n", event_idx);
  5222. break;
  5223. }
  5224. return 0;
  5225. }
  5226. static void dsi_display_register_error_handler(struct dsi_display *display)
  5227. {
  5228. int i = 0;
  5229. struct dsi_display_ctrl *ctrl;
  5230. struct dsi_event_cb_info event_info;
  5231. if (!display)
  5232. return;
  5233. display->err_workq = create_singlethread_workqueue("dsi_err_workq");
  5234. if (!display->err_workq) {
  5235. pr_err("failed to create dsi workq!\n");
  5236. return;
  5237. }
  5238. INIT_WORK(&display->fifo_underflow_work,
  5239. dsi_display_handle_fifo_underflow);
  5240. INIT_WORK(&display->fifo_overflow_work,
  5241. dsi_display_handle_fifo_overflow);
  5242. INIT_WORK(&display->lp_rx_timeout_work,
  5243. dsi_display_handle_lp_rx_timeout);
  5244. memset(&event_info, 0, sizeof(event_info));
  5245. event_info.event_cb = dsi_display_cb_error_handler;
  5246. event_info.event_usr_ptr = display;
  5247. display_for_each_ctrl(i, display) {
  5248. ctrl = &display->ctrl[i];
  5249. ctrl->ctrl->irq_info.irq_err_cb = event_info;
  5250. }
  5251. }
  5252. static void dsi_display_unregister_error_handler(struct dsi_display *display)
  5253. {
  5254. int i = 0;
  5255. struct dsi_display_ctrl *ctrl;
  5256. if (!display)
  5257. return;
  5258. display_for_each_ctrl(i, display) {
  5259. ctrl = &display->ctrl[i];
  5260. memset(&ctrl->ctrl->irq_info.irq_err_cb,
  5261. 0, sizeof(struct dsi_event_cb_info));
  5262. }
  5263. if (display->err_workq) {
  5264. destroy_workqueue(display->err_workq);
  5265. display->err_workq = NULL;
  5266. }
  5267. }
  5268. int dsi_display_prepare(struct dsi_display *display)
  5269. {
  5270. int rc = 0;
  5271. struct dsi_display_mode *mode;
  5272. if (!display) {
  5273. pr_err("Invalid params\n");
  5274. return -EINVAL;
  5275. }
  5276. if (!display->panel->cur_mode) {
  5277. pr_err("no valid mode set for the display\n");
  5278. return -EINVAL;
  5279. }
  5280. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  5281. mutex_lock(&display->display_lock);
  5282. mode = display->panel->cur_mode;
  5283. dsi_display_set_ctrl_esd_check_flag(display, false);
  5284. /* Set up ctrl isr before enabling core clk */
  5285. dsi_display_ctrl_isr_configure(display, true);
  5286. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  5287. if (display->is_cont_splash_enabled) {
  5288. pr_err("DMS is not supposed to be set on first frame\n");
  5289. return -EINVAL;
  5290. }
  5291. /* update dsi ctrl for new mode */
  5292. rc = dsi_display_pre_switch(display);
  5293. if (rc)
  5294. pr_err("[%s] panel pre-prepare-res-switch failed, rc=%d\n",
  5295. display->name, rc);
  5296. goto error;
  5297. }
  5298. if (!(mode->dsi_mode_flags & DSI_MODE_FLAG_POMS) &&
  5299. (!display->is_cont_splash_enabled)) {
  5300. /*
  5301. * For continuous splash usecase we skip panel
  5302. * pre prepare since the regulator vote is already
  5303. * taken care in splash resource init
  5304. */
  5305. rc = dsi_panel_pre_prepare(display->panel);
  5306. if (rc) {
  5307. pr_err("[%s] panel pre-prepare failed, rc=%d\n",
  5308. display->name, rc);
  5309. goto error;
  5310. }
  5311. }
  5312. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  5313. DSI_CORE_CLK, DSI_CLK_ON);
  5314. if (rc) {
  5315. pr_err("[%s] failed to enable DSI core clocks, rc=%d\n",
  5316. display->name, rc);
  5317. goto error_panel_post_unprep;
  5318. }
  5319. /*
  5320. * If ULPS during suspend feature is enabled, then DSI PHY was
  5321. * left on during suspend. In this case, we do not need to reset/init
  5322. * PHY. This would have already been done when the CORE clocks are
  5323. * turned on. However, if cont splash is disabled, the first time DSI
  5324. * is powered on, phy init needs to be done unconditionally.
  5325. */
  5326. if (!display->panel->ulps_suspend_enabled || !display->ulps_enabled) {
  5327. rc = dsi_display_phy_sw_reset(display);
  5328. if (rc) {
  5329. pr_err("[%s] failed to reset phy, rc=%d\n",
  5330. display->name, rc);
  5331. goto error_ctrl_clk_off;
  5332. }
  5333. rc = dsi_display_phy_enable(display);
  5334. if (rc) {
  5335. pr_err("[%s] failed to enable DSI PHY, rc=%d\n",
  5336. display->name, rc);
  5337. goto error_ctrl_clk_off;
  5338. }
  5339. }
  5340. rc = dsi_display_set_clk_src(display);
  5341. if (rc) {
  5342. pr_err("[%s] failed to set DSI link clock source, rc=%d\n",
  5343. display->name, rc);
  5344. goto error_phy_disable;
  5345. }
  5346. rc = dsi_display_ctrl_init(display);
  5347. if (rc) {
  5348. pr_err("[%s] failed to setup DSI controller, rc=%d\n",
  5349. display->name, rc);
  5350. goto error_phy_disable;
  5351. }
  5352. /* Set up DSI ERROR event callback */
  5353. dsi_display_register_error_handler(display);
  5354. rc = dsi_display_ctrl_host_enable(display);
  5355. if (rc) {
  5356. pr_err("[%s] failed to enable DSI host, rc=%d\n",
  5357. display->name, rc);
  5358. goto error_ctrl_deinit;
  5359. }
  5360. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  5361. DSI_LINK_CLK, DSI_CLK_ON);
  5362. if (rc) {
  5363. pr_err("[%s] failed to enable DSI link clocks, rc=%d\n",
  5364. display->name, rc);
  5365. goto error_host_engine_off;
  5366. }
  5367. if (!display->is_cont_splash_enabled) {
  5368. /*
  5369. * For continuous splash usecase, skip panel prepare and
  5370. * ctl reset since the pnael and ctrl is already in active
  5371. * state and panel on commands are not needed
  5372. */
  5373. rc = dsi_display_soft_reset(display);
  5374. if (rc) {
  5375. pr_err("[%s] failed soft reset, rc=%d\n",
  5376. display->name, rc);
  5377. goto error_ctrl_link_off;
  5378. }
  5379. if (!(mode->dsi_mode_flags & DSI_MODE_FLAG_POMS)) {
  5380. rc = dsi_panel_prepare(display->panel);
  5381. if (rc) {
  5382. pr_err("[%s] panel prepare failed, rc=%d\n",
  5383. display->name, rc);
  5384. goto error_ctrl_link_off;
  5385. }
  5386. }
  5387. }
  5388. goto error;
  5389. error_ctrl_link_off:
  5390. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  5391. DSI_LINK_CLK, DSI_CLK_OFF);
  5392. error_host_engine_off:
  5393. (void)dsi_display_ctrl_host_disable(display);
  5394. error_ctrl_deinit:
  5395. (void)dsi_display_ctrl_deinit(display);
  5396. error_phy_disable:
  5397. (void)dsi_display_phy_disable(display);
  5398. error_ctrl_clk_off:
  5399. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  5400. DSI_CORE_CLK, DSI_CLK_OFF);
  5401. error_panel_post_unprep:
  5402. (void)dsi_panel_post_unprepare(display->panel);
  5403. error:
  5404. mutex_unlock(&display->display_lock);
  5405. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  5406. return rc;
  5407. }
  5408. static int dsi_display_calc_ctrl_roi(const struct dsi_display *display,
  5409. const struct dsi_display_ctrl *ctrl,
  5410. const struct msm_roi_list *req_rois,
  5411. struct dsi_rect *out_roi)
  5412. {
  5413. const struct dsi_rect *bounds = &ctrl->ctrl->mode_bounds;
  5414. struct dsi_display_mode *cur_mode;
  5415. struct msm_roi_caps *roi_caps;
  5416. struct dsi_rect req_roi = { 0 };
  5417. int rc = 0;
  5418. cur_mode = display->panel->cur_mode;
  5419. if (!cur_mode)
  5420. return 0;
  5421. roi_caps = &cur_mode->priv_info->roi_caps;
  5422. if (req_rois->num_rects > roi_caps->num_roi) {
  5423. pr_err("request for %d rois greater than max %d\n",
  5424. req_rois->num_rects,
  5425. roi_caps->num_roi);
  5426. rc = -EINVAL;
  5427. goto exit;
  5428. }
  5429. /**
  5430. * if no rois, user wants to reset back to full resolution
  5431. * note: h_active is already divided by ctrl_count
  5432. */
  5433. if (!req_rois->num_rects) {
  5434. *out_roi = *bounds;
  5435. goto exit;
  5436. }
  5437. /* intersect with the bounds */
  5438. req_roi.x = req_rois->roi[0].x1;
  5439. req_roi.y = req_rois->roi[0].y1;
  5440. req_roi.w = req_rois->roi[0].x2 - req_rois->roi[0].x1;
  5441. req_roi.h = req_rois->roi[0].y2 - req_rois->roi[0].y1;
  5442. dsi_rect_intersect(&req_roi, bounds, out_roi);
  5443. exit:
  5444. /* adjust the ctrl origin to be top left within the ctrl */
  5445. out_roi->x = out_roi->x - bounds->x;
  5446. pr_debug("ctrl%d:%d: req (%d,%d,%d,%d) bnd (%d,%d,%d,%d) out (%d,%d,%d,%d)\n",
  5447. ctrl->dsi_ctrl_idx, ctrl->ctrl->cell_index,
  5448. req_roi.x, req_roi.y, req_roi.w, req_roi.h,
  5449. bounds->x, bounds->y, bounds->w, bounds->h,
  5450. out_roi->x, out_roi->y, out_roi->w, out_roi->h);
  5451. return rc;
  5452. }
  5453. static int dsi_display_qsync(struct dsi_display *display, bool enable)
  5454. {
  5455. int i;
  5456. int rc = 0;
  5457. if (!display->panel->qsync_min_fps) {
  5458. pr_err("%s:ERROR: qsync set, but no fps\n", __func__);
  5459. return 0;
  5460. }
  5461. mutex_lock(&display->display_lock);
  5462. for (i = 0; i < display->ctrl_count; i++) {
  5463. if (enable) {
  5464. /* send the commands to enable qsync */
  5465. rc = dsi_panel_send_qsync_on_dcs(display->panel, i);
  5466. if (rc) {
  5467. pr_err("fail qsync ON cmds rc:%d\n", rc);
  5468. goto exit;
  5469. }
  5470. } else {
  5471. /* send the commands to enable qsync */
  5472. rc = dsi_panel_send_qsync_off_dcs(display->panel, i);
  5473. if (rc) {
  5474. pr_err("fail qsync OFF cmds rc:%d\n", rc);
  5475. goto exit;
  5476. }
  5477. }
  5478. dsi_ctrl_setup_avr(display->ctrl[i].ctrl, enable);
  5479. }
  5480. exit:
  5481. SDE_EVT32(enable, display->panel->qsync_min_fps, rc);
  5482. mutex_unlock(&display->display_lock);
  5483. return rc;
  5484. }
  5485. static int dsi_display_set_roi(struct dsi_display *display,
  5486. struct msm_roi_list *rois)
  5487. {
  5488. struct dsi_display_mode *cur_mode;
  5489. struct msm_roi_caps *roi_caps;
  5490. int rc = 0;
  5491. int i;
  5492. if (!display || !rois || !display->panel)
  5493. return -EINVAL;
  5494. cur_mode = display->panel->cur_mode;
  5495. if (!cur_mode)
  5496. return 0;
  5497. roi_caps = &cur_mode->priv_info->roi_caps;
  5498. if (!roi_caps->enabled)
  5499. return 0;
  5500. display_for_each_ctrl(i, display) {
  5501. struct dsi_display_ctrl *ctrl = &display->ctrl[i];
  5502. struct dsi_rect ctrl_roi;
  5503. bool changed = false;
  5504. rc = dsi_display_calc_ctrl_roi(display, ctrl, rois, &ctrl_roi);
  5505. if (rc) {
  5506. pr_err("dsi_display_calc_ctrl_roi failed rc %d\n", rc);
  5507. return rc;
  5508. }
  5509. rc = dsi_ctrl_set_roi(ctrl->ctrl, &ctrl_roi, &changed);
  5510. if (rc) {
  5511. pr_err("dsi_ctrl_set_roi failed rc %d\n", rc);
  5512. return rc;
  5513. }
  5514. if (!changed)
  5515. continue;
  5516. /* send the new roi to the panel via dcs commands */
  5517. rc = dsi_panel_send_roi_dcs(display->panel, i, &ctrl_roi);
  5518. if (rc) {
  5519. pr_err("dsi_panel_set_roi failed rc %d\n", rc);
  5520. return rc;
  5521. }
  5522. /* re-program the ctrl with the timing based on the new roi */
  5523. rc = dsi_ctrl_setup(ctrl->ctrl);
  5524. if (rc) {
  5525. pr_err("dsi_ctrl_setup failed rc %d\n", rc);
  5526. return rc;
  5527. }
  5528. }
  5529. return rc;
  5530. }
  5531. int dsi_display_pre_kickoff(struct drm_connector *connector,
  5532. struct dsi_display *display,
  5533. struct msm_display_kickoff_params *params)
  5534. {
  5535. int rc = 0;
  5536. int i;
  5537. bool enable;
  5538. /* check and setup MISR */
  5539. if (display->misr_enable)
  5540. _dsi_display_setup_misr(display);
  5541. if (params->qsync_update) {
  5542. enable = (params->qsync_mode > 0) ? true : false;
  5543. rc = dsi_display_qsync(display, enable);
  5544. if (rc)
  5545. pr_err("%s failed to send qsync commands\n",
  5546. __func__);
  5547. SDE_EVT32(params->qsync_mode, rc);
  5548. }
  5549. rc = dsi_display_set_roi(display, params->rois);
  5550. /* dynamic DSI clock setting */
  5551. if (atomic_read(&display->clkrate_change_pending)) {
  5552. mutex_lock(&display->display_lock);
  5553. /*
  5554. * acquire panel_lock to make sure no commands are in progress
  5555. */
  5556. dsi_panel_acquire_panel_lock(display->panel);
  5557. /*
  5558. * Wait for DSI command engine not to be busy sending data
  5559. * from display engine.
  5560. * If waiting fails, return "rc" instead of below "ret" so as
  5561. * not to impact DRM commit. The clock updating would be
  5562. * deferred to the next DRM commit.
  5563. */
  5564. display_for_each_ctrl(i, display) {
  5565. struct dsi_ctrl *ctrl = display->ctrl[i].ctrl;
  5566. int ret = 0;
  5567. ret = dsi_ctrl_wait_for_cmd_mode_mdp_idle(ctrl);
  5568. if (ret)
  5569. goto wait_failure;
  5570. }
  5571. /*
  5572. * Don't check the return value so as not to impact DRM commit
  5573. * when error occurs.
  5574. */
  5575. (void)dsi_display_force_update_dsi_clk(display);
  5576. wait_failure:
  5577. /* release panel_lock */
  5578. dsi_panel_release_panel_lock(display->panel);
  5579. mutex_unlock(&display->display_lock);
  5580. }
  5581. return rc;
  5582. }
  5583. int dsi_display_config_ctrl_for_cont_splash(struct dsi_display *display)
  5584. {
  5585. int rc = 0;
  5586. if (!display || !display->panel) {
  5587. pr_err("Invalid params\n");
  5588. return -EINVAL;
  5589. }
  5590. if (!display->panel->cur_mode) {
  5591. pr_err("no valid mode set for the display\n");
  5592. return -EINVAL;
  5593. }
  5594. if (!display->is_cont_splash_enabled)
  5595. return 0;
  5596. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  5597. rc = dsi_display_vid_engine_enable(display);
  5598. if (rc) {
  5599. pr_err("[%s]failed to enable DSI video engine, rc=%d\n",
  5600. display->name, rc);
  5601. goto error_out;
  5602. }
  5603. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  5604. rc = dsi_display_cmd_engine_enable(display);
  5605. if (rc) {
  5606. pr_err("[%s]failed to enable DSI cmd engine, rc=%d\n",
  5607. display->name, rc);
  5608. goto error_out;
  5609. }
  5610. } else {
  5611. pr_err("[%s] Invalid configuration\n", display->name);
  5612. rc = -EINVAL;
  5613. }
  5614. error_out:
  5615. return rc;
  5616. }
  5617. int dsi_display_enable(struct dsi_display *display)
  5618. {
  5619. int rc = 0;
  5620. struct dsi_display_mode *mode;
  5621. if (!display || !display->panel) {
  5622. pr_err("Invalid params\n");
  5623. return -EINVAL;
  5624. }
  5625. if (!display->panel->cur_mode) {
  5626. pr_err("no valid mode set for the display\n");
  5627. return -EINVAL;
  5628. }
  5629. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  5630. /* Engine states and panel states are populated during splash
  5631. * resource init and hence we return early
  5632. */
  5633. if (display->is_cont_splash_enabled) {
  5634. dsi_display_config_ctrl_for_cont_splash(display);
  5635. rc = dsi_display_splash_res_cleanup(display);
  5636. if (rc) {
  5637. pr_err("Continuous splash res cleanup failed, rc=%d\n",
  5638. rc);
  5639. return -EINVAL;
  5640. }
  5641. display->panel->panel_initialized = true;
  5642. pr_debug("cont splash enabled, display enable not required\n");
  5643. return 0;
  5644. }
  5645. mutex_lock(&display->display_lock);
  5646. mode = display->panel->cur_mode;
  5647. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  5648. rc = dsi_panel_post_switch(display->panel);
  5649. if (rc) {
  5650. pr_err("[%s] failed to switch DSI panel mode, rc=%d\n",
  5651. display->name, rc);
  5652. goto error;
  5653. }
  5654. } else if (!(display->panel->cur_mode->dsi_mode_flags &
  5655. DSI_MODE_FLAG_POMS)){
  5656. rc = dsi_panel_enable(display->panel);
  5657. if (rc) {
  5658. pr_err("[%s] failed to enable DSI panel, rc=%d\n",
  5659. display->name, rc);
  5660. goto error;
  5661. }
  5662. }
  5663. if (mode->priv_info->dsc_enabled) {
  5664. mode->priv_info->dsc.pic_width *= display->ctrl_count;
  5665. rc = dsi_panel_update_pps(display->panel);
  5666. if (rc) {
  5667. pr_err("[%s] panel pps cmd update failed, rc=%d\n",
  5668. display->name, rc);
  5669. goto error;
  5670. }
  5671. }
  5672. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  5673. rc = dsi_panel_switch(display->panel);
  5674. if (rc)
  5675. pr_err("[%s] failed to switch DSI panel mode, rc=%d\n",
  5676. display->name, rc);
  5677. goto error;
  5678. }
  5679. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  5680. pr_debug("%s:enable video timing eng\n", __func__);
  5681. rc = dsi_display_vid_engine_enable(display);
  5682. if (rc) {
  5683. pr_err("[%s]failed to enable DSI video engine, rc=%d\n",
  5684. display->name, rc);
  5685. goto error_disable_panel;
  5686. }
  5687. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  5688. pr_debug("%s:enable command timing eng\n", __func__);
  5689. rc = dsi_display_cmd_engine_enable(display);
  5690. if (rc) {
  5691. pr_err("[%s]failed to enable DSI cmd engine, rc=%d\n",
  5692. display->name, rc);
  5693. goto error_disable_panel;
  5694. }
  5695. } else {
  5696. pr_err("[%s] Invalid configuration\n", display->name);
  5697. rc = -EINVAL;
  5698. goto error_disable_panel;
  5699. }
  5700. goto error;
  5701. error_disable_panel:
  5702. (void)dsi_panel_disable(display->panel);
  5703. error:
  5704. mutex_unlock(&display->display_lock);
  5705. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  5706. return rc;
  5707. }
  5708. int dsi_display_post_enable(struct dsi_display *display)
  5709. {
  5710. int rc = 0;
  5711. if (!display) {
  5712. pr_err("Invalid params\n");
  5713. return -EINVAL;
  5714. }
  5715. mutex_lock(&display->display_lock);
  5716. if (display->panel->cur_mode->dsi_mode_flags & DSI_MODE_FLAG_POMS) {
  5717. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  5718. dsi_panel_mode_switch_to_cmd(display->panel);
  5719. if (display->config.panel_mode == DSI_OP_VIDEO_MODE)
  5720. dsi_panel_mode_switch_to_vid(display->panel);
  5721. } else {
  5722. rc = dsi_panel_post_enable(display->panel);
  5723. if (rc)
  5724. pr_err("[%s] panel post-enable failed, rc=%d\n",
  5725. display->name, rc);
  5726. }
  5727. /* remove the clk vote for CMD mode panels */
  5728. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  5729. dsi_display_clk_ctrl(display->dsi_clk_handle,
  5730. DSI_ALL_CLKS, DSI_CLK_OFF);
  5731. mutex_unlock(&display->display_lock);
  5732. return rc;
  5733. }
  5734. int dsi_display_pre_disable(struct dsi_display *display)
  5735. {
  5736. int rc = 0;
  5737. if (!display) {
  5738. pr_err("Invalid params\n");
  5739. return -EINVAL;
  5740. }
  5741. mutex_lock(&display->display_lock);
  5742. /* enable the clk vote for CMD mode panels */
  5743. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  5744. dsi_display_clk_ctrl(display->dsi_clk_handle,
  5745. DSI_ALL_CLKS, DSI_CLK_ON);
  5746. if (display->poms_pending) {
  5747. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  5748. dsi_panel_pre_mode_switch_to_video(display->panel);
  5749. if (display->config.panel_mode == DSI_OP_VIDEO_MODE)
  5750. dsi_panel_pre_mode_switch_to_cmd(display->panel);
  5751. } else {
  5752. rc = dsi_panel_pre_disable(display->panel);
  5753. if (rc)
  5754. pr_err("[%s] panel pre-disable failed, rc=%d\n",
  5755. display->name, rc);
  5756. }
  5757. mutex_unlock(&display->display_lock);
  5758. return rc;
  5759. }
  5760. int dsi_display_disable(struct dsi_display *display)
  5761. {
  5762. int rc = 0;
  5763. if (!display) {
  5764. pr_err("Invalid params\n");
  5765. return -EINVAL;
  5766. }
  5767. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  5768. mutex_lock(&display->display_lock);
  5769. rc = dsi_display_wake_up(display);
  5770. if (rc)
  5771. pr_err("[%s] display wake up failed, rc=%d\n",
  5772. display->name, rc);
  5773. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  5774. rc = dsi_display_vid_engine_disable(display);
  5775. if (rc)
  5776. pr_err("[%s]failed to disable DSI vid engine, rc=%d\n",
  5777. display->name, rc);
  5778. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  5779. rc = dsi_display_cmd_engine_disable(display);
  5780. if (rc)
  5781. pr_err("[%s]failed to disable DSI cmd engine, rc=%d\n",
  5782. display->name, rc);
  5783. } else {
  5784. pr_err("[%s] Invalid configuration\n", display->name);
  5785. rc = -EINVAL;
  5786. }
  5787. if (!display->poms_pending) {
  5788. rc = dsi_panel_disable(display->panel);
  5789. if (rc)
  5790. pr_err("[%s] failed to disable DSI panel, rc=%d\n",
  5791. display->name, rc);
  5792. }
  5793. mutex_unlock(&display->display_lock);
  5794. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  5795. return rc;
  5796. }
  5797. int dsi_display_update_pps(char *pps_cmd, void *disp)
  5798. {
  5799. struct dsi_display *display;
  5800. if (pps_cmd == NULL || disp == NULL) {
  5801. pr_err("Invalid parameter\n");
  5802. return -EINVAL;
  5803. }
  5804. display = disp;
  5805. mutex_lock(&display->display_lock);
  5806. memcpy(display->panel->dsc_pps_cmd, pps_cmd, DSI_CMD_PPS_SIZE);
  5807. mutex_unlock(&display->display_lock);
  5808. return 0;
  5809. }
  5810. int dsi_display_unprepare(struct dsi_display *display)
  5811. {
  5812. int rc = 0;
  5813. if (!display) {
  5814. pr_err("Invalid params\n");
  5815. return -EINVAL;
  5816. }
  5817. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  5818. mutex_lock(&display->display_lock);
  5819. rc = dsi_display_wake_up(display);
  5820. if (rc)
  5821. pr_err("[%s] display wake up failed, rc=%d\n",
  5822. display->name, rc);
  5823. if (!display->poms_pending) {
  5824. rc = dsi_panel_unprepare(display->panel);
  5825. if (rc)
  5826. pr_err("[%s] panel unprepare failed, rc=%d\n",
  5827. display->name, rc);
  5828. }
  5829. rc = dsi_display_ctrl_host_disable(display);
  5830. if (rc)
  5831. pr_err("[%s] failed to disable DSI host, rc=%d\n",
  5832. display->name, rc);
  5833. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  5834. DSI_LINK_CLK, DSI_CLK_OFF);
  5835. if (rc)
  5836. pr_err("[%s] failed to disable Link clocks, rc=%d\n",
  5837. display->name, rc);
  5838. rc = dsi_display_ctrl_deinit(display);
  5839. if (rc)
  5840. pr_err("[%s] failed to deinit controller, rc=%d\n",
  5841. display->name, rc);
  5842. if (!display->panel->ulps_suspend_enabled) {
  5843. rc = dsi_display_phy_disable(display);
  5844. if (rc)
  5845. pr_err("[%s] failed to disable DSI PHY, rc=%d\n",
  5846. display->name, rc);
  5847. }
  5848. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  5849. DSI_CORE_CLK, DSI_CLK_OFF);
  5850. if (rc)
  5851. pr_err("[%s] failed to disable DSI clocks, rc=%d\n",
  5852. display->name, rc);
  5853. /* destrory dsi isr set up */
  5854. dsi_display_ctrl_isr_configure(display, false);
  5855. if (!display->poms_pending) {
  5856. rc = dsi_panel_post_unprepare(display->panel);
  5857. if (rc)
  5858. pr_err("[%s] panel post-unprepare failed, rc=%d\n",
  5859. display->name, rc);
  5860. }
  5861. mutex_unlock(&display->display_lock);
  5862. /* Free up DSI ERROR event callback */
  5863. dsi_display_unregister_error_handler(display);
  5864. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  5865. return rc;
  5866. }
  5867. static int __init dsi_display_register(void)
  5868. {
  5869. dsi_phy_drv_register();
  5870. dsi_ctrl_drv_register();
  5871. dsi_display_parse_boot_display_selection();
  5872. return platform_driver_register(&dsi_display_driver);
  5873. }
  5874. static void __exit dsi_display_unregister(void)
  5875. {
  5876. platform_driver_unregister(&dsi_display_driver);
  5877. dsi_ctrl_drv_unregister();
  5878. dsi_phy_drv_unregister();
  5879. }
  5880. module_param_string(dsi_display0, dsi_display_primary, MAX_CMDLINE_PARAM_LEN,
  5881. 0600);
  5882. MODULE_PARM_DESC(dsi_display0,
  5883. "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");
  5884. module_param_string(dsi_display1, dsi_display_secondary, MAX_CMDLINE_PARAM_LEN,
  5885. 0600);
  5886. MODULE_PARM_DESC(dsi_display1,
  5887. "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");
  5888. module_init(dsi_display_register);
  5889. module_exit(dsi_display_unregister);