dsi_display.c 181 KB

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