dsi_display.c 168 KB

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