dsi_display.c 189 KB

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