dsi_display.c 180 KB

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