dsi_display.c 184 KB

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