dsi_display.c 169 KB

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