dsi_display.c 180 KB

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