intel_dp.c 156 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672
  1. /*
  2. * Copyright © 2008 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Keith Packard <keithp@keithp.com>
  25. *
  26. */
  27. #include <linux/i2c.h>
  28. #include <linux/slab.h>
  29. #include <linux/export.h>
  30. #include <linux/notifier.h>
  31. #include <linux/reboot.h>
  32. #include <drm/drmP.h>
  33. #include <drm/drm_atomic_helper.h>
  34. #include <drm/drm_crtc.h>
  35. #include <drm/drm_crtc_helper.h>
  36. #include <drm/drm_edid.h>
  37. #include "intel_drv.h"
  38. #include <drm/i915_drm.h>
  39. #include "i915_drv.h"
  40. #define DP_LINK_CHECK_TIMEOUT (10 * 1000)
  41. /* Compliance test status bits */
  42. #define INTEL_DP_RESOLUTION_SHIFT_MASK 0
  43. #define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
  44. #define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
  45. #define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
  46. struct dp_link_dpll {
  47. int clock;
  48. struct dpll dpll;
  49. };
  50. static const struct dp_link_dpll gen4_dpll[] = {
  51. { 162000,
  52. { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
  53. { 270000,
  54. { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
  55. };
  56. static const struct dp_link_dpll pch_dpll[] = {
  57. { 162000,
  58. { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
  59. { 270000,
  60. { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
  61. };
  62. static const struct dp_link_dpll vlv_dpll[] = {
  63. { 162000,
  64. { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
  65. { 270000,
  66. { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
  67. };
  68. /*
  69. * CHV supports eDP 1.4 that have more link rates.
  70. * Below only provides the fixed rate but exclude variable rate.
  71. */
  72. static const struct dp_link_dpll chv_dpll[] = {
  73. /*
  74. * CHV requires to program fractional division for m2.
  75. * m2 is stored in fixed point format using formula below
  76. * (m2_int << 22) | m2_fraction
  77. */
  78. { 162000, /* m2_int = 32, m2_fraction = 1677722 */
  79. { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
  80. { 270000, /* m2_int = 27, m2_fraction = 0 */
  81. { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
  82. { 540000, /* m2_int = 27, m2_fraction = 0 */
  83. { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
  84. };
  85. static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
  86. 324000, 432000, 540000 };
  87. static const int skl_rates[] = { 162000, 216000, 270000,
  88. 324000, 432000, 540000 };
  89. static const int default_rates[] = { 162000, 270000, 540000 };
  90. /**
  91. * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
  92. * @intel_dp: DP struct
  93. *
  94. * If a CPU or PCH DP output is attached to an eDP panel, this function
  95. * will return true, and false otherwise.
  96. */
  97. static bool is_edp(struct intel_dp *intel_dp)
  98. {
  99. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  100. return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
  101. }
  102. static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
  103. {
  104. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  105. return intel_dig_port->base.base.dev;
  106. }
  107. static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
  108. {
  109. return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
  110. }
  111. static void intel_dp_link_down(struct intel_dp *intel_dp);
  112. static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
  113. static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
  114. static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
  115. static void vlv_steal_power_sequencer(struct drm_device *dev,
  116. enum pipe pipe);
  117. static void intel_dp_unset_edid(struct intel_dp *intel_dp);
  118. static int
  119. intel_dp_max_link_bw(struct intel_dp *intel_dp)
  120. {
  121. int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
  122. switch (max_link_bw) {
  123. case DP_LINK_BW_1_62:
  124. case DP_LINK_BW_2_7:
  125. case DP_LINK_BW_5_4:
  126. break;
  127. default:
  128. WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
  129. max_link_bw);
  130. max_link_bw = DP_LINK_BW_1_62;
  131. break;
  132. }
  133. return max_link_bw;
  134. }
  135. static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
  136. {
  137. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  138. u8 source_max, sink_max;
  139. source_max = intel_dig_port->max_lanes;
  140. sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
  141. return min(source_max, sink_max);
  142. }
  143. /*
  144. * The units on the numbers in the next two are... bizarre. Examples will
  145. * make it clearer; this one parallels an example in the eDP spec.
  146. *
  147. * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
  148. *
  149. * 270000 * 1 * 8 / 10 == 216000
  150. *
  151. * The actual data capacity of that configuration is 2.16Gbit/s, so the
  152. * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
  153. * or equivalently, kilopixels per second - so for 1680x1050R it'd be
  154. * 119000. At 18bpp that's 2142000 kilobits per second.
  155. *
  156. * Thus the strange-looking division by 10 in intel_dp_link_required, to
  157. * get the result in decakilobits instead of kilobits.
  158. */
  159. static int
  160. intel_dp_link_required(int pixel_clock, int bpp)
  161. {
  162. return (pixel_clock * bpp + 9) / 10;
  163. }
  164. static int
  165. intel_dp_max_data_rate(int max_link_clock, int max_lanes)
  166. {
  167. return (max_link_clock * max_lanes * 8) / 10;
  168. }
  169. static enum drm_mode_status
  170. intel_dp_mode_valid(struct drm_connector *connector,
  171. struct drm_display_mode *mode)
  172. {
  173. struct intel_dp *intel_dp = intel_attached_dp(connector);
  174. struct intel_connector *intel_connector = to_intel_connector(connector);
  175. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  176. int target_clock = mode->clock;
  177. int max_rate, mode_rate, max_lanes, max_link_clock;
  178. int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
  179. if (is_edp(intel_dp) && fixed_mode) {
  180. if (mode->hdisplay > fixed_mode->hdisplay)
  181. return MODE_PANEL;
  182. if (mode->vdisplay > fixed_mode->vdisplay)
  183. return MODE_PANEL;
  184. target_clock = fixed_mode->clock;
  185. }
  186. max_link_clock = intel_dp_max_link_rate(intel_dp);
  187. max_lanes = intel_dp_max_lane_count(intel_dp);
  188. max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
  189. mode_rate = intel_dp_link_required(target_clock, 18);
  190. if (mode_rate > max_rate || target_clock > max_dotclk)
  191. return MODE_CLOCK_HIGH;
  192. if (mode->clock < 10000)
  193. return MODE_CLOCK_LOW;
  194. if (mode->flags & DRM_MODE_FLAG_DBLCLK)
  195. return MODE_H_ILLEGAL;
  196. return MODE_OK;
  197. }
  198. uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
  199. {
  200. int i;
  201. uint32_t v = 0;
  202. if (src_bytes > 4)
  203. src_bytes = 4;
  204. for (i = 0; i < src_bytes; i++)
  205. v |= ((uint32_t) src[i]) << ((3-i) * 8);
  206. return v;
  207. }
  208. static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
  209. {
  210. int i;
  211. if (dst_bytes > 4)
  212. dst_bytes = 4;
  213. for (i = 0; i < dst_bytes; i++)
  214. dst[i] = src >> ((3-i) * 8);
  215. }
  216. static void
  217. intel_dp_init_panel_power_sequencer(struct drm_device *dev,
  218. struct intel_dp *intel_dp);
  219. static void
  220. intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
  221. struct intel_dp *intel_dp);
  222. static void pps_lock(struct intel_dp *intel_dp)
  223. {
  224. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  225. struct intel_encoder *encoder = &intel_dig_port->base;
  226. struct drm_device *dev = encoder->base.dev;
  227. struct drm_i915_private *dev_priv = dev->dev_private;
  228. enum intel_display_power_domain power_domain;
  229. /*
  230. * See vlv_power_sequencer_reset() why we need
  231. * a power domain reference here.
  232. */
  233. power_domain = intel_display_port_aux_power_domain(encoder);
  234. intel_display_power_get(dev_priv, power_domain);
  235. mutex_lock(&dev_priv->pps_mutex);
  236. }
  237. static void pps_unlock(struct intel_dp *intel_dp)
  238. {
  239. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  240. struct intel_encoder *encoder = &intel_dig_port->base;
  241. struct drm_device *dev = encoder->base.dev;
  242. struct drm_i915_private *dev_priv = dev->dev_private;
  243. enum intel_display_power_domain power_domain;
  244. mutex_unlock(&dev_priv->pps_mutex);
  245. power_domain = intel_display_port_aux_power_domain(encoder);
  246. intel_display_power_put(dev_priv, power_domain);
  247. }
  248. static void
  249. vlv_power_sequencer_kick(struct intel_dp *intel_dp)
  250. {
  251. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  252. struct drm_device *dev = intel_dig_port->base.base.dev;
  253. struct drm_i915_private *dev_priv = dev->dev_private;
  254. enum pipe pipe = intel_dp->pps_pipe;
  255. bool pll_enabled, release_cl_override = false;
  256. enum dpio_phy phy = DPIO_PHY(pipe);
  257. enum dpio_channel ch = vlv_pipe_to_channel(pipe);
  258. uint32_t DP;
  259. if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
  260. "skipping pipe %c power seqeuncer kick due to port %c being active\n",
  261. pipe_name(pipe), port_name(intel_dig_port->port)))
  262. return;
  263. DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
  264. pipe_name(pipe), port_name(intel_dig_port->port));
  265. /* Preserve the BIOS-computed detected bit. This is
  266. * supposed to be read-only.
  267. */
  268. DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
  269. DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
  270. DP |= DP_PORT_WIDTH(1);
  271. DP |= DP_LINK_TRAIN_PAT_1;
  272. if (IS_CHERRYVIEW(dev))
  273. DP |= DP_PIPE_SELECT_CHV(pipe);
  274. else if (pipe == PIPE_B)
  275. DP |= DP_PIPEB_SELECT;
  276. pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
  277. /*
  278. * The DPLL for the pipe must be enabled for this to work.
  279. * So enable temporarily it if it's not already enabled.
  280. */
  281. if (!pll_enabled) {
  282. release_cl_override = IS_CHERRYVIEW(dev) &&
  283. !chv_phy_powergate_ch(dev_priv, phy, ch, true);
  284. if (vlv_force_pll_on(dev, pipe, IS_CHERRYVIEW(dev) ?
  285. &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
  286. DRM_ERROR("Failed to force on pll for pipe %c!\n",
  287. pipe_name(pipe));
  288. return;
  289. }
  290. }
  291. /*
  292. * Similar magic as in intel_dp_enable_port().
  293. * We _must_ do this port enable + disable trick
  294. * to make this power seqeuencer lock onto the port.
  295. * Otherwise even VDD force bit won't work.
  296. */
  297. I915_WRITE(intel_dp->output_reg, DP);
  298. POSTING_READ(intel_dp->output_reg);
  299. I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
  300. POSTING_READ(intel_dp->output_reg);
  301. I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
  302. POSTING_READ(intel_dp->output_reg);
  303. if (!pll_enabled) {
  304. vlv_force_pll_off(dev, pipe);
  305. if (release_cl_override)
  306. chv_phy_powergate_ch(dev_priv, phy, ch, false);
  307. }
  308. }
  309. static enum pipe
  310. vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
  311. {
  312. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  313. struct drm_device *dev = intel_dig_port->base.base.dev;
  314. struct drm_i915_private *dev_priv = dev->dev_private;
  315. struct intel_encoder *encoder;
  316. unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
  317. enum pipe pipe;
  318. lockdep_assert_held(&dev_priv->pps_mutex);
  319. /* We should never land here with regular DP ports */
  320. WARN_ON(!is_edp(intel_dp));
  321. if (intel_dp->pps_pipe != INVALID_PIPE)
  322. return intel_dp->pps_pipe;
  323. /*
  324. * We don't have power sequencer currently.
  325. * Pick one that's not used by other ports.
  326. */
  327. for_each_intel_encoder(dev, encoder) {
  328. struct intel_dp *tmp;
  329. if (encoder->type != INTEL_OUTPUT_EDP)
  330. continue;
  331. tmp = enc_to_intel_dp(&encoder->base);
  332. if (tmp->pps_pipe != INVALID_PIPE)
  333. pipes &= ~(1 << tmp->pps_pipe);
  334. }
  335. /*
  336. * Didn't find one. This should not happen since there
  337. * are two power sequencers and up to two eDP ports.
  338. */
  339. if (WARN_ON(pipes == 0))
  340. pipe = PIPE_A;
  341. else
  342. pipe = ffs(pipes) - 1;
  343. vlv_steal_power_sequencer(dev, pipe);
  344. intel_dp->pps_pipe = pipe;
  345. DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
  346. pipe_name(intel_dp->pps_pipe),
  347. port_name(intel_dig_port->port));
  348. /* init power sequencer on this pipe and port */
  349. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  350. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
  351. /*
  352. * Even vdd force doesn't work until we've made
  353. * the power sequencer lock in on the port.
  354. */
  355. vlv_power_sequencer_kick(intel_dp);
  356. return intel_dp->pps_pipe;
  357. }
  358. typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
  359. enum pipe pipe);
  360. static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
  361. enum pipe pipe)
  362. {
  363. return I915_READ(VLV_PIPE_PP_STATUS(pipe)) & PP_ON;
  364. }
  365. static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
  366. enum pipe pipe)
  367. {
  368. return I915_READ(VLV_PIPE_PP_CONTROL(pipe)) & EDP_FORCE_VDD;
  369. }
  370. static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
  371. enum pipe pipe)
  372. {
  373. return true;
  374. }
  375. static enum pipe
  376. vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
  377. enum port port,
  378. vlv_pipe_check pipe_check)
  379. {
  380. enum pipe pipe;
  381. for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
  382. u32 port_sel = I915_READ(VLV_PIPE_PP_ON_DELAYS(pipe)) &
  383. PANEL_PORT_SELECT_MASK;
  384. if (port_sel != PANEL_PORT_SELECT_VLV(port))
  385. continue;
  386. if (!pipe_check(dev_priv, pipe))
  387. continue;
  388. return pipe;
  389. }
  390. return INVALID_PIPE;
  391. }
  392. static void
  393. vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
  394. {
  395. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  396. struct drm_device *dev = intel_dig_port->base.base.dev;
  397. struct drm_i915_private *dev_priv = dev->dev_private;
  398. enum port port = intel_dig_port->port;
  399. lockdep_assert_held(&dev_priv->pps_mutex);
  400. /* try to find a pipe with this port selected */
  401. /* first pick one where the panel is on */
  402. intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
  403. vlv_pipe_has_pp_on);
  404. /* didn't find one? pick one where vdd is on */
  405. if (intel_dp->pps_pipe == INVALID_PIPE)
  406. intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
  407. vlv_pipe_has_vdd_on);
  408. /* didn't find one? pick one with just the correct port */
  409. if (intel_dp->pps_pipe == INVALID_PIPE)
  410. intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
  411. vlv_pipe_any);
  412. /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
  413. if (intel_dp->pps_pipe == INVALID_PIPE) {
  414. DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
  415. port_name(port));
  416. return;
  417. }
  418. DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
  419. port_name(port), pipe_name(intel_dp->pps_pipe));
  420. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  421. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
  422. }
  423. void vlv_power_sequencer_reset(struct drm_i915_private *dev_priv)
  424. {
  425. struct drm_device *dev = dev_priv->dev;
  426. struct intel_encoder *encoder;
  427. if (WARN_ON(!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)))
  428. return;
  429. /*
  430. * We can't grab pps_mutex here due to deadlock with power_domain
  431. * mutex when power_domain functions are called while holding pps_mutex.
  432. * That also means that in order to use pps_pipe the code needs to
  433. * hold both a power domain reference and pps_mutex, and the power domain
  434. * reference get/put must be done while _not_ holding pps_mutex.
  435. * pps_{lock,unlock}() do these steps in the correct order, so one
  436. * should use them always.
  437. */
  438. for_each_intel_encoder(dev, encoder) {
  439. struct intel_dp *intel_dp;
  440. if (encoder->type != INTEL_OUTPUT_EDP)
  441. continue;
  442. intel_dp = enc_to_intel_dp(&encoder->base);
  443. intel_dp->pps_pipe = INVALID_PIPE;
  444. }
  445. }
  446. static i915_reg_t
  447. _pp_ctrl_reg(struct intel_dp *intel_dp)
  448. {
  449. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  450. if (IS_BROXTON(dev))
  451. return BXT_PP_CONTROL(0);
  452. else if (HAS_PCH_SPLIT(dev))
  453. return PCH_PP_CONTROL;
  454. else
  455. return VLV_PIPE_PP_CONTROL(vlv_power_sequencer_pipe(intel_dp));
  456. }
  457. static i915_reg_t
  458. _pp_stat_reg(struct intel_dp *intel_dp)
  459. {
  460. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  461. if (IS_BROXTON(dev))
  462. return BXT_PP_STATUS(0);
  463. else if (HAS_PCH_SPLIT(dev))
  464. return PCH_PP_STATUS;
  465. else
  466. return VLV_PIPE_PP_STATUS(vlv_power_sequencer_pipe(intel_dp));
  467. }
  468. /* Reboot notifier handler to shutdown panel power to guarantee T12 timing
  469. This function only applicable when panel PM state is not to be tracked */
  470. static int edp_notify_handler(struct notifier_block *this, unsigned long code,
  471. void *unused)
  472. {
  473. struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
  474. edp_notifier);
  475. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  476. struct drm_i915_private *dev_priv = dev->dev_private;
  477. if (!is_edp(intel_dp) || code != SYS_RESTART)
  478. return 0;
  479. pps_lock(intel_dp);
  480. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  481. enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
  482. i915_reg_t pp_ctrl_reg, pp_div_reg;
  483. u32 pp_div;
  484. pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
  485. pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
  486. pp_div = I915_READ(pp_div_reg);
  487. pp_div &= PP_REFERENCE_DIVIDER_MASK;
  488. /* 0x1F write to PP_DIV_REG sets max cycle delay */
  489. I915_WRITE(pp_div_reg, pp_div | 0x1F);
  490. I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
  491. msleep(intel_dp->panel_power_cycle_delay);
  492. }
  493. pps_unlock(intel_dp);
  494. return 0;
  495. }
  496. static bool edp_have_panel_power(struct intel_dp *intel_dp)
  497. {
  498. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  499. struct drm_i915_private *dev_priv = dev->dev_private;
  500. lockdep_assert_held(&dev_priv->pps_mutex);
  501. if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
  502. intel_dp->pps_pipe == INVALID_PIPE)
  503. return false;
  504. return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
  505. }
  506. static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
  507. {
  508. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  509. struct drm_i915_private *dev_priv = dev->dev_private;
  510. lockdep_assert_held(&dev_priv->pps_mutex);
  511. if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
  512. intel_dp->pps_pipe == INVALID_PIPE)
  513. return false;
  514. return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
  515. }
  516. static void
  517. intel_dp_check_edp(struct intel_dp *intel_dp)
  518. {
  519. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  520. struct drm_i915_private *dev_priv = dev->dev_private;
  521. if (!is_edp(intel_dp))
  522. return;
  523. if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
  524. WARN(1, "eDP powered off while attempting aux channel communication.\n");
  525. DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
  526. I915_READ(_pp_stat_reg(intel_dp)),
  527. I915_READ(_pp_ctrl_reg(intel_dp)));
  528. }
  529. }
  530. static uint32_t
  531. intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
  532. {
  533. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  534. struct drm_device *dev = intel_dig_port->base.base.dev;
  535. struct drm_i915_private *dev_priv = dev->dev_private;
  536. i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
  537. uint32_t status;
  538. bool done;
  539. #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
  540. if (has_aux_irq)
  541. done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
  542. msecs_to_jiffies_timeout(10));
  543. else
  544. done = wait_for_atomic(C, 10) == 0;
  545. if (!done)
  546. DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
  547. has_aux_irq);
  548. #undef C
  549. return status;
  550. }
  551. static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  552. {
  553. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  554. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  555. if (index)
  556. return 0;
  557. /*
  558. * The clock divider is based off the hrawclk, and would like to run at
  559. * 2MHz. So, take the hrawclk value and divide by 2000 and use that
  560. */
  561. return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
  562. }
  563. static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  564. {
  565. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  566. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  567. if (index)
  568. return 0;
  569. /*
  570. * The clock divider is based off the cdclk or PCH rawclk, and would
  571. * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
  572. * divide by 2000 and use that
  573. */
  574. if (intel_dig_port->port == PORT_A)
  575. return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
  576. else
  577. return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
  578. }
  579. static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  580. {
  581. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  582. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  583. if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
  584. /* Workaround for non-ULT HSW */
  585. switch (index) {
  586. case 0: return 63;
  587. case 1: return 72;
  588. default: return 0;
  589. }
  590. }
  591. return ilk_get_aux_clock_divider(intel_dp, index);
  592. }
  593. static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  594. {
  595. /*
  596. * SKL doesn't need us to program the AUX clock divider (Hardware will
  597. * derive the clock from CDCLK automatically). We still implement the
  598. * get_aux_clock_divider vfunc to plug-in into the existing code.
  599. */
  600. return index ? 0 : 1;
  601. }
  602. static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
  603. bool has_aux_irq,
  604. int send_bytes,
  605. uint32_t aux_clock_divider)
  606. {
  607. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  608. struct drm_device *dev = intel_dig_port->base.base.dev;
  609. uint32_t precharge, timeout;
  610. if (IS_GEN6(dev))
  611. precharge = 3;
  612. else
  613. precharge = 5;
  614. if (IS_BROADWELL(dev) && intel_dig_port->port == PORT_A)
  615. timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
  616. else
  617. timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
  618. return DP_AUX_CH_CTL_SEND_BUSY |
  619. DP_AUX_CH_CTL_DONE |
  620. (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
  621. DP_AUX_CH_CTL_TIME_OUT_ERROR |
  622. timeout |
  623. DP_AUX_CH_CTL_RECEIVE_ERROR |
  624. (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
  625. (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
  626. (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
  627. }
  628. static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
  629. bool has_aux_irq,
  630. int send_bytes,
  631. uint32_t unused)
  632. {
  633. return DP_AUX_CH_CTL_SEND_BUSY |
  634. DP_AUX_CH_CTL_DONE |
  635. (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
  636. DP_AUX_CH_CTL_TIME_OUT_ERROR |
  637. DP_AUX_CH_CTL_TIME_OUT_1600us |
  638. DP_AUX_CH_CTL_RECEIVE_ERROR |
  639. (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
  640. DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
  641. DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
  642. }
  643. static int
  644. intel_dp_aux_ch(struct intel_dp *intel_dp,
  645. const uint8_t *send, int send_bytes,
  646. uint8_t *recv, int recv_size)
  647. {
  648. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  649. struct drm_device *dev = intel_dig_port->base.base.dev;
  650. struct drm_i915_private *dev_priv = dev->dev_private;
  651. i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
  652. uint32_t aux_clock_divider;
  653. int i, ret, recv_bytes;
  654. uint32_t status;
  655. int try, clock = 0;
  656. bool has_aux_irq = HAS_AUX_IRQ(dev);
  657. bool vdd;
  658. pps_lock(intel_dp);
  659. /*
  660. * We will be called with VDD already enabled for dpcd/edid/oui reads.
  661. * In such cases we want to leave VDD enabled and it's up to upper layers
  662. * to turn it off. But for eg. i2c-dev access we need to turn it on/off
  663. * ourselves.
  664. */
  665. vdd = edp_panel_vdd_on(intel_dp);
  666. /* dp aux is extremely sensitive to irq latency, hence request the
  667. * lowest possible wakeup latency and so prevent the cpu from going into
  668. * deep sleep states.
  669. */
  670. pm_qos_update_request(&dev_priv->pm_qos, 0);
  671. intel_dp_check_edp(intel_dp);
  672. /* Try to wait for any previous AUX channel activity */
  673. for (try = 0; try < 3; try++) {
  674. status = I915_READ_NOTRACE(ch_ctl);
  675. if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
  676. break;
  677. msleep(1);
  678. }
  679. if (try == 3) {
  680. static u32 last_status = -1;
  681. const u32 status = I915_READ(ch_ctl);
  682. if (status != last_status) {
  683. WARN(1, "dp_aux_ch not started status 0x%08x\n",
  684. status);
  685. last_status = status;
  686. }
  687. ret = -EBUSY;
  688. goto out;
  689. }
  690. /* Only 5 data registers! */
  691. if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
  692. ret = -E2BIG;
  693. goto out;
  694. }
  695. while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
  696. u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
  697. has_aux_irq,
  698. send_bytes,
  699. aux_clock_divider);
  700. /* Must try at least 3 times according to DP spec */
  701. for (try = 0; try < 5; try++) {
  702. /* Load the send data into the aux channel data registers */
  703. for (i = 0; i < send_bytes; i += 4)
  704. I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
  705. intel_dp_pack_aux(send + i,
  706. send_bytes - i));
  707. /* Send the command and wait for it to complete */
  708. I915_WRITE(ch_ctl, send_ctl);
  709. status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
  710. /* Clear done status and any errors */
  711. I915_WRITE(ch_ctl,
  712. status |
  713. DP_AUX_CH_CTL_DONE |
  714. DP_AUX_CH_CTL_TIME_OUT_ERROR |
  715. DP_AUX_CH_CTL_RECEIVE_ERROR);
  716. if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
  717. continue;
  718. /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
  719. * 400us delay required for errors and timeouts
  720. * Timeout errors from the HW already meet this
  721. * requirement so skip to next iteration
  722. */
  723. if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
  724. usleep_range(400, 500);
  725. continue;
  726. }
  727. if (status & DP_AUX_CH_CTL_DONE)
  728. goto done;
  729. }
  730. }
  731. if ((status & DP_AUX_CH_CTL_DONE) == 0) {
  732. DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
  733. ret = -EBUSY;
  734. goto out;
  735. }
  736. done:
  737. /* Check for timeout or receive error.
  738. * Timeouts occur when the sink is not connected
  739. */
  740. if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
  741. DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
  742. ret = -EIO;
  743. goto out;
  744. }
  745. /* Timeouts occur when the device isn't connected, so they're
  746. * "normal" -- don't fill the kernel log with these */
  747. if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
  748. DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
  749. ret = -ETIMEDOUT;
  750. goto out;
  751. }
  752. /* Unload any bytes sent back from the other side */
  753. recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
  754. DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
  755. /*
  756. * By BSpec: "Message sizes of 0 or >20 are not allowed."
  757. * We have no idea of what happened so we return -EBUSY so
  758. * drm layer takes care for the necessary retries.
  759. */
  760. if (recv_bytes == 0 || recv_bytes > 20) {
  761. DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
  762. recv_bytes);
  763. /*
  764. * FIXME: This patch was created on top of a series that
  765. * organize the retries at drm level. There EBUSY should
  766. * also take care for 1ms wait before retrying.
  767. * That aux retries re-org is still needed and after that is
  768. * merged we remove this sleep from here.
  769. */
  770. usleep_range(1000, 1500);
  771. ret = -EBUSY;
  772. goto out;
  773. }
  774. if (recv_bytes > recv_size)
  775. recv_bytes = recv_size;
  776. for (i = 0; i < recv_bytes; i += 4)
  777. intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
  778. recv + i, recv_bytes - i);
  779. ret = recv_bytes;
  780. out:
  781. pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
  782. if (vdd)
  783. edp_panel_vdd_off(intel_dp, false);
  784. pps_unlock(intel_dp);
  785. return ret;
  786. }
  787. #define BARE_ADDRESS_SIZE 3
  788. #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
  789. static ssize_t
  790. intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
  791. {
  792. struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
  793. uint8_t txbuf[20], rxbuf[20];
  794. size_t txsize, rxsize;
  795. int ret;
  796. txbuf[0] = (msg->request << 4) |
  797. ((msg->address >> 16) & 0xf);
  798. txbuf[1] = (msg->address >> 8) & 0xff;
  799. txbuf[2] = msg->address & 0xff;
  800. txbuf[3] = msg->size - 1;
  801. switch (msg->request & ~DP_AUX_I2C_MOT) {
  802. case DP_AUX_NATIVE_WRITE:
  803. case DP_AUX_I2C_WRITE:
  804. case DP_AUX_I2C_WRITE_STATUS_UPDATE:
  805. txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
  806. rxsize = 2; /* 0 or 1 data bytes */
  807. if (WARN_ON(txsize > 20))
  808. return -E2BIG;
  809. if (msg->buffer)
  810. memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
  811. else
  812. WARN_ON(msg->size);
  813. ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
  814. if (ret > 0) {
  815. msg->reply = rxbuf[0] >> 4;
  816. if (ret > 1) {
  817. /* Number of bytes written in a short write. */
  818. ret = clamp_t(int, rxbuf[1], 0, msg->size);
  819. } else {
  820. /* Return payload size. */
  821. ret = msg->size;
  822. }
  823. }
  824. break;
  825. case DP_AUX_NATIVE_READ:
  826. case DP_AUX_I2C_READ:
  827. txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
  828. rxsize = msg->size + 1;
  829. if (WARN_ON(rxsize > 20))
  830. return -E2BIG;
  831. ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
  832. if (ret > 0) {
  833. msg->reply = rxbuf[0] >> 4;
  834. /*
  835. * Assume happy day, and copy the data. The caller is
  836. * expected to check msg->reply before touching it.
  837. *
  838. * Return payload size.
  839. */
  840. ret--;
  841. memcpy(msg->buffer, rxbuf + 1, ret);
  842. }
  843. break;
  844. default:
  845. ret = -EINVAL;
  846. break;
  847. }
  848. return ret;
  849. }
  850. static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
  851. enum port port)
  852. {
  853. switch (port) {
  854. case PORT_B:
  855. case PORT_C:
  856. case PORT_D:
  857. return DP_AUX_CH_CTL(port);
  858. default:
  859. MISSING_CASE(port);
  860. return DP_AUX_CH_CTL(PORT_B);
  861. }
  862. }
  863. static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
  864. enum port port, int index)
  865. {
  866. switch (port) {
  867. case PORT_B:
  868. case PORT_C:
  869. case PORT_D:
  870. return DP_AUX_CH_DATA(port, index);
  871. default:
  872. MISSING_CASE(port);
  873. return DP_AUX_CH_DATA(PORT_B, index);
  874. }
  875. }
  876. static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
  877. enum port port)
  878. {
  879. switch (port) {
  880. case PORT_A:
  881. return DP_AUX_CH_CTL(port);
  882. case PORT_B:
  883. case PORT_C:
  884. case PORT_D:
  885. return PCH_DP_AUX_CH_CTL(port);
  886. default:
  887. MISSING_CASE(port);
  888. return DP_AUX_CH_CTL(PORT_A);
  889. }
  890. }
  891. static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
  892. enum port port, int index)
  893. {
  894. switch (port) {
  895. case PORT_A:
  896. return DP_AUX_CH_DATA(port, index);
  897. case PORT_B:
  898. case PORT_C:
  899. case PORT_D:
  900. return PCH_DP_AUX_CH_DATA(port, index);
  901. default:
  902. MISSING_CASE(port);
  903. return DP_AUX_CH_DATA(PORT_A, index);
  904. }
  905. }
  906. /*
  907. * On SKL we don't have Aux for port E so we rely
  908. * on VBT to set a proper alternate aux channel.
  909. */
  910. static enum port skl_porte_aux_port(struct drm_i915_private *dev_priv)
  911. {
  912. const struct ddi_vbt_port_info *info =
  913. &dev_priv->vbt.ddi_port_info[PORT_E];
  914. switch (info->alternate_aux_channel) {
  915. case DP_AUX_A:
  916. return PORT_A;
  917. case DP_AUX_B:
  918. return PORT_B;
  919. case DP_AUX_C:
  920. return PORT_C;
  921. case DP_AUX_D:
  922. return PORT_D;
  923. default:
  924. MISSING_CASE(info->alternate_aux_channel);
  925. return PORT_A;
  926. }
  927. }
  928. static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
  929. enum port port)
  930. {
  931. if (port == PORT_E)
  932. port = skl_porte_aux_port(dev_priv);
  933. switch (port) {
  934. case PORT_A:
  935. case PORT_B:
  936. case PORT_C:
  937. case PORT_D:
  938. return DP_AUX_CH_CTL(port);
  939. default:
  940. MISSING_CASE(port);
  941. return DP_AUX_CH_CTL(PORT_A);
  942. }
  943. }
  944. static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
  945. enum port port, int index)
  946. {
  947. if (port == PORT_E)
  948. port = skl_porte_aux_port(dev_priv);
  949. switch (port) {
  950. case PORT_A:
  951. case PORT_B:
  952. case PORT_C:
  953. case PORT_D:
  954. return DP_AUX_CH_DATA(port, index);
  955. default:
  956. MISSING_CASE(port);
  957. return DP_AUX_CH_DATA(PORT_A, index);
  958. }
  959. }
  960. static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
  961. enum port port)
  962. {
  963. if (INTEL_INFO(dev_priv)->gen >= 9)
  964. return skl_aux_ctl_reg(dev_priv, port);
  965. else if (HAS_PCH_SPLIT(dev_priv))
  966. return ilk_aux_ctl_reg(dev_priv, port);
  967. else
  968. return g4x_aux_ctl_reg(dev_priv, port);
  969. }
  970. static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
  971. enum port port, int index)
  972. {
  973. if (INTEL_INFO(dev_priv)->gen >= 9)
  974. return skl_aux_data_reg(dev_priv, port, index);
  975. else if (HAS_PCH_SPLIT(dev_priv))
  976. return ilk_aux_data_reg(dev_priv, port, index);
  977. else
  978. return g4x_aux_data_reg(dev_priv, port, index);
  979. }
  980. static void intel_aux_reg_init(struct intel_dp *intel_dp)
  981. {
  982. struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
  983. enum port port = dp_to_dig_port(intel_dp)->port;
  984. int i;
  985. intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
  986. for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
  987. intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
  988. }
  989. static void
  990. intel_dp_aux_fini(struct intel_dp *intel_dp)
  991. {
  992. drm_dp_aux_unregister(&intel_dp->aux);
  993. kfree(intel_dp->aux.name);
  994. }
  995. static int
  996. intel_dp_aux_init(struct intel_dp *intel_dp, struct intel_connector *connector)
  997. {
  998. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  999. enum port port = intel_dig_port->port;
  1000. int ret;
  1001. intel_aux_reg_init(intel_dp);
  1002. intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
  1003. if (!intel_dp->aux.name)
  1004. return -ENOMEM;
  1005. intel_dp->aux.dev = connector->base.kdev;
  1006. intel_dp->aux.transfer = intel_dp_aux_transfer;
  1007. DRM_DEBUG_KMS("registering %s bus for %s\n",
  1008. intel_dp->aux.name,
  1009. connector->base.kdev->kobj.name);
  1010. ret = drm_dp_aux_register(&intel_dp->aux);
  1011. if (ret < 0) {
  1012. DRM_ERROR("drm_dp_aux_register() for %s failed (%d)\n",
  1013. intel_dp->aux.name, ret);
  1014. kfree(intel_dp->aux.name);
  1015. return ret;
  1016. }
  1017. return 0;
  1018. }
  1019. static void
  1020. intel_dp_connector_unregister(struct intel_connector *intel_connector)
  1021. {
  1022. struct intel_dp *intel_dp = intel_attached_dp(&intel_connector->base);
  1023. intel_dp_aux_fini(intel_dp);
  1024. intel_connector_unregister(intel_connector);
  1025. }
  1026. static int
  1027. intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
  1028. {
  1029. if (intel_dp->num_sink_rates) {
  1030. *sink_rates = intel_dp->sink_rates;
  1031. return intel_dp->num_sink_rates;
  1032. }
  1033. *sink_rates = default_rates;
  1034. return (intel_dp_max_link_bw(intel_dp) >> 3) + 1;
  1035. }
  1036. bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
  1037. {
  1038. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  1039. struct drm_device *dev = dig_port->base.base.dev;
  1040. /* WaDisableHBR2:skl */
  1041. if (IS_SKL_REVID(dev, 0, SKL_REVID_B0))
  1042. return false;
  1043. if ((IS_HASWELL(dev) && !IS_HSW_ULX(dev)) || IS_BROADWELL(dev) ||
  1044. (INTEL_INFO(dev)->gen >= 9))
  1045. return true;
  1046. else
  1047. return false;
  1048. }
  1049. static int
  1050. intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
  1051. {
  1052. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  1053. struct drm_device *dev = dig_port->base.base.dev;
  1054. int size;
  1055. if (IS_BROXTON(dev)) {
  1056. *source_rates = bxt_rates;
  1057. size = ARRAY_SIZE(bxt_rates);
  1058. } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
  1059. *source_rates = skl_rates;
  1060. size = ARRAY_SIZE(skl_rates);
  1061. } else {
  1062. *source_rates = default_rates;
  1063. size = ARRAY_SIZE(default_rates);
  1064. }
  1065. /* This depends on the fact that 5.4 is last value in the array */
  1066. if (!intel_dp_source_supports_hbr2(intel_dp))
  1067. size--;
  1068. return size;
  1069. }
  1070. static void
  1071. intel_dp_set_clock(struct intel_encoder *encoder,
  1072. struct intel_crtc_state *pipe_config)
  1073. {
  1074. struct drm_device *dev = encoder->base.dev;
  1075. const struct dp_link_dpll *divisor = NULL;
  1076. int i, count = 0;
  1077. if (IS_G4X(dev)) {
  1078. divisor = gen4_dpll;
  1079. count = ARRAY_SIZE(gen4_dpll);
  1080. } else if (HAS_PCH_SPLIT(dev)) {
  1081. divisor = pch_dpll;
  1082. count = ARRAY_SIZE(pch_dpll);
  1083. } else if (IS_CHERRYVIEW(dev)) {
  1084. divisor = chv_dpll;
  1085. count = ARRAY_SIZE(chv_dpll);
  1086. } else if (IS_VALLEYVIEW(dev)) {
  1087. divisor = vlv_dpll;
  1088. count = ARRAY_SIZE(vlv_dpll);
  1089. }
  1090. if (divisor && count) {
  1091. for (i = 0; i < count; i++) {
  1092. if (pipe_config->port_clock == divisor[i].clock) {
  1093. pipe_config->dpll = divisor[i].dpll;
  1094. pipe_config->clock_set = true;
  1095. break;
  1096. }
  1097. }
  1098. }
  1099. }
  1100. static int intersect_rates(const int *source_rates, int source_len,
  1101. const int *sink_rates, int sink_len,
  1102. int *common_rates)
  1103. {
  1104. int i = 0, j = 0, k = 0;
  1105. while (i < source_len && j < sink_len) {
  1106. if (source_rates[i] == sink_rates[j]) {
  1107. if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
  1108. return k;
  1109. common_rates[k] = source_rates[i];
  1110. ++k;
  1111. ++i;
  1112. ++j;
  1113. } else if (source_rates[i] < sink_rates[j]) {
  1114. ++i;
  1115. } else {
  1116. ++j;
  1117. }
  1118. }
  1119. return k;
  1120. }
  1121. static int intel_dp_common_rates(struct intel_dp *intel_dp,
  1122. int *common_rates)
  1123. {
  1124. const int *source_rates, *sink_rates;
  1125. int source_len, sink_len;
  1126. sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
  1127. source_len = intel_dp_source_rates(intel_dp, &source_rates);
  1128. return intersect_rates(source_rates, source_len,
  1129. sink_rates, sink_len,
  1130. common_rates);
  1131. }
  1132. static void snprintf_int_array(char *str, size_t len,
  1133. const int *array, int nelem)
  1134. {
  1135. int i;
  1136. str[0] = '\0';
  1137. for (i = 0; i < nelem; i++) {
  1138. int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
  1139. if (r >= len)
  1140. return;
  1141. str += r;
  1142. len -= r;
  1143. }
  1144. }
  1145. static void intel_dp_print_rates(struct intel_dp *intel_dp)
  1146. {
  1147. const int *source_rates, *sink_rates;
  1148. int source_len, sink_len, common_len;
  1149. int common_rates[DP_MAX_SUPPORTED_RATES];
  1150. char str[128]; /* FIXME: too big for stack? */
  1151. if ((drm_debug & DRM_UT_KMS) == 0)
  1152. return;
  1153. source_len = intel_dp_source_rates(intel_dp, &source_rates);
  1154. snprintf_int_array(str, sizeof(str), source_rates, source_len);
  1155. DRM_DEBUG_KMS("source rates: %s\n", str);
  1156. sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
  1157. snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
  1158. DRM_DEBUG_KMS("sink rates: %s\n", str);
  1159. common_len = intel_dp_common_rates(intel_dp, common_rates);
  1160. snprintf_int_array(str, sizeof(str), common_rates, common_len);
  1161. DRM_DEBUG_KMS("common rates: %s\n", str);
  1162. }
  1163. static int rate_to_index(int find, const int *rates)
  1164. {
  1165. int i = 0;
  1166. for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
  1167. if (find == rates[i])
  1168. break;
  1169. return i;
  1170. }
  1171. int
  1172. intel_dp_max_link_rate(struct intel_dp *intel_dp)
  1173. {
  1174. int rates[DP_MAX_SUPPORTED_RATES] = {};
  1175. int len;
  1176. len = intel_dp_common_rates(intel_dp, rates);
  1177. if (WARN_ON(len <= 0))
  1178. return 162000;
  1179. return rates[rate_to_index(0, rates) - 1];
  1180. }
  1181. int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
  1182. {
  1183. return rate_to_index(rate, intel_dp->sink_rates);
  1184. }
  1185. void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
  1186. uint8_t *link_bw, uint8_t *rate_select)
  1187. {
  1188. if (intel_dp->num_sink_rates) {
  1189. *link_bw = 0;
  1190. *rate_select =
  1191. intel_dp_rate_select(intel_dp, port_clock);
  1192. } else {
  1193. *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
  1194. *rate_select = 0;
  1195. }
  1196. }
  1197. bool
  1198. intel_dp_compute_config(struct intel_encoder *encoder,
  1199. struct intel_crtc_state *pipe_config)
  1200. {
  1201. struct drm_device *dev = encoder->base.dev;
  1202. struct drm_i915_private *dev_priv = dev->dev_private;
  1203. struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  1204. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1205. enum port port = dp_to_dig_port(intel_dp)->port;
  1206. struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
  1207. struct intel_connector *intel_connector = intel_dp->attached_connector;
  1208. int lane_count, clock;
  1209. int min_lane_count = 1;
  1210. int max_lane_count = intel_dp_max_lane_count(intel_dp);
  1211. /* Conveniently, the link BW constants become indices with a shift...*/
  1212. int min_clock = 0;
  1213. int max_clock;
  1214. int bpp, mode_rate;
  1215. int link_avail, link_clock;
  1216. int common_rates[DP_MAX_SUPPORTED_RATES] = {};
  1217. int common_len;
  1218. uint8_t link_bw, rate_select;
  1219. common_len = intel_dp_common_rates(intel_dp, common_rates);
  1220. /* No common link rates between source and sink */
  1221. WARN_ON(common_len <= 0);
  1222. max_clock = common_len - 1;
  1223. if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
  1224. pipe_config->has_pch_encoder = true;
  1225. pipe_config->has_dp_encoder = true;
  1226. pipe_config->has_drrs = false;
  1227. pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
  1228. if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
  1229. intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
  1230. adjusted_mode);
  1231. if (INTEL_INFO(dev)->gen >= 9) {
  1232. int ret;
  1233. ret = skl_update_scaler_crtc(pipe_config);
  1234. if (ret)
  1235. return ret;
  1236. }
  1237. if (HAS_GMCH_DISPLAY(dev))
  1238. intel_gmch_panel_fitting(intel_crtc, pipe_config,
  1239. intel_connector->panel.fitting_mode);
  1240. else
  1241. intel_pch_panel_fitting(intel_crtc, pipe_config,
  1242. intel_connector->panel.fitting_mode);
  1243. }
  1244. if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
  1245. return false;
  1246. DRM_DEBUG_KMS("DP link computation with max lane count %i "
  1247. "max bw %d pixel clock %iKHz\n",
  1248. max_lane_count, common_rates[max_clock],
  1249. adjusted_mode->crtc_clock);
  1250. /* Walk through all bpp values. Luckily they're all nicely spaced with 2
  1251. * bpc in between. */
  1252. bpp = pipe_config->pipe_bpp;
  1253. if (is_edp(intel_dp)) {
  1254. /* Get bpp from vbt only for panels that dont have bpp in edid */
  1255. if (intel_connector->base.display_info.bpc == 0 &&
  1256. (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
  1257. DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
  1258. dev_priv->vbt.edp.bpp);
  1259. bpp = dev_priv->vbt.edp.bpp;
  1260. }
  1261. /*
  1262. * Use the maximum clock and number of lanes the eDP panel
  1263. * advertizes being capable of. The panels are generally
  1264. * designed to support only a single clock and lane
  1265. * configuration, and typically these values correspond to the
  1266. * native resolution of the panel.
  1267. */
  1268. min_lane_count = max_lane_count;
  1269. min_clock = max_clock;
  1270. }
  1271. for (; bpp >= 6*3; bpp -= 2*3) {
  1272. mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
  1273. bpp);
  1274. for (clock = min_clock; clock <= max_clock; clock++) {
  1275. for (lane_count = min_lane_count;
  1276. lane_count <= max_lane_count;
  1277. lane_count <<= 1) {
  1278. link_clock = common_rates[clock];
  1279. link_avail = intel_dp_max_data_rate(link_clock,
  1280. lane_count);
  1281. if (mode_rate <= link_avail) {
  1282. goto found;
  1283. }
  1284. }
  1285. }
  1286. }
  1287. return false;
  1288. found:
  1289. if (intel_dp->color_range_auto) {
  1290. /*
  1291. * See:
  1292. * CEA-861-E - 5.1 Default Encoding Parameters
  1293. * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
  1294. */
  1295. pipe_config->limited_color_range =
  1296. bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
  1297. } else {
  1298. pipe_config->limited_color_range =
  1299. intel_dp->limited_color_range;
  1300. }
  1301. pipe_config->lane_count = lane_count;
  1302. pipe_config->pipe_bpp = bpp;
  1303. pipe_config->port_clock = common_rates[clock];
  1304. intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
  1305. &link_bw, &rate_select);
  1306. DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
  1307. link_bw, rate_select, pipe_config->lane_count,
  1308. pipe_config->port_clock, bpp);
  1309. DRM_DEBUG_KMS("DP link bw required %i available %i\n",
  1310. mode_rate, link_avail);
  1311. intel_link_compute_m_n(bpp, lane_count,
  1312. adjusted_mode->crtc_clock,
  1313. pipe_config->port_clock,
  1314. &pipe_config->dp_m_n);
  1315. if (intel_connector->panel.downclock_mode != NULL &&
  1316. dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
  1317. pipe_config->has_drrs = true;
  1318. intel_link_compute_m_n(bpp, lane_count,
  1319. intel_connector->panel.downclock_mode->clock,
  1320. pipe_config->port_clock,
  1321. &pipe_config->dp_m2_n2);
  1322. }
  1323. if (!HAS_DDI(dev))
  1324. intel_dp_set_clock(encoder, pipe_config);
  1325. return true;
  1326. }
  1327. void intel_dp_set_link_params(struct intel_dp *intel_dp,
  1328. const struct intel_crtc_state *pipe_config)
  1329. {
  1330. intel_dp->link_rate = pipe_config->port_clock;
  1331. intel_dp->lane_count = pipe_config->lane_count;
  1332. }
  1333. static void intel_dp_prepare(struct intel_encoder *encoder)
  1334. {
  1335. struct drm_device *dev = encoder->base.dev;
  1336. struct drm_i915_private *dev_priv = dev->dev_private;
  1337. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1338. enum port port = dp_to_dig_port(intel_dp)->port;
  1339. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  1340. const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
  1341. intel_dp_set_link_params(intel_dp, crtc->config);
  1342. /*
  1343. * There are four kinds of DP registers:
  1344. *
  1345. * IBX PCH
  1346. * SNB CPU
  1347. * IVB CPU
  1348. * CPT PCH
  1349. *
  1350. * IBX PCH and CPU are the same for almost everything,
  1351. * except that the CPU DP PLL is configured in this
  1352. * register
  1353. *
  1354. * CPT PCH is quite different, having many bits moved
  1355. * to the TRANS_DP_CTL register instead. That
  1356. * configuration happens (oddly) in ironlake_pch_enable
  1357. */
  1358. /* Preserve the BIOS-computed detected bit. This is
  1359. * supposed to be read-only.
  1360. */
  1361. intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
  1362. /* Handle DP bits in common between all three register formats */
  1363. intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
  1364. intel_dp->DP |= DP_PORT_WIDTH(crtc->config->lane_count);
  1365. /* Split out the IBX/CPU vs CPT settings */
  1366. if (IS_GEN7(dev) && port == PORT_A) {
  1367. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  1368. intel_dp->DP |= DP_SYNC_HS_HIGH;
  1369. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  1370. intel_dp->DP |= DP_SYNC_VS_HIGH;
  1371. intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
  1372. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1373. intel_dp->DP |= DP_ENHANCED_FRAMING;
  1374. intel_dp->DP |= crtc->pipe << 29;
  1375. } else if (HAS_PCH_CPT(dev) && port != PORT_A) {
  1376. u32 trans_dp;
  1377. intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
  1378. trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
  1379. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1380. trans_dp |= TRANS_DP_ENH_FRAMING;
  1381. else
  1382. trans_dp &= ~TRANS_DP_ENH_FRAMING;
  1383. I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
  1384. } else {
  1385. if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) &&
  1386. !IS_CHERRYVIEW(dev) && crtc->config->limited_color_range)
  1387. intel_dp->DP |= DP_COLOR_RANGE_16_235;
  1388. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  1389. intel_dp->DP |= DP_SYNC_HS_HIGH;
  1390. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  1391. intel_dp->DP |= DP_SYNC_VS_HIGH;
  1392. intel_dp->DP |= DP_LINK_TRAIN_OFF;
  1393. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1394. intel_dp->DP |= DP_ENHANCED_FRAMING;
  1395. if (IS_CHERRYVIEW(dev))
  1396. intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
  1397. else if (crtc->pipe == PIPE_B)
  1398. intel_dp->DP |= DP_PIPEB_SELECT;
  1399. }
  1400. }
  1401. #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
  1402. #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
  1403. #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
  1404. #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
  1405. #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
  1406. #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
  1407. static void wait_panel_status(struct intel_dp *intel_dp,
  1408. u32 mask,
  1409. u32 value)
  1410. {
  1411. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1412. struct drm_i915_private *dev_priv = dev->dev_private;
  1413. i915_reg_t pp_stat_reg, pp_ctrl_reg;
  1414. lockdep_assert_held(&dev_priv->pps_mutex);
  1415. pp_stat_reg = _pp_stat_reg(intel_dp);
  1416. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1417. DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
  1418. mask, value,
  1419. I915_READ(pp_stat_reg),
  1420. I915_READ(pp_ctrl_reg));
  1421. if (_wait_for((I915_READ(pp_stat_reg) & mask) == value,
  1422. 5 * USEC_PER_SEC, 10 * USEC_PER_MSEC))
  1423. DRM_ERROR("Panel status timeout: status %08x control %08x\n",
  1424. I915_READ(pp_stat_reg),
  1425. I915_READ(pp_ctrl_reg));
  1426. DRM_DEBUG_KMS("Wait complete\n");
  1427. }
  1428. static void wait_panel_on(struct intel_dp *intel_dp)
  1429. {
  1430. DRM_DEBUG_KMS("Wait for panel power on\n");
  1431. wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
  1432. }
  1433. static void wait_panel_off(struct intel_dp *intel_dp)
  1434. {
  1435. DRM_DEBUG_KMS("Wait for panel power off time\n");
  1436. wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
  1437. }
  1438. static void wait_panel_power_cycle(struct intel_dp *intel_dp)
  1439. {
  1440. ktime_t panel_power_on_time;
  1441. s64 panel_power_off_duration;
  1442. DRM_DEBUG_KMS("Wait for panel power cycle\n");
  1443. /* take the difference of currrent time and panel power off time
  1444. * and then make panel wait for t11_t12 if needed. */
  1445. panel_power_on_time = ktime_get_boottime();
  1446. panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
  1447. /* When we disable the VDD override bit last we have to do the manual
  1448. * wait. */
  1449. if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
  1450. wait_remaining_ms_from_jiffies(jiffies,
  1451. intel_dp->panel_power_cycle_delay - panel_power_off_duration);
  1452. wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
  1453. }
  1454. static void wait_backlight_on(struct intel_dp *intel_dp)
  1455. {
  1456. wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
  1457. intel_dp->backlight_on_delay);
  1458. }
  1459. static void edp_wait_backlight_off(struct intel_dp *intel_dp)
  1460. {
  1461. wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
  1462. intel_dp->backlight_off_delay);
  1463. }
  1464. /* Read the current pp_control value, unlocking the register if it
  1465. * is locked
  1466. */
  1467. static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
  1468. {
  1469. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1470. struct drm_i915_private *dev_priv = dev->dev_private;
  1471. u32 control;
  1472. lockdep_assert_held(&dev_priv->pps_mutex);
  1473. control = I915_READ(_pp_ctrl_reg(intel_dp));
  1474. if (!IS_BROXTON(dev)) {
  1475. control &= ~PANEL_UNLOCK_MASK;
  1476. control |= PANEL_UNLOCK_REGS;
  1477. }
  1478. return control;
  1479. }
  1480. /*
  1481. * Must be paired with edp_panel_vdd_off().
  1482. * Must hold pps_mutex around the whole on/off sequence.
  1483. * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
  1484. */
  1485. static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
  1486. {
  1487. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1488. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1489. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  1490. struct drm_i915_private *dev_priv = dev->dev_private;
  1491. enum intel_display_power_domain power_domain;
  1492. u32 pp;
  1493. i915_reg_t pp_stat_reg, pp_ctrl_reg;
  1494. bool need_to_disable = !intel_dp->want_panel_vdd;
  1495. lockdep_assert_held(&dev_priv->pps_mutex);
  1496. if (!is_edp(intel_dp))
  1497. return false;
  1498. cancel_delayed_work(&intel_dp->panel_vdd_work);
  1499. intel_dp->want_panel_vdd = true;
  1500. if (edp_have_panel_vdd(intel_dp))
  1501. return need_to_disable;
  1502. power_domain = intel_display_port_aux_power_domain(intel_encoder);
  1503. intel_display_power_get(dev_priv, power_domain);
  1504. DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
  1505. port_name(intel_dig_port->port));
  1506. if (!edp_have_panel_power(intel_dp))
  1507. wait_panel_power_cycle(intel_dp);
  1508. pp = ironlake_get_pp_control(intel_dp);
  1509. pp |= EDP_FORCE_VDD;
  1510. pp_stat_reg = _pp_stat_reg(intel_dp);
  1511. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1512. I915_WRITE(pp_ctrl_reg, pp);
  1513. POSTING_READ(pp_ctrl_reg);
  1514. DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
  1515. I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
  1516. /*
  1517. * If the panel wasn't on, delay before accessing aux channel
  1518. */
  1519. if (!edp_have_panel_power(intel_dp)) {
  1520. DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
  1521. port_name(intel_dig_port->port));
  1522. msleep(intel_dp->panel_power_up_delay);
  1523. }
  1524. return need_to_disable;
  1525. }
  1526. /*
  1527. * Must be paired with intel_edp_panel_vdd_off() or
  1528. * intel_edp_panel_off().
  1529. * Nested calls to these functions are not allowed since
  1530. * we drop the lock. Caller must use some higher level
  1531. * locking to prevent nested calls from other threads.
  1532. */
  1533. void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
  1534. {
  1535. bool vdd;
  1536. if (!is_edp(intel_dp))
  1537. return;
  1538. pps_lock(intel_dp);
  1539. vdd = edp_panel_vdd_on(intel_dp);
  1540. pps_unlock(intel_dp);
  1541. I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
  1542. port_name(dp_to_dig_port(intel_dp)->port));
  1543. }
  1544. static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
  1545. {
  1546. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1547. struct drm_i915_private *dev_priv = dev->dev_private;
  1548. struct intel_digital_port *intel_dig_port =
  1549. dp_to_dig_port(intel_dp);
  1550. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  1551. enum intel_display_power_domain power_domain;
  1552. u32 pp;
  1553. i915_reg_t pp_stat_reg, pp_ctrl_reg;
  1554. lockdep_assert_held(&dev_priv->pps_mutex);
  1555. WARN_ON(intel_dp->want_panel_vdd);
  1556. if (!edp_have_panel_vdd(intel_dp))
  1557. return;
  1558. DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
  1559. port_name(intel_dig_port->port));
  1560. pp = ironlake_get_pp_control(intel_dp);
  1561. pp &= ~EDP_FORCE_VDD;
  1562. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1563. pp_stat_reg = _pp_stat_reg(intel_dp);
  1564. I915_WRITE(pp_ctrl_reg, pp);
  1565. POSTING_READ(pp_ctrl_reg);
  1566. /* Make sure sequencer is idle before allowing subsequent activity */
  1567. DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
  1568. I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
  1569. if ((pp & POWER_TARGET_ON) == 0)
  1570. intel_dp->panel_power_off_time = ktime_get_boottime();
  1571. power_domain = intel_display_port_aux_power_domain(intel_encoder);
  1572. intel_display_power_put(dev_priv, power_domain);
  1573. }
  1574. static void edp_panel_vdd_work(struct work_struct *__work)
  1575. {
  1576. struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
  1577. struct intel_dp, panel_vdd_work);
  1578. pps_lock(intel_dp);
  1579. if (!intel_dp->want_panel_vdd)
  1580. edp_panel_vdd_off_sync(intel_dp);
  1581. pps_unlock(intel_dp);
  1582. }
  1583. static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
  1584. {
  1585. unsigned long delay;
  1586. /*
  1587. * Queue the timer to fire a long time from now (relative to the power
  1588. * down delay) to keep the panel power up across a sequence of
  1589. * operations.
  1590. */
  1591. delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
  1592. schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
  1593. }
  1594. /*
  1595. * Must be paired with edp_panel_vdd_on().
  1596. * Must hold pps_mutex around the whole on/off sequence.
  1597. * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
  1598. */
  1599. static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
  1600. {
  1601. struct drm_i915_private *dev_priv =
  1602. intel_dp_to_dev(intel_dp)->dev_private;
  1603. lockdep_assert_held(&dev_priv->pps_mutex);
  1604. if (!is_edp(intel_dp))
  1605. return;
  1606. I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
  1607. port_name(dp_to_dig_port(intel_dp)->port));
  1608. intel_dp->want_panel_vdd = false;
  1609. if (sync)
  1610. edp_panel_vdd_off_sync(intel_dp);
  1611. else
  1612. edp_panel_vdd_schedule_off(intel_dp);
  1613. }
  1614. static void edp_panel_on(struct intel_dp *intel_dp)
  1615. {
  1616. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1617. struct drm_i915_private *dev_priv = dev->dev_private;
  1618. u32 pp;
  1619. i915_reg_t pp_ctrl_reg;
  1620. lockdep_assert_held(&dev_priv->pps_mutex);
  1621. if (!is_edp(intel_dp))
  1622. return;
  1623. DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
  1624. port_name(dp_to_dig_port(intel_dp)->port));
  1625. if (WARN(edp_have_panel_power(intel_dp),
  1626. "eDP port %c panel power already on\n",
  1627. port_name(dp_to_dig_port(intel_dp)->port)))
  1628. return;
  1629. wait_panel_power_cycle(intel_dp);
  1630. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1631. pp = ironlake_get_pp_control(intel_dp);
  1632. if (IS_GEN5(dev)) {
  1633. /* ILK workaround: disable reset around power sequence */
  1634. pp &= ~PANEL_POWER_RESET;
  1635. I915_WRITE(pp_ctrl_reg, pp);
  1636. POSTING_READ(pp_ctrl_reg);
  1637. }
  1638. pp |= POWER_TARGET_ON;
  1639. if (!IS_GEN5(dev))
  1640. pp |= PANEL_POWER_RESET;
  1641. I915_WRITE(pp_ctrl_reg, pp);
  1642. POSTING_READ(pp_ctrl_reg);
  1643. wait_panel_on(intel_dp);
  1644. intel_dp->last_power_on = jiffies;
  1645. if (IS_GEN5(dev)) {
  1646. pp |= PANEL_POWER_RESET; /* restore panel reset bit */
  1647. I915_WRITE(pp_ctrl_reg, pp);
  1648. POSTING_READ(pp_ctrl_reg);
  1649. }
  1650. }
  1651. void intel_edp_panel_on(struct intel_dp *intel_dp)
  1652. {
  1653. if (!is_edp(intel_dp))
  1654. return;
  1655. pps_lock(intel_dp);
  1656. edp_panel_on(intel_dp);
  1657. pps_unlock(intel_dp);
  1658. }
  1659. static void edp_panel_off(struct intel_dp *intel_dp)
  1660. {
  1661. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1662. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  1663. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1664. struct drm_i915_private *dev_priv = dev->dev_private;
  1665. enum intel_display_power_domain power_domain;
  1666. u32 pp;
  1667. i915_reg_t pp_ctrl_reg;
  1668. lockdep_assert_held(&dev_priv->pps_mutex);
  1669. if (!is_edp(intel_dp))
  1670. return;
  1671. DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
  1672. port_name(dp_to_dig_port(intel_dp)->port));
  1673. WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
  1674. port_name(dp_to_dig_port(intel_dp)->port));
  1675. pp = ironlake_get_pp_control(intel_dp);
  1676. /* We need to switch off panel power _and_ force vdd, for otherwise some
  1677. * panels get very unhappy and cease to work. */
  1678. pp &= ~(POWER_TARGET_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
  1679. EDP_BLC_ENABLE);
  1680. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1681. intel_dp->want_panel_vdd = false;
  1682. I915_WRITE(pp_ctrl_reg, pp);
  1683. POSTING_READ(pp_ctrl_reg);
  1684. intel_dp->panel_power_off_time = ktime_get_boottime();
  1685. wait_panel_off(intel_dp);
  1686. /* We got a reference when we enabled the VDD. */
  1687. power_domain = intel_display_port_aux_power_domain(intel_encoder);
  1688. intel_display_power_put(dev_priv, power_domain);
  1689. }
  1690. void intel_edp_panel_off(struct intel_dp *intel_dp)
  1691. {
  1692. if (!is_edp(intel_dp))
  1693. return;
  1694. pps_lock(intel_dp);
  1695. edp_panel_off(intel_dp);
  1696. pps_unlock(intel_dp);
  1697. }
  1698. /* Enable backlight in the panel power control. */
  1699. static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
  1700. {
  1701. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1702. struct drm_device *dev = intel_dig_port->base.base.dev;
  1703. struct drm_i915_private *dev_priv = dev->dev_private;
  1704. u32 pp;
  1705. i915_reg_t pp_ctrl_reg;
  1706. /*
  1707. * If we enable the backlight right away following a panel power
  1708. * on, we may see slight flicker as the panel syncs with the eDP
  1709. * link. So delay a bit to make sure the image is solid before
  1710. * allowing it to appear.
  1711. */
  1712. wait_backlight_on(intel_dp);
  1713. pps_lock(intel_dp);
  1714. pp = ironlake_get_pp_control(intel_dp);
  1715. pp |= EDP_BLC_ENABLE;
  1716. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1717. I915_WRITE(pp_ctrl_reg, pp);
  1718. POSTING_READ(pp_ctrl_reg);
  1719. pps_unlock(intel_dp);
  1720. }
  1721. /* Enable backlight PWM and backlight PP control. */
  1722. void intel_edp_backlight_on(struct intel_dp *intel_dp)
  1723. {
  1724. if (!is_edp(intel_dp))
  1725. return;
  1726. DRM_DEBUG_KMS("\n");
  1727. intel_panel_enable_backlight(intel_dp->attached_connector);
  1728. _intel_edp_backlight_on(intel_dp);
  1729. }
  1730. /* Disable backlight in the panel power control. */
  1731. static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
  1732. {
  1733. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1734. struct drm_i915_private *dev_priv = dev->dev_private;
  1735. u32 pp;
  1736. i915_reg_t pp_ctrl_reg;
  1737. if (!is_edp(intel_dp))
  1738. return;
  1739. pps_lock(intel_dp);
  1740. pp = ironlake_get_pp_control(intel_dp);
  1741. pp &= ~EDP_BLC_ENABLE;
  1742. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1743. I915_WRITE(pp_ctrl_reg, pp);
  1744. POSTING_READ(pp_ctrl_reg);
  1745. pps_unlock(intel_dp);
  1746. intel_dp->last_backlight_off = jiffies;
  1747. edp_wait_backlight_off(intel_dp);
  1748. }
  1749. /* Disable backlight PP control and backlight PWM. */
  1750. void intel_edp_backlight_off(struct intel_dp *intel_dp)
  1751. {
  1752. if (!is_edp(intel_dp))
  1753. return;
  1754. DRM_DEBUG_KMS("\n");
  1755. _intel_edp_backlight_off(intel_dp);
  1756. intel_panel_disable_backlight(intel_dp->attached_connector);
  1757. }
  1758. /*
  1759. * Hook for controlling the panel power control backlight through the bl_power
  1760. * sysfs attribute. Take care to handle multiple calls.
  1761. */
  1762. static void intel_edp_backlight_power(struct intel_connector *connector,
  1763. bool enable)
  1764. {
  1765. struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
  1766. bool is_enabled;
  1767. pps_lock(intel_dp);
  1768. is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
  1769. pps_unlock(intel_dp);
  1770. if (is_enabled == enable)
  1771. return;
  1772. DRM_DEBUG_KMS("panel power control backlight %s\n",
  1773. enable ? "enable" : "disable");
  1774. if (enable)
  1775. _intel_edp_backlight_on(intel_dp);
  1776. else
  1777. _intel_edp_backlight_off(intel_dp);
  1778. }
  1779. static void assert_dp_port(struct intel_dp *intel_dp, bool state)
  1780. {
  1781. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  1782. struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
  1783. bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
  1784. I915_STATE_WARN(cur_state != state,
  1785. "DP port %c state assertion failure (expected %s, current %s)\n",
  1786. port_name(dig_port->port),
  1787. onoff(state), onoff(cur_state));
  1788. }
  1789. #define assert_dp_port_disabled(d) assert_dp_port((d), false)
  1790. static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
  1791. {
  1792. bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
  1793. I915_STATE_WARN(cur_state != state,
  1794. "eDP PLL state assertion failure (expected %s, current %s)\n",
  1795. onoff(state), onoff(cur_state));
  1796. }
  1797. #define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
  1798. #define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
  1799. static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
  1800. {
  1801. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1802. struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
  1803. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1804. assert_pipe_disabled(dev_priv, crtc->pipe);
  1805. assert_dp_port_disabled(intel_dp);
  1806. assert_edp_pll_disabled(dev_priv);
  1807. DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
  1808. crtc->config->port_clock);
  1809. intel_dp->DP &= ~DP_PLL_FREQ_MASK;
  1810. if (crtc->config->port_clock == 162000)
  1811. intel_dp->DP |= DP_PLL_FREQ_162MHZ;
  1812. else
  1813. intel_dp->DP |= DP_PLL_FREQ_270MHZ;
  1814. I915_WRITE(DP_A, intel_dp->DP);
  1815. POSTING_READ(DP_A);
  1816. udelay(500);
  1817. /*
  1818. * [DevILK] Work around required when enabling DP PLL
  1819. * while a pipe is enabled going to FDI:
  1820. * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
  1821. * 2. Program DP PLL enable
  1822. */
  1823. if (IS_GEN5(dev_priv))
  1824. intel_wait_for_vblank_if_active(dev_priv->dev, !crtc->pipe);
  1825. intel_dp->DP |= DP_PLL_ENABLE;
  1826. I915_WRITE(DP_A, intel_dp->DP);
  1827. POSTING_READ(DP_A);
  1828. udelay(200);
  1829. }
  1830. static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
  1831. {
  1832. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1833. struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
  1834. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1835. assert_pipe_disabled(dev_priv, crtc->pipe);
  1836. assert_dp_port_disabled(intel_dp);
  1837. assert_edp_pll_enabled(dev_priv);
  1838. DRM_DEBUG_KMS("disabling eDP PLL\n");
  1839. intel_dp->DP &= ~DP_PLL_ENABLE;
  1840. I915_WRITE(DP_A, intel_dp->DP);
  1841. POSTING_READ(DP_A);
  1842. udelay(200);
  1843. }
  1844. /* If the sink supports it, try to set the power state appropriately */
  1845. void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
  1846. {
  1847. int ret, i;
  1848. /* Should have a valid DPCD by this point */
  1849. if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
  1850. return;
  1851. if (mode != DRM_MODE_DPMS_ON) {
  1852. ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
  1853. DP_SET_POWER_D3);
  1854. } else {
  1855. /*
  1856. * When turning on, we need to retry for 1ms to give the sink
  1857. * time to wake up.
  1858. */
  1859. for (i = 0; i < 3; i++) {
  1860. ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
  1861. DP_SET_POWER_D0);
  1862. if (ret == 1)
  1863. break;
  1864. msleep(1);
  1865. }
  1866. }
  1867. if (ret != 1)
  1868. DRM_DEBUG_KMS("failed to %s sink power state\n",
  1869. mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
  1870. }
  1871. static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
  1872. enum pipe *pipe)
  1873. {
  1874. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1875. enum port port = dp_to_dig_port(intel_dp)->port;
  1876. struct drm_device *dev = encoder->base.dev;
  1877. struct drm_i915_private *dev_priv = dev->dev_private;
  1878. enum intel_display_power_domain power_domain;
  1879. u32 tmp;
  1880. bool ret;
  1881. power_domain = intel_display_port_power_domain(encoder);
  1882. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  1883. return false;
  1884. ret = false;
  1885. tmp = I915_READ(intel_dp->output_reg);
  1886. if (!(tmp & DP_PORT_EN))
  1887. goto out;
  1888. if (IS_GEN7(dev) && port == PORT_A) {
  1889. *pipe = PORT_TO_PIPE_CPT(tmp);
  1890. } else if (HAS_PCH_CPT(dev) && port != PORT_A) {
  1891. enum pipe p;
  1892. for_each_pipe(dev_priv, p) {
  1893. u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
  1894. if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
  1895. *pipe = p;
  1896. ret = true;
  1897. goto out;
  1898. }
  1899. }
  1900. DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
  1901. i915_mmio_reg_offset(intel_dp->output_reg));
  1902. } else if (IS_CHERRYVIEW(dev)) {
  1903. *pipe = DP_PORT_TO_PIPE_CHV(tmp);
  1904. } else {
  1905. *pipe = PORT_TO_PIPE(tmp);
  1906. }
  1907. ret = true;
  1908. out:
  1909. intel_display_power_put(dev_priv, power_domain);
  1910. return ret;
  1911. }
  1912. static void intel_dp_get_config(struct intel_encoder *encoder,
  1913. struct intel_crtc_state *pipe_config)
  1914. {
  1915. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1916. u32 tmp, flags = 0;
  1917. struct drm_device *dev = encoder->base.dev;
  1918. struct drm_i915_private *dev_priv = dev->dev_private;
  1919. enum port port = dp_to_dig_port(intel_dp)->port;
  1920. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  1921. tmp = I915_READ(intel_dp->output_reg);
  1922. pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
  1923. if (HAS_PCH_CPT(dev) && port != PORT_A) {
  1924. u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
  1925. if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
  1926. flags |= DRM_MODE_FLAG_PHSYNC;
  1927. else
  1928. flags |= DRM_MODE_FLAG_NHSYNC;
  1929. if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
  1930. flags |= DRM_MODE_FLAG_PVSYNC;
  1931. else
  1932. flags |= DRM_MODE_FLAG_NVSYNC;
  1933. } else {
  1934. if (tmp & DP_SYNC_HS_HIGH)
  1935. flags |= DRM_MODE_FLAG_PHSYNC;
  1936. else
  1937. flags |= DRM_MODE_FLAG_NHSYNC;
  1938. if (tmp & DP_SYNC_VS_HIGH)
  1939. flags |= DRM_MODE_FLAG_PVSYNC;
  1940. else
  1941. flags |= DRM_MODE_FLAG_NVSYNC;
  1942. }
  1943. pipe_config->base.adjusted_mode.flags |= flags;
  1944. if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) &&
  1945. !IS_CHERRYVIEW(dev) && tmp & DP_COLOR_RANGE_16_235)
  1946. pipe_config->limited_color_range = true;
  1947. pipe_config->has_dp_encoder = true;
  1948. pipe_config->lane_count =
  1949. ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
  1950. intel_dp_get_m_n(crtc, pipe_config);
  1951. if (port == PORT_A) {
  1952. if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
  1953. pipe_config->port_clock = 162000;
  1954. else
  1955. pipe_config->port_clock = 270000;
  1956. }
  1957. pipe_config->base.adjusted_mode.crtc_clock =
  1958. intel_dotclock_calculate(pipe_config->port_clock,
  1959. &pipe_config->dp_m_n);
  1960. if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
  1961. pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
  1962. /*
  1963. * This is a big fat ugly hack.
  1964. *
  1965. * Some machines in UEFI boot mode provide us a VBT that has 18
  1966. * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
  1967. * unknown we fail to light up. Yet the same BIOS boots up with
  1968. * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
  1969. * max, not what it tells us to use.
  1970. *
  1971. * Note: This will still be broken if the eDP panel is not lit
  1972. * up by the BIOS, and thus we can't get the mode at module
  1973. * load.
  1974. */
  1975. DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
  1976. pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
  1977. dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
  1978. }
  1979. }
  1980. static void intel_disable_dp(struct intel_encoder *encoder)
  1981. {
  1982. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1983. struct drm_device *dev = encoder->base.dev;
  1984. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  1985. if (crtc->config->has_audio)
  1986. intel_audio_codec_disable(encoder);
  1987. if (HAS_PSR(dev) && !HAS_DDI(dev))
  1988. intel_psr_disable(intel_dp);
  1989. /* Make sure the panel is off before trying to change the mode. But also
  1990. * ensure that we have vdd while we switch off the panel. */
  1991. intel_edp_panel_vdd_on(intel_dp);
  1992. intel_edp_backlight_off(intel_dp);
  1993. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
  1994. intel_edp_panel_off(intel_dp);
  1995. /* disable the port before the pipe on g4x */
  1996. if (INTEL_INFO(dev)->gen < 5)
  1997. intel_dp_link_down(intel_dp);
  1998. }
  1999. static void ilk_post_disable_dp(struct intel_encoder *encoder)
  2000. {
  2001. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2002. enum port port = dp_to_dig_port(intel_dp)->port;
  2003. intel_dp_link_down(intel_dp);
  2004. /* Only ilk+ has port A */
  2005. if (port == PORT_A)
  2006. ironlake_edp_pll_off(intel_dp);
  2007. }
  2008. static void vlv_post_disable_dp(struct intel_encoder *encoder)
  2009. {
  2010. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2011. intel_dp_link_down(intel_dp);
  2012. }
  2013. static void chv_post_disable_dp(struct intel_encoder *encoder)
  2014. {
  2015. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2016. struct drm_device *dev = encoder->base.dev;
  2017. struct drm_i915_private *dev_priv = dev->dev_private;
  2018. intel_dp_link_down(intel_dp);
  2019. mutex_lock(&dev_priv->sb_lock);
  2020. /* Assert data lane reset */
  2021. chv_data_lane_soft_reset(encoder, true);
  2022. mutex_unlock(&dev_priv->sb_lock);
  2023. }
  2024. static void
  2025. _intel_dp_set_link_train(struct intel_dp *intel_dp,
  2026. uint32_t *DP,
  2027. uint8_t dp_train_pat)
  2028. {
  2029. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2030. struct drm_device *dev = intel_dig_port->base.base.dev;
  2031. struct drm_i915_private *dev_priv = dev->dev_private;
  2032. enum port port = intel_dig_port->port;
  2033. if (HAS_DDI(dev)) {
  2034. uint32_t temp = I915_READ(DP_TP_CTL(port));
  2035. if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
  2036. temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
  2037. else
  2038. temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
  2039. temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  2040. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2041. case DP_TRAINING_PATTERN_DISABLE:
  2042. temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
  2043. break;
  2044. case DP_TRAINING_PATTERN_1:
  2045. temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
  2046. break;
  2047. case DP_TRAINING_PATTERN_2:
  2048. temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
  2049. break;
  2050. case DP_TRAINING_PATTERN_3:
  2051. temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
  2052. break;
  2053. }
  2054. I915_WRITE(DP_TP_CTL(port), temp);
  2055. } else if ((IS_GEN7(dev) && port == PORT_A) ||
  2056. (HAS_PCH_CPT(dev) && port != PORT_A)) {
  2057. *DP &= ~DP_LINK_TRAIN_MASK_CPT;
  2058. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2059. case DP_TRAINING_PATTERN_DISABLE:
  2060. *DP |= DP_LINK_TRAIN_OFF_CPT;
  2061. break;
  2062. case DP_TRAINING_PATTERN_1:
  2063. *DP |= DP_LINK_TRAIN_PAT_1_CPT;
  2064. break;
  2065. case DP_TRAINING_PATTERN_2:
  2066. *DP |= DP_LINK_TRAIN_PAT_2_CPT;
  2067. break;
  2068. case DP_TRAINING_PATTERN_3:
  2069. DRM_ERROR("DP training pattern 3 not supported\n");
  2070. *DP |= DP_LINK_TRAIN_PAT_2_CPT;
  2071. break;
  2072. }
  2073. } else {
  2074. if (IS_CHERRYVIEW(dev))
  2075. *DP &= ~DP_LINK_TRAIN_MASK_CHV;
  2076. else
  2077. *DP &= ~DP_LINK_TRAIN_MASK;
  2078. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2079. case DP_TRAINING_PATTERN_DISABLE:
  2080. *DP |= DP_LINK_TRAIN_OFF;
  2081. break;
  2082. case DP_TRAINING_PATTERN_1:
  2083. *DP |= DP_LINK_TRAIN_PAT_1;
  2084. break;
  2085. case DP_TRAINING_PATTERN_2:
  2086. *DP |= DP_LINK_TRAIN_PAT_2;
  2087. break;
  2088. case DP_TRAINING_PATTERN_3:
  2089. if (IS_CHERRYVIEW(dev)) {
  2090. *DP |= DP_LINK_TRAIN_PAT_3_CHV;
  2091. } else {
  2092. DRM_ERROR("DP training pattern 3 not supported\n");
  2093. *DP |= DP_LINK_TRAIN_PAT_2;
  2094. }
  2095. break;
  2096. }
  2097. }
  2098. }
  2099. static void intel_dp_enable_port(struct intel_dp *intel_dp)
  2100. {
  2101. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  2102. struct drm_i915_private *dev_priv = dev->dev_private;
  2103. struct intel_crtc *crtc =
  2104. to_intel_crtc(dp_to_dig_port(intel_dp)->base.base.crtc);
  2105. /* enable with pattern 1 (as per spec) */
  2106. _intel_dp_set_link_train(intel_dp, &intel_dp->DP,
  2107. DP_TRAINING_PATTERN_1);
  2108. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2109. POSTING_READ(intel_dp->output_reg);
  2110. /*
  2111. * Magic for VLV/CHV. We _must_ first set up the register
  2112. * without actually enabling the port, and then do another
  2113. * write to enable the port. Otherwise link training will
  2114. * fail when the power sequencer is freshly used for this port.
  2115. */
  2116. intel_dp->DP |= DP_PORT_EN;
  2117. if (crtc->config->has_audio)
  2118. intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
  2119. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2120. POSTING_READ(intel_dp->output_reg);
  2121. }
  2122. static void intel_enable_dp(struct intel_encoder *encoder)
  2123. {
  2124. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2125. struct drm_device *dev = encoder->base.dev;
  2126. struct drm_i915_private *dev_priv = dev->dev_private;
  2127. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  2128. uint32_t dp_reg = I915_READ(intel_dp->output_reg);
  2129. enum pipe pipe = crtc->pipe;
  2130. if (WARN_ON(dp_reg & DP_PORT_EN))
  2131. return;
  2132. pps_lock(intel_dp);
  2133. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
  2134. vlv_init_panel_power_sequencer(intel_dp);
  2135. intel_dp_enable_port(intel_dp);
  2136. edp_panel_vdd_on(intel_dp);
  2137. edp_panel_on(intel_dp);
  2138. edp_panel_vdd_off(intel_dp, true);
  2139. pps_unlock(intel_dp);
  2140. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  2141. unsigned int lane_mask = 0x0;
  2142. if (IS_CHERRYVIEW(dev))
  2143. lane_mask = intel_dp_unused_lane_mask(crtc->config->lane_count);
  2144. vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
  2145. lane_mask);
  2146. }
  2147. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  2148. intel_dp_start_link_train(intel_dp);
  2149. intel_dp_stop_link_train(intel_dp);
  2150. if (crtc->config->has_audio) {
  2151. DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
  2152. pipe_name(pipe));
  2153. intel_audio_codec_enable(encoder);
  2154. }
  2155. }
  2156. static void g4x_enable_dp(struct intel_encoder *encoder)
  2157. {
  2158. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2159. intel_enable_dp(encoder);
  2160. intel_edp_backlight_on(intel_dp);
  2161. }
  2162. static void vlv_enable_dp(struct intel_encoder *encoder)
  2163. {
  2164. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2165. intel_edp_backlight_on(intel_dp);
  2166. intel_psr_enable(intel_dp);
  2167. }
  2168. static void g4x_pre_enable_dp(struct intel_encoder *encoder)
  2169. {
  2170. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2171. enum port port = dp_to_dig_port(intel_dp)->port;
  2172. intel_dp_prepare(encoder);
  2173. /* Only ilk+ has port A */
  2174. if (port == PORT_A)
  2175. ironlake_edp_pll_on(intel_dp);
  2176. }
  2177. static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
  2178. {
  2179. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2180. struct drm_i915_private *dev_priv = intel_dig_port->base.base.dev->dev_private;
  2181. enum pipe pipe = intel_dp->pps_pipe;
  2182. i915_reg_t pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
  2183. edp_panel_vdd_off_sync(intel_dp);
  2184. /*
  2185. * VLV seems to get confused when multiple power seqeuencers
  2186. * have the same port selected (even if only one has power/vdd
  2187. * enabled). The failure manifests as vlv_wait_port_ready() failing
  2188. * CHV on the other hand doesn't seem to mind having the same port
  2189. * selected in multiple power seqeuencers, but let's clear the
  2190. * port select always when logically disconnecting a power sequencer
  2191. * from a port.
  2192. */
  2193. DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
  2194. pipe_name(pipe), port_name(intel_dig_port->port));
  2195. I915_WRITE(pp_on_reg, 0);
  2196. POSTING_READ(pp_on_reg);
  2197. intel_dp->pps_pipe = INVALID_PIPE;
  2198. }
  2199. static void vlv_steal_power_sequencer(struct drm_device *dev,
  2200. enum pipe pipe)
  2201. {
  2202. struct drm_i915_private *dev_priv = dev->dev_private;
  2203. struct intel_encoder *encoder;
  2204. lockdep_assert_held(&dev_priv->pps_mutex);
  2205. if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
  2206. return;
  2207. for_each_intel_encoder(dev, encoder) {
  2208. struct intel_dp *intel_dp;
  2209. enum port port;
  2210. if (encoder->type != INTEL_OUTPUT_EDP)
  2211. continue;
  2212. intel_dp = enc_to_intel_dp(&encoder->base);
  2213. port = dp_to_dig_port(intel_dp)->port;
  2214. if (intel_dp->pps_pipe != pipe)
  2215. continue;
  2216. DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
  2217. pipe_name(pipe), port_name(port));
  2218. WARN(encoder->base.crtc,
  2219. "stealing pipe %c power sequencer from active eDP port %c\n",
  2220. pipe_name(pipe), port_name(port));
  2221. /* make sure vdd is off before we steal it */
  2222. vlv_detach_power_sequencer(intel_dp);
  2223. }
  2224. }
  2225. static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
  2226. {
  2227. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2228. struct intel_encoder *encoder = &intel_dig_port->base;
  2229. struct drm_device *dev = encoder->base.dev;
  2230. struct drm_i915_private *dev_priv = dev->dev_private;
  2231. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  2232. lockdep_assert_held(&dev_priv->pps_mutex);
  2233. if (!is_edp(intel_dp))
  2234. return;
  2235. if (intel_dp->pps_pipe == crtc->pipe)
  2236. return;
  2237. /*
  2238. * If another power sequencer was being used on this
  2239. * port previously make sure to turn off vdd there while
  2240. * we still have control of it.
  2241. */
  2242. if (intel_dp->pps_pipe != INVALID_PIPE)
  2243. vlv_detach_power_sequencer(intel_dp);
  2244. /*
  2245. * We may be stealing the power
  2246. * sequencer from another port.
  2247. */
  2248. vlv_steal_power_sequencer(dev, crtc->pipe);
  2249. /* now it's all ours */
  2250. intel_dp->pps_pipe = crtc->pipe;
  2251. DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
  2252. pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
  2253. /* init power sequencer on this pipe and port */
  2254. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  2255. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
  2256. }
  2257. static void vlv_pre_enable_dp(struct intel_encoder *encoder)
  2258. {
  2259. vlv_phy_pre_encoder_enable(encoder);
  2260. intel_enable_dp(encoder);
  2261. }
  2262. static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder)
  2263. {
  2264. intel_dp_prepare(encoder);
  2265. vlv_phy_pre_pll_enable(encoder);
  2266. }
  2267. static void chv_pre_enable_dp(struct intel_encoder *encoder)
  2268. {
  2269. chv_phy_pre_encoder_enable(encoder);
  2270. intel_enable_dp(encoder);
  2271. /* Second common lane will stay alive on its own now */
  2272. chv_phy_release_cl2_override(encoder);
  2273. }
  2274. static void chv_dp_pre_pll_enable(struct intel_encoder *encoder)
  2275. {
  2276. intel_dp_prepare(encoder);
  2277. chv_phy_pre_pll_enable(encoder);
  2278. }
  2279. static void chv_dp_post_pll_disable(struct intel_encoder *encoder)
  2280. {
  2281. chv_phy_post_pll_disable(encoder);
  2282. }
  2283. /*
  2284. * Fetch AUX CH registers 0x202 - 0x207 which contain
  2285. * link status information
  2286. */
  2287. bool
  2288. intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
  2289. {
  2290. return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
  2291. DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
  2292. }
  2293. /* These are source-specific values. */
  2294. uint8_t
  2295. intel_dp_voltage_max(struct intel_dp *intel_dp)
  2296. {
  2297. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  2298. struct drm_i915_private *dev_priv = dev->dev_private;
  2299. enum port port = dp_to_dig_port(intel_dp)->port;
  2300. if (IS_BROXTON(dev))
  2301. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2302. else if (INTEL_INFO(dev)->gen >= 9) {
  2303. if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
  2304. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2305. return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  2306. } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
  2307. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2308. else if (IS_GEN7(dev) && port == PORT_A)
  2309. return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  2310. else if (HAS_PCH_CPT(dev) && port != PORT_A)
  2311. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2312. else
  2313. return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  2314. }
  2315. uint8_t
  2316. intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
  2317. {
  2318. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  2319. enum port port = dp_to_dig_port(intel_dp)->port;
  2320. if (INTEL_INFO(dev)->gen >= 9) {
  2321. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2322. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2323. return DP_TRAIN_PRE_EMPH_LEVEL_3;
  2324. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2325. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2326. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2327. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2328. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2329. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2330. default:
  2331. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2332. }
  2333. } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2334. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2335. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2336. return DP_TRAIN_PRE_EMPH_LEVEL_3;
  2337. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2338. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2339. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2340. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2341. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2342. default:
  2343. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2344. }
  2345. } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  2346. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2347. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2348. return DP_TRAIN_PRE_EMPH_LEVEL_3;
  2349. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2350. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2351. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2352. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2353. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2354. default:
  2355. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2356. }
  2357. } else if (IS_GEN7(dev) && port == PORT_A) {
  2358. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2359. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2360. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2361. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2362. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2363. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2364. default:
  2365. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2366. }
  2367. } else {
  2368. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2369. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2370. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2371. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2372. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2373. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2374. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2375. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2376. default:
  2377. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2378. }
  2379. }
  2380. }
  2381. static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
  2382. {
  2383. struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
  2384. unsigned long demph_reg_value, preemph_reg_value,
  2385. uniqtranscale_reg_value;
  2386. uint8_t train_set = intel_dp->train_set[0];
  2387. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2388. case DP_TRAIN_PRE_EMPH_LEVEL_0:
  2389. preemph_reg_value = 0x0004000;
  2390. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2391. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2392. demph_reg_value = 0x2B405555;
  2393. uniqtranscale_reg_value = 0x552AB83A;
  2394. break;
  2395. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2396. demph_reg_value = 0x2B404040;
  2397. uniqtranscale_reg_value = 0x5548B83A;
  2398. break;
  2399. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2400. demph_reg_value = 0x2B245555;
  2401. uniqtranscale_reg_value = 0x5560B83A;
  2402. break;
  2403. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2404. demph_reg_value = 0x2B405555;
  2405. uniqtranscale_reg_value = 0x5598DA3A;
  2406. break;
  2407. default:
  2408. return 0;
  2409. }
  2410. break;
  2411. case DP_TRAIN_PRE_EMPH_LEVEL_1:
  2412. preemph_reg_value = 0x0002000;
  2413. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2414. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2415. demph_reg_value = 0x2B404040;
  2416. uniqtranscale_reg_value = 0x5552B83A;
  2417. break;
  2418. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2419. demph_reg_value = 0x2B404848;
  2420. uniqtranscale_reg_value = 0x5580B83A;
  2421. break;
  2422. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2423. demph_reg_value = 0x2B404040;
  2424. uniqtranscale_reg_value = 0x55ADDA3A;
  2425. break;
  2426. default:
  2427. return 0;
  2428. }
  2429. break;
  2430. case DP_TRAIN_PRE_EMPH_LEVEL_2:
  2431. preemph_reg_value = 0x0000000;
  2432. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2433. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2434. demph_reg_value = 0x2B305555;
  2435. uniqtranscale_reg_value = 0x5570B83A;
  2436. break;
  2437. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2438. demph_reg_value = 0x2B2B4040;
  2439. uniqtranscale_reg_value = 0x55ADDA3A;
  2440. break;
  2441. default:
  2442. return 0;
  2443. }
  2444. break;
  2445. case DP_TRAIN_PRE_EMPH_LEVEL_3:
  2446. preemph_reg_value = 0x0006000;
  2447. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2448. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2449. demph_reg_value = 0x1B405555;
  2450. uniqtranscale_reg_value = 0x55ADDA3A;
  2451. break;
  2452. default:
  2453. return 0;
  2454. }
  2455. break;
  2456. default:
  2457. return 0;
  2458. }
  2459. vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
  2460. uniqtranscale_reg_value, 0);
  2461. return 0;
  2462. }
  2463. static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
  2464. {
  2465. struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
  2466. u32 deemph_reg_value, margin_reg_value;
  2467. bool uniq_trans_scale = false;
  2468. uint8_t train_set = intel_dp->train_set[0];
  2469. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2470. case DP_TRAIN_PRE_EMPH_LEVEL_0:
  2471. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2472. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2473. deemph_reg_value = 128;
  2474. margin_reg_value = 52;
  2475. break;
  2476. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2477. deemph_reg_value = 128;
  2478. margin_reg_value = 77;
  2479. break;
  2480. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2481. deemph_reg_value = 128;
  2482. margin_reg_value = 102;
  2483. break;
  2484. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2485. deemph_reg_value = 128;
  2486. margin_reg_value = 154;
  2487. uniq_trans_scale = true;
  2488. break;
  2489. default:
  2490. return 0;
  2491. }
  2492. break;
  2493. case DP_TRAIN_PRE_EMPH_LEVEL_1:
  2494. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2495. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2496. deemph_reg_value = 85;
  2497. margin_reg_value = 78;
  2498. break;
  2499. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2500. deemph_reg_value = 85;
  2501. margin_reg_value = 116;
  2502. break;
  2503. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2504. deemph_reg_value = 85;
  2505. margin_reg_value = 154;
  2506. break;
  2507. default:
  2508. return 0;
  2509. }
  2510. break;
  2511. case DP_TRAIN_PRE_EMPH_LEVEL_2:
  2512. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2513. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2514. deemph_reg_value = 64;
  2515. margin_reg_value = 104;
  2516. break;
  2517. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2518. deemph_reg_value = 64;
  2519. margin_reg_value = 154;
  2520. break;
  2521. default:
  2522. return 0;
  2523. }
  2524. break;
  2525. case DP_TRAIN_PRE_EMPH_LEVEL_3:
  2526. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2527. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2528. deemph_reg_value = 43;
  2529. margin_reg_value = 154;
  2530. break;
  2531. default:
  2532. return 0;
  2533. }
  2534. break;
  2535. default:
  2536. return 0;
  2537. }
  2538. chv_set_phy_signal_level(encoder, deemph_reg_value,
  2539. margin_reg_value, uniq_trans_scale);
  2540. return 0;
  2541. }
  2542. static uint32_t
  2543. gen4_signal_levels(uint8_t train_set)
  2544. {
  2545. uint32_t signal_levels = 0;
  2546. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2547. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2548. default:
  2549. signal_levels |= DP_VOLTAGE_0_4;
  2550. break;
  2551. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2552. signal_levels |= DP_VOLTAGE_0_6;
  2553. break;
  2554. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2555. signal_levels |= DP_VOLTAGE_0_8;
  2556. break;
  2557. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2558. signal_levels |= DP_VOLTAGE_1_2;
  2559. break;
  2560. }
  2561. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2562. case DP_TRAIN_PRE_EMPH_LEVEL_0:
  2563. default:
  2564. signal_levels |= DP_PRE_EMPHASIS_0;
  2565. break;
  2566. case DP_TRAIN_PRE_EMPH_LEVEL_1:
  2567. signal_levels |= DP_PRE_EMPHASIS_3_5;
  2568. break;
  2569. case DP_TRAIN_PRE_EMPH_LEVEL_2:
  2570. signal_levels |= DP_PRE_EMPHASIS_6;
  2571. break;
  2572. case DP_TRAIN_PRE_EMPH_LEVEL_3:
  2573. signal_levels |= DP_PRE_EMPHASIS_9_5;
  2574. break;
  2575. }
  2576. return signal_levels;
  2577. }
  2578. /* Gen6's DP voltage swing and pre-emphasis control */
  2579. static uint32_t
  2580. gen6_edp_signal_levels(uint8_t train_set)
  2581. {
  2582. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  2583. DP_TRAIN_PRE_EMPHASIS_MASK);
  2584. switch (signal_levels) {
  2585. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2586. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2587. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  2588. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2589. return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
  2590. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  2591. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  2592. return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
  2593. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2594. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2595. return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
  2596. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2597. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2598. return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
  2599. default:
  2600. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  2601. "0x%x\n", signal_levels);
  2602. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  2603. }
  2604. }
  2605. /* Gen7's DP voltage swing and pre-emphasis control */
  2606. static uint32_t
  2607. gen7_edp_signal_levels(uint8_t train_set)
  2608. {
  2609. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  2610. DP_TRAIN_PRE_EMPHASIS_MASK);
  2611. switch (signal_levels) {
  2612. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2613. return EDP_LINK_TRAIN_400MV_0DB_IVB;
  2614. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2615. return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
  2616. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  2617. return EDP_LINK_TRAIN_400MV_6DB_IVB;
  2618. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2619. return EDP_LINK_TRAIN_600MV_0DB_IVB;
  2620. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2621. return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
  2622. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2623. return EDP_LINK_TRAIN_800MV_0DB_IVB;
  2624. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2625. return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
  2626. default:
  2627. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  2628. "0x%x\n", signal_levels);
  2629. return EDP_LINK_TRAIN_500MV_0DB_IVB;
  2630. }
  2631. }
  2632. void
  2633. intel_dp_set_signal_levels(struct intel_dp *intel_dp)
  2634. {
  2635. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2636. enum port port = intel_dig_port->port;
  2637. struct drm_device *dev = intel_dig_port->base.base.dev;
  2638. struct drm_i915_private *dev_priv = to_i915(dev);
  2639. uint32_t signal_levels, mask = 0;
  2640. uint8_t train_set = intel_dp->train_set[0];
  2641. if (HAS_DDI(dev)) {
  2642. signal_levels = ddi_signal_levels(intel_dp);
  2643. if (IS_BROXTON(dev))
  2644. signal_levels = 0;
  2645. else
  2646. mask = DDI_BUF_EMP_MASK;
  2647. } else if (IS_CHERRYVIEW(dev)) {
  2648. signal_levels = chv_signal_levels(intel_dp);
  2649. } else if (IS_VALLEYVIEW(dev)) {
  2650. signal_levels = vlv_signal_levels(intel_dp);
  2651. } else if (IS_GEN7(dev) && port == PORT_A) {
  2652. signal_levels = gen7_edp_signal_levels(train_set);
  2653. mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
  2654. } else if (IS_GEN6(dev) && port == PORT_A) {
  2655. signal_levels = gen6_edp_signal_levels(train_set);
  2656. mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
  2657. } else {
  2658. signal_levels = gen4_signal_levels(train_set);
  2659. mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
  2660. }
  2661. if (mask)
  2662. DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
  2663. DRM_DEBUG_KMS("Using vswing level %d\n",
  2664. train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
  2665. DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
  2666. (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
  2667. DP_TRAIN_PRE_EMPHASIS_SHIFT);
  2668. intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
  2669. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2670. POSTING_READ(intel_dp->output_reg);
  2671. }
  2672. void
  2673. intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
  2674. uint8_t dp_train_pat)
  2675. {
  2676. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2677. struct drm_i915_private *dev_priv =
  2678. to_i915(intel_dig_port->base.base.dev);
  2679. _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
  2680. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2681. POSTING_READ(intel_dp->output_reg);
  2682. }
  2683. void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
  2684. {
  2685. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2686. struct drm_device *dev = intel_dig_port->base.base.dev;
  2687. struct drm_i915_private *dev_priv = dev->dev_private;
  2688. enum port port = intel_dig_port->port;
  2689. uint32_t val;
  2690. if (!HAS_DDI(dev))
  2691. return;
  2692. val = I915_READ(DP_TP_CTL(port));
  2693. val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  2694. val |= DP_TP_CTL_LINK_TRAIN_IDLE;
  2695. I915_WRITE(DP_TP_CTL(port), val);
  2696. /*
  2697. * On PORT_A we can have only eDP in SST mode. There the only reason
  2698. * we need to set idle transmission mode is to work around a HW issue
  2699. * where we enable the pipe while not in idle link-training mode.
  2700. * In this case there is requirement to wait for a minimum number of
  2701. * idle patterns to be sent.
  2702. */
  2703. if (port == PORT_A)
  2704. return;
  2705. if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_IDLE_DONE),
  2706. 1))
  2707. DRM_ERROR("Timed out waiting for DP idle patterns\n");
  2708. }
  2709. static void
  2710. intel_dp_link_down(struct intel_dp *intel_dp)
  2711. {
  2712. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2713. struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
  2714. enum port port = intel_dig_port->port;
  2715. struct drm_device *dev = intel_dig_port->base.base.dev;
  2716. struct drm_i915_private *dev_priv = dev->dev_private;
  2717. uint32_t DP = intel_dp->DP;
  2718. if (WARN_ON(HAS_DDI(dev)))
  2719. return;
  2720. if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
  2721. return;
  2722. DRM_DEBUG_KMS("\n");
  2723. if ((IS_GEN7(dev) && port == PORT_A) ||
  2724. (HAS_PCH_CPT(dev) && port != PORT_A)) {
  2725. DP &= ~DP_LINK_TRAIN_MASK_CPT;
  2726. DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
  2727. } else {
  2728. if (IS_CHERRYVIEW(dev))
  2729. DP &= ~DP_LINK_TRAIN_MASK_CHV;
  2730. else
  2731. DP &= ~DP_LINK_TRAIN_MASK;
  2732. DP |= DP_LINK_TRAIN_PAT_IDLE;
  2733. }
  2734. I915_WRITE(intel_dp->output_reg, DP);
  2735. POSTING_READ(intel_dp->output_reg);
  2736. DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
  2737. I915_WRITE(intel_dp->output_reg, DP);
  2738. POSTING_READ(intel_dp->output_reg);
  2739. /*
  2740. * HW workaround for IBX, we need to move the port
  2741. * to transcoder A after disabling it to allow the
  2742. * matching HDMI port to be enabled on transcoder A.
  2743. */
  2744. if (HAS_PCH_IBX(dev) && crtc->pipe == PIPE_B && port != PORT_A) {
  2745. /*
  2746. * We get CPU/PCH FIFO underruns on the other pipe when
  2747. * doing the workaround. Sweep them under the rug.
  2748. */
  2749. intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
  2750. intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
  2751. /* always enable with pattern 1 (as per spec) */
  2752. DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
  2753. DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
  2754. I915_WRITE(intel_dp->output_reg, DP);
  2755. POSTING_READ(intel_dp->output_reg);
  2756. DP &= ~DP_PORT_EN;
  2757. I915_WRITE(intel_dp->output_reg, DP);
  2758. POSTING_READ(intel_dp->output_reg);
  2759. intel_wait_for_vblank_if_active(dev_priv->dev, PIPE_A);
  2760. intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
  2761. intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
  2762. }
  2763. msleep(intel_dp->panel_power_down_delay);
  2764. intel_dp->DP = DP;
  2765. }
  2766. static bool
  2767. intel_dp_get_dpcd(struct intel_dp *intel_dp)
  2768. {
  2769. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  2770. struct drm_device *dev = dig_port->base.base.dev;
  2771. struct drm_i915_private *dev_priv = dev->dev_private;
  2772. if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
  2773. sizeof(intel_dp->dpcd)) < 0)
  2774. return false; /* aux transfer failed */
  2775. DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
  2776. if (intel_dp->dpcd[DP_DPCD_REV] == 0)
  2777. return false; /* DPCD not present */
  2778. if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
  2779. &intel_dp->sink_count, 1) < 0)
  2780. return false;
  2781. /*
  2782. * Sink count can change between short pulse hpd hence
  2783. * a member variable in intel_dp will track any changes
  2784. * between short pulse interrupts.
  2785. */
  2786. intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
  2787. /*
  2788. * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
  2789. * a dongle is present but no display. Unless we require to know
  2790. * if a dongle is present or not, we don't need to update
  2791. * downstream port information. So, an early return here saves
  2792. * time from performing other operations which are not required.
  2793. */
  2794. if (!is_edp(intel_dp) && !intel_dp->sink_count)
  2795. return false;
  2796. /* Check if the panel supports PSR */
  2797. memset(intel_dp->psr_dpcd, 0, sizeof(intel_dp->psr_dpcd));
  2798. if (is_edp(intel_dp)) {
  2799. drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
  2800. intel_dp->psr_dpcd,
  2801. sizeof(intel_dp->psr_dpcd));
  2802. if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
  2803. dev_priv->psr.sink_support = true;
  2804. DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
  2805. }
  2806. if (INTEL_INFO(dev)->gen >= 9 &&
  2807. (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
  2808. uint8_t frame_sync_cap;
  2809. dev_priv->psr.sink_support = true;
  2810. drm_dp_dpcd_read(&intel_dp->aux,
  2811. DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
  2812. &frame_sync_cap, 1);
  2813. dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
  2814. /* PSR2 needs frame sync as well */
  2815. dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
  2816. DRM_DEBUG_KMS("PSR2 %s on sink",
  2817. dev_priv->psr.psr2_support ? "supported" : "not supported");
  2818. }
  2819. /* Read the eDP Display control capabilities registers */
  2820. memset(intel_dp->edp_dpcd, 0, sizeof(intel_dp->edp_dpcd));
  2821. if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
  2822. (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
  2823. intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
  2824. sizeof(intel_dp->edp_dpcd)))
  2825. DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
  2826. intel_dp->edp_dpcd);
  2827. }
  2828. DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
  2829. yesno(intel_dp_source_supports_hbr2(intel_dp)),
  2830. yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
  2831. /* Intermediate frequency support */
  2832. if (is_edp(intel_dp) && (intel_dp->edp_dpcd[0] >= 0x03)) { /* eDp v1.4 or higher */
  2833. __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
  2834. int i;
  2835. drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
  2836. sink_rates, sizeof(sink_rates));
  2837. for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
  2838. int val = le16_to_cpu(sink_rates[i]);
  2839. if (val == 0)
  2840. break;
  2841. /* Value read is in kHz while drm clock is saved in deca-kHz */
  2842. intel_dp->sink_rates[i] = (val * 200) / 10;
  2843. }
  2844. intel_dp->num_sink_rates = i;
  2845. }
  2846. intel_dp_print_rates(intel_dp);
  2847. if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  2848. DP_DWN_STRM_PORT_PRESENT))
  2849. return true; /* native DP sink */
  2850. if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
  2851. return true; /* no per-port downstream info */
  2852. if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
  2853. intel_dp->downstream_ports,
  2854. DP_MAX_DOWNSTREAM_PORTS) < 0)
  2855. return false; /* downstream port status fetch failed */
  2856. return true;
  2857. }
  2858. static void
  2859. intel_dp_probe_oui(struct intel_dp *intel_dp)
  2860. {
  2861. u8 buf[3];
  2862. if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
  2863. return;
  2864. if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_OUI, buf, 3) == 3)
  2865. DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
  2866. buf[0], buf[1], buf[2]);
  2867. if (drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_OUI, buf, 3) == 3)
  2868. DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
  2869. buf[0], buf[1], buf[2]);
  2870. }
  2871. static bool
  2872. intel_dp_probe_mst(struct intel_dp *intel_dp)
  2873. {
  2874. u8 buf[1];
  2875. if (!i915.enable_dp_mst)
  2876. return false;
  2877. if (!intel_dp->can_mst)
  2878. return false;
  2879. if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
  2880. return false;
  2881. if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1)) {
  2882. if (buf[0] & DP_MST_CAP) {
  2883. DRM_DEBUG_KMS("Sink is MST capable\n");
  2884. intel_dp->is_mst = true;
  2885. } else {
  2886. DRM_DEBUG_KMS("Sink is not MST capable\n");
  2887. intel_dp->is_mst = false;
  2888. }
  2889. }
  2890. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
  2891. return intel_dp->is_mst;
  2892. }
  2893. static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
  2894. {
  2895. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  2896. struct drm_device *dev = dig_port->base.base.dev;
  2897. struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
  2898. u8 buf;
  2899. int ret = 0;
  2900. int count = 0;
  2901. int attempts = 10;
  2902. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
  2903. DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
  2904. ret = -EIO;
  2905. goto out;
  2906. }
  2907. if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
  2908. buf & ~DP_TEST_SINK_START) < 0) {
  2909. DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
  2910. ret = -EIO;
  2911. goto out;
  2912. }
  2913. do {
  2914. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2915. if (drm_dp_dpcd_readb(&intel_dp->aux,
  2916. DP_TEST_SINK_MISC, &buf) < 0) {
  2917. ret = -EIO;
  2918. goto out;
  2919. }
  2920. count = buf & DP_TEST_COUNT_MASK;
  2921. } while (--attempts && count);
  2922. if (attempts == 0) {
  2923. DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
  2924. ret = -ETIMEDOUT;
  2925. }
  2926. out:
  2927. hsw_enable_ips(intel_crtc);
  2928. return ret;
  2929. }
  2930. static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
  2931. {
  2932. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  2933. struct drm_device *dev = dig_port->base.base.dev;
  2934. struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
  2935. u8 buf;
  2936. int ret;
  2937. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
  2938. return -EIO;
  2939. if (!(buf & DP_TEST_CRC_SUPPORTED))
  2940. return -ENOTTY;
  2941. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
  2942. return -EIO;
  2943. if (buf & DP_TEST_SINK_START) {
  2944. ret = intel_dp_sink_crc_stop(intel_dp);
  2945. if (ret)
  2946. return ret;
  2947. }
  2948. hsw_disable_ips(intel_crtc);
  2949. if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
  2950. buf | DP_TEST_SINK_START) < 0) {
  2951. hsw_enable_ips(intel_crtc);
  2952. return -EIO;
  2953. }
  2954. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2955. return 0;
  2956. }
  2957. int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
  2958. {
  2959. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  2960. struct drm_device *dev = dig_port->base.base.dev;
  2961. struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
  2962. u8 buf;
  2963. int count, ret;
  2964. int attempts = 6;
  2965. ret = intel_dp_sink_crc_start(intel_dp);
  2966. if (ret)
  2967. return ret;
  2968. do {
  2969. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2970. if (drm_dp_dpcd_readb(&intel_dp->aux,
  2971. DP_TEST_SINK_MISC, &buf) < 0) {
  2972. ret = -EIO;
  2973. goto stop;
  2974. }
  2975. count = buf & DP_TEST_COUNT_MASK;
  2976. } while (--attempts && count == 0);
  2977. if (attempts == 0) {
  2978. DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
  2979. ret = -ETIMEDOUT;
  2980. goto stop;
  2981. }
  2982. if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
  2983. ret = -EIO;
  2984. goto stop;
  2985. }
  2986. stop:
  2987. intel_dp_sink_crc_stop(intel_dp);
  2988. return ret;
  2989. }
  2990. static bool
  2991. intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
  2992. {
  2993. return drm_dp_dpcd_read(&intel_dp->aux,
  2994. DP_DEVICE_SERVICE_IRQ_VECTOR,
  2995. sink_irq_vector, 1) == 1;
  2996. }
  2997. static bool
  2998. intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
  2999. {
  3000. int ret;
  3001. ret = drm_dp_dpcd_read(&intel_dp->aux,
  3002. DP_SINK_COUNT_ESI,
  3003. sink_irq_vector, 14);
  3004. if (ret != 14)
  3005. return false;
  3006. return true;
  3007. }
  3008. static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
  3009. {
  3010. uint8_t test_result = DP_TEST_ACK;
  3011. return test_result;
  3012. }
  3013. static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
  3014. {
  3015. uint8_t test_result = DP_TEST_NAK;
  3016. return test_result;
  3017. }
  3018. static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
  3019. {
  3020. uint8_t test_result = DP_TEST_NAK;
  3021. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3022. struct drm_connector *connector = &intel_connector->base;
  3023. if (intel_connector->detect_edid == NULL ||
  3024. connector->edid_corrupt ||
  3025. intel_dp->aux.i2c_defer_count > 6) {
  3026. /* Check EDID read for NACKs, DEFERs and corruption
  3027. * (DP CTS 1.2 Core r1.1)
  3028. * 4.2.2.4 : Failed EDID read, I2C_NAK
  3029. * 4.2.2.5 : Failed EDID read, I2C_DEFER
  3030. * 4.2.2.6 : EDID corruption detected
  3031. * Use failsafe mode for all cases
  3032. */
  3033. if (intel_dp->aux.i2c_nack_count > 0 ||
  3034. intel_dp->aux.i2c_defer_count > 0)
  3035. DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
  3036. intel_dp->aux.i2c_nack_count,
  3037. intel_dp->aux.i2c_defer_count);
  3038. intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_FAILSAFE;
  3039. } else {
  3040. struct edid *block = intel_connector->detect_edid;
  3041. /* We have to write the checksum
  3042. * of the last block read
  3043. */
  3044. block += intel_connector->detect_edid->extensions;
  3045. if (!drm_dp_dpcd_write(&intel_dp->aux,
  3046. DP_TEST_EDID_CHECKSUM,
  3047. &block->checksum,
  3048. 1))
  3049. DRM_DEBUG_KMS("Failed to write EDID checksum\n");
  3050. test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
  3051. intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_STANDARD;
  3052. }
  3053. /* Set test active flag here so userspace doesn't interrupt things */
  3054. intel_dp->compliance_test_active = 1;
  3055. return test_result;
  3056. }
  3057. static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
  3058. {
  3059. uint8_t test_result = DP_TEST_NAK;
  3060. return test_result;
  3061. }
  3062. static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
  3063. {
  3064. uint8_t response = DP_TEST_NAK;
  3065. uint8_t rxdata = 0;
  3066. int status = 0;
  3067. status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
  3068. if (status <= 0) {
  3069. DRM_DEBUG_KMS("Could not read test request from sink\n");
  3070. goto update_status;
  3071. }
  3072. switch (rxdata) {
  3073. case DP_TEST_LINK_TRAINING:
  3074. DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
  3075. intel_dp->compliance_test_type = DP_TEST_LINK_TRAINING;
  3076. response = intel_dp_autotest_link_training(intel_dp);
  3077. break;
  3078. case DP_TEST_LINK_VIDEO_PATTERN:
  3079. DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
  3080. intel_dp->compliance_test_type = DP_TEST_LINK_VIDEO_PATTERN;
  3081. response = intel_dp_autotest_video_pattern(intel_dp);
  3082. break;
  3083. case DP_TEST_LINK_EDID_READ:
  3084. DRM_DEBUG_KMS("EDID test requested\n");
  3085. intel_dp->compliance_test_type = DP_TEST_LINK_EDID_READ;
  3086. response = intel_dp_autotest_edid(intel_dp);
  3087. break;
  3088. case DP_TEST_LINK_PHY_TEST_PATTERN:
  3089. DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
  3090. intel_dp->compliance_test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
  3091. response = intel_dp_autotest_phy_pattern(intel_dp);
  3092. break;
  3093. default:
  3094. DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
  3095. break;
  3096. }
  3097. update_status:
  3098. status = drm_dp_dpcd_write(&intel_dp->aux,
  3099. DP_TEST_RESPONSE,
  3100. &response, 1);
  3101. if (status <= 0)
  3102. DRM_DEBUG_KMS("Could not write test response to sink\n");
  3103. }
  3104. static int
  3105. intel_dp_check_mst_status(struct intel_dp *intel_dp)
  3106. {
  3107. bool bret;
  3108. if (intel_dp->is_mst) {
  3109. u8 esi[16] = { 0 };
  3110. int ret = 0;
  3111. int retry;
  3112. bool handled;
  3113. bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
  3114. go_again:
  3115. if (bret == true) {
  3116. /* check link status - esi[10] = 0x200c */
  3117. if (intel_dp->active_mst_links &&
  3118. !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
  3119. DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
  3120. intel_dp_start_link_train(intel_dp);
  3121. intel_dp_stop_link_train(intel_dp);
  3122. }
  3123. DRM_DEBUG_KMS("got esi %3ph\n", esi);
  3124. ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
  3125. if (handled) {
  3126. for (retry = 0; retry < 3; retry++) {
  3127. int wret;
  3128. wret = drm_dp_dpcd_write(&intel_dp->aux,
  3129. DP_SINK_COUNT_ESI+1,
  3130. &esi[1], 3);
  3131. if (wret == 3) {
  3132. break;
  3133. }
  3134. }
  3135. bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
  3136. if (bret == true) {
  3137. DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
  3138. goto go_again;
  3139. }
  3140. } else
  3141. ret = 0;
  3142. return ret;
  3143. } else {
  3144. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3145. DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
  3146. intel_dp->is_mst = false;
  3147. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
  3148. /* send a hotplug event */
  3149. drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
  3150. }
  3151. }
  3152. return -EINVAL;
  3153. }
  3154. static void
  3155. intel_dp_check_link_status(struct intel_dp *intel_dp)
  3156. {
  3157. struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
  3158. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3159. u8 link_status[DP_LINK_STATUS_SIZE];
  3160. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  3161. if (!intel_dp_get_link_status(intel_dp, link_status)) {
  3162. DRM_ERROR("Failed to get link status\n");
  3163. return;
  3164. }
  3165. if (!intel_encoder->base.crtc)
  3166. return;
  3167. if (!to_intel_crtc(intel_encoder->base.crtc)->active)
  3168. return;
  3169. /* if link training is requested we should perform it always */
  3170. if ((intel_dp->compliance_test_type == DP_TEST_LINK_TRAINING) ||
  3171. (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
  3172. DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
  3173. intel_encoder->base.name);
  3174. intel_dp_start_link_train(intel_dp);
  3175. intel_dp_stop_link_train(intel_dp);
  3176. }
  3177. }
  3178. /*
  3179. * According to DP spec
  3180. * 5.1.2:
  3181. * 1. Read DPCD
  3182. * 2. Configure link according to Receiver Capabilities
  3183. * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
  3184. * 4. Check link status on receipt of hot-plug interrupt
  3185. *
  3186. * intel_dp_short_pulse - handles short pulse interrupts
  3187. * when full detection is not required.
  3188. * Returns %true if short pulse is handled and full detection
  3189. * is NOT required and %false otherwise.
  3190. */
  3191. static bool
  3192. intel_dp_short_pulse(struct intel_dp *intel_dp)
  3193. {
  3194. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3195. u8 sink_irq_vector;
  3196. u8 old_sink_count = intel_dp->sink_count;
  3197. bool ret;
  3198. /*
  3199. * Clearing compliance test variables to allow capturing
  3200. * of values for next automated test request.
  3201. */
  3202. intel_dp->compliance_test_active = 0;
  3203. intel_dp->compliance_test_type = 0;
  3204. intel_dp->compliance_test_data = 0;
  3205. /*
  3206. * Now read the DPCD to see if it's actually running
  3207. * If the current value of sink count doesn't match with
  3208. * the value that was stored earlier or dpcd read failed
  3209. * we need to do full detection
  3210. */
  3211. ret = intel_dp_get_dpcd(intel_dp);
  3212. if ((old_sink_count != intel_dp->sink_count) || !ret) {
  3213. /* No need to proceed if we are going to do full detect */
  3214. return false;
  3215. }
  3216. /* Try to read the source of the interrupt */
  3217. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3218. intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
  3219. /* Clear interrupt source */
  3220. drm_dp_dpcd_writeb(&intel_dp->aux,
  3221. DP_DEVICE_SERVICE_IRQ_VECTOR,
  3222. sink_irq_vector);
  3223. if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
  3224. DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
  3225. if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
  3226. DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
  3227. }
  3228. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  3229. intel_dp_check_link_status(intel_dp);
  3230. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  3231. return true;
  3232. }
  3233. /* XXX this is probably wrong for multiple downstream ports */
  3234. static enum drm_connector_status
  3235. intel_dp_detect_dpcd(struct intel_dp *intel_dp)
  3236. {
  3237. uint8_t *dpcd = intel_dp->dpcd;
  3238. uint8_t type;
  3239. if (!intel_dp_get_dpcd(intel_dp))
  3240. return connector_status_disconnected;
  3241. if (is_edp(intel_dp))
  3242. return connector_status_connected;
  3243. /* if there's no downstream port, we're done */
  3244. if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
  3245. return connector_status_connected;
  3246. /* If we're HPD-aware, SINK_COUNT changes dynamically */
  3247. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3248. intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
  3249. return intel_dp->sink_count ?
  3250. connector_status_connected : connector_status_disconnected;
  3251. }
  3252. /* If no HPD, poke DDC gently */
  3253. if (drm_probe_ddc(&intel_dp->aux.ddc))
  3254. return connector_status_connected;
  3255. /* Well we tried, say unknown for unreliable port types */
  3256. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
  3257. type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
  3258. if (type == DP_DS_PORT_TYPE_VGA ||
  3259. type == DP_DS_PORT_TYPE_NON_EDID)
  3260. return connector_status_unknown;
  3261. } else {
  3262. type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  3263. DP_DWN_STRM_PORT_TYPE_MASK;
  3264. if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
  3265. type == DP_DWN_STRM_PORT_TYPE_OTHER)
  3266. return connector_status_unknown;
  3267. }
  3268. /* Anything else is out of spec, warn and ignore */
  3269. DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
  3270. return connector_status_disconnected;
  3271. }
  3272. static enum drm_connector_status
  3273. edp_detect(struct intel_dp *intel_dp)
  3274. {
  3275. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3276. enum drm_connector_status status;
  3277. status = intel_panel_detect(dev);
  3278. if (status == connector_status_unknown)
  3279. status = connector_status_connected;
  3280. return status;
  3281. }
  3282. static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  3283. struct intel_digital_port *port)
  3284. {
  3285. u32 bit;
  3286. switch (port->port) {
  3287. case PORT_A:
  3288. return true;
  3289. case PORT_B:
  3290. bit = SDE_PORTB_HOTPLUG;
  3291. break;
  3292. case PORT_C:
  3293. bit = SDE_PORTC_HOTPLUG;
  3294. break;
  3295. case PORT_D:
  3296. bit = SDE_PORTD_HOTPLUG;
  3297. break;
  3298. default:
  3299. MISSING_CASE(port->port);
  3300. return false;
  3301. }
  3302. return I915_READ(SDEISR) & bit;
  3303. }
  3304. static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
  3305. struct intel_digital_port *port)
  3306. {
  3307. u32 bit;
  3308. switch (port->port) {
  3309. case PORT_A:
  3310. return true;
  3311. case PORT_B:
  3312. bit = SDE_PORTB_HOTPLUG_CPT;
  3313. break;
  3314. case PORT_C:
  3315. bit = SDE_PORTC_HOTPLUG_CPT;
  3316. break;
  3317. case PORT_D:
  3318. bit = SDE_PORTD_HOTPLUG_CPT;
  3319. break;
  3320. case PORT_E:
  3321. bit = SDE_PORTE_HOTPLUG_SPT;
  3322. break;
  3323. default:
  3324. MISSING_CASE(port->port);
  3325. return false;
  3326. }
  3327. return I915_READ(SDEISR) & bit;
  3328. }
  3329. static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
  3330. struct intel_digital_port *port)
  3331. {
  3332. u32 bit;
  3333. switch (port->port) {
  3334. case PORT_B:
  3335. bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
  3336. break;
  3337. case PORT_C:
  3338. bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
  3339. break;
  3340. case PORT_D:
  3341. bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
  3342. break;
  3343. default:
  3344. MISSING_CASE(port->port);
  3345. return false;
  3346. }
  3347. return I915_READ(PORT_HOTPLUG_STAT) & bit;
  3348. }
  3349. static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
  3350. struct intel_digital_port *port)
  3351. {
  3352. u32 bit;
  3353. switch (port->port) {
  3354. case PORT_B:
  3355. bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
  3356. break;
  3357. case PORT_C:
  3358. bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
  3359. break;
  3360. case PORT_D:
  3361. bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
  3362. break;
  3363. default:
  3364. MISSING_CASE(port->port);
  3365. return false;
  3366. }
  3367. return I915_READ(PORT_HOTPLUG_STAT) & bit;
  3368. }
  3369. static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
  3370. struct intel_digital_port *intel_dig_port)
  3371. {
  3372. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3373. enum port port;
  3374. u32 bit;
  3375. intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
  3376. switch (port) {
  3377. case PORT_A:
  3378. bit = BXT_DE_PORT_HP_DDIA;
  3379. break;
  3380. case PORT_B:
  3381. bit = BXT_DE_PORT_HP_DDIB;
  3382. break;
  3383. case PORT_C:
  3384. bit = BXT_DE_PORT_HP_DDIC;
  3385. break;
  3386. default:
  3387. MISSING_CASE(port);
  3388. return false;
  3389. }
  3390. return I915_READ(GEN8_DE_PORT_ISR) & bit;
  3391. }
  3392. /*
  3393. * intel_digital_port_connected - is the specified port connected?
  3394. * @dev_priv: i915 private structure
  3395. * @port: the port to test
  3396. *
  3397. * Return %true if @port is connected, %false otherwise.
  3398. */
  3399. bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
  3400. struct intel_digital_port *port)
  3401. {
  3402. if (HAS_PCH_IBX(dev_priv))
  3403. return ibx_digital_port_connected(dev_priv, port);
  3404. else if (HAS_PCH_SPLIT(dev_priv))
  3405. return cpt_digital_port_connected(dev_priv, port);
  3406. else if (IS_BROXTON(dev_priv))
  3407. return bxt_digital_port_connected(dev_priv, port);
  3408. else if (IS_GM45(dev_priv))
  3409. return gm45_digital_port_connected(dev_priv, port);
  3410. else
  3411. return g4x_digital_port_connected(dev_priv, port);
  3412. }
  3413. static struct edid *
  3414. intel_dp_get_edid(struct intel_dp *intel_dp)
  3415. {
  3416. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3417. /* use cached edid if we have one */
  3418. if (intel_connector->edid) {
  3419. /* invalid edid */
  3420. if (IS_ERR(intel_connector->edid))
  3421. return NULL;
  3422. return drm_edid_duplicate(intel_connector->edid);
  3423. } else
  3424. return drm_get_edid(&intel_connector->base,
  3425. &intel_dp->aux.ddc);
  3426. }
  3427. static void
  3428. intel_dp_set_edid(struct intel_dp *intel_dp)
  3429. {
  3430. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3431. struct edid *edid;
  3432. intel_dp_unset_edid(intel_dp);
  3433. edid = intel_dp_get_edid(intel_dp);
  3434. intel_connector->detect_edid = edid;
  3435. if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
  3436. intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
  3437. else
  3438. intel_dp->has_audio = drm_detect_monitor_audio(edid);
  3439. }
  3440. static void
  3441. intel_dp_unset_edid(struct intel_dp *intel_dp)
  3442. {
  3443. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3444. kfree(intel_connector->detect_edid);
  3445. intel_connector->detect_edid = NULL;
  3446. intel_dp->has_audio = false;
  3447. }
  3448. static void
  3449. intel_dp_long_pulse(struct intel_connector *intel_connector)
  3450. {
  3451. struct drm_connector *connector = &intel_connector->base;
  3452. struct intel_dp *intel_dp = intel_attached_dp(connector);
  3453. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3454. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3455. struct drm_device *dev = connector->dev;
  3456. enum drm_connector_status status;
  3457. enum intel_display_power_domain power_domain;
  3458. bool ret;
  3459. u8 sink_irq_vector;
  3460. power_domain = intel_display_port_aux_power_domain(intel_encoder);
  3461. intel_display_power_get(to_i915(dev), power_domain);
  3462. /* Can't disconnect eDP, but you can close the lid... */
  3463. if (is_edp(intel_dp))
  3464. status = edp_detect(intel_dp);
  3465. else if (intel_digital_port_connected(to_i915(dev),
  3466. dp_to_dig_port(intel_dp)))
  3467. status = intel_dp_detect_dpcd(intel_dp);
  3468. else
  3469. status = connector_status_disconnected;
  3470. if (status != connector_status_connected) {
  3471. intel_dp->compliance_test_active = 0;
  3472. intel_dp->compliance_test_type = 0;
  3473. intel_dp->compliance_test_data = 0;
  3474. if (intel_dp->is_mst) {
  3475. DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
  3476. intel_dp->is_mst,
  3477. intel_dp->mst_mgr.mst_state);
  3478. intel_dp->is_mst = false;
  3479. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
  3480. intel_dp->is_mst);
  3481. }
  3482. goto out;
  3483. }
  3484. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  3485. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  3486. intel_dp_probe_oui(intel_dp);
  3487. ret = intel_dp_probe_mst(intel_dp);
  3488. if (ret) {
  3489. /*
  3490. * If we are in MST mode then this connector
  3491. * won't appear connected or have anything
  3492. * with EDID on it
  3493. */
  3494. status = connector_status_disconnected;
  3495. goto out;
  3496. } else if (connector->status == connector_status_connected) {
  3497. /*
  3498. * If display was connected already and is still connected
  3499. * check links status, there has been known issues of
  3500. * link loss triggerring long pulse!!!!
  3501. */
  3502. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  3503. intel_dp_check_link_status(intel_dp);
  3504. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  3505. goto out;
  3506. }
  3507. /*
  3508. * Clearing NACK and defer counts to get their exact values
  3509. * while reading EDID which are required by Compliance tests
  3510. * 4.2.2.4 and 4.2.2.5
  3511. */
  3512. intel_dp->aux.i2c_nack_count = 0;
  3513. intel_dp->aux.i2c_defer_count = 0;
  3514. intel_dp_set_edid(intel_dp);
  3515. status = connector_status_connected;
  3516. intel_dp->detect_done = true;
  3517. /* Try to read the source of the interrupt */
  3518. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3519. intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
  3520. /* Clear interrupt source */
  3521. drm_dp_dpcd_writeb(&intel_dp->aux,
  3522. DP_DEVICE_SERVICE_IRQ_VECTOR,
  3523. sink_irq_vector);
  3524. if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
  3525. intel_dp_handle_test_request(intel_dp);
  3526. if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
  3527. DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
  3528. }
  3529. out:
  3530. if ((status != connector_status_connected) &&
  3531. (intel_dp->is_mst == false))
  3532. intel_dp_unset_edid(intel_dp);
  3533. intel_display_power_put(to_i915(dev), power_domain);
  3534. return;
  3535. }
  3536. static enum drm_connector_status
  3537. intel_dp_detect(struct drm_connector *connector, bool force)
  3538. {
  3539. struct intel_dp *intel_dp = intel_attached_dp(connector);
  3540. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3541. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3542. struct intel_connector *intel_connector = to_intel_connector(connector);
  3543. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  3544. connector->base.id, connector->name);
  3545. if (intel_dp->is_mst) {
  3546. /* MST devices are disconnected from a monitor POV */
  3547. intel_dp_unset_edid(intel_dp);
  3548. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  3549. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  3550. return connector_status_disconnected;
  3551. }
  3552. /* If full detect is not performed yet, do a full detect */
  3553. if (!intel_dp->detect_done)
  3554. intel_dp_long_pulse(intel_dp->attached_connector);
  3555. intel_dp->detect_done = false;
  3556. if (intel_connector->detect_edid)
  3557. return connector_status_connected;
  3558. else
  3559. return connector_status_disconnected;
  3560. }
  3561. static void
  3562. intel_dp_force(struct drm_connector *connector)
  3563. {
  3564. struct intel_dp *intel_dp = intel_attached_dp(connector);
  3565. struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
  3566. struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
  3567. enum intel_display_power_domain power_domain;
  3568. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  3569. connector->base.id, connector->name);
  3570. intel_dp_unset_edid(intel_dp);
  3571. if (connector->status != connector_status_connected)
  3572. return;
  3573. power_domain = intel_display_port_aux_power_domain(intel_encoder);
  3574. intel_display_power_get(dev_priv, power_domain);
  3575. intel_dp_set_edid(intel_dp);
  3576. intel_display_power_put(dev_priv, power_domain);
  3577. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  3578. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  3579. }
  3580. static int intel_dp_get_modes(struct drm_connector *connector)
  3581. {
  3582. struct intel_connector *intel_connector = to_intel_connector(connector);
  3583. struct edid *edid;
  3584. edid = intel_connector->detect_edid;
  3585. if (edid) {
  3586. int ret = intel_connector_update_modes(connector, edid);
  3587. if (ret)
  3588. return ret;
  3589. }
  3590. /* if eDP has no EDID, fall back to fixed mode */
  3591. if (is_edp(intel_attached_dp(connector)) &&
  3592. intel_connector->panel.fixed_mode) {
  3593. struct drm_display_mode *mode;
  3594. mode = drm_mode_duplicate(connector->dev,
  3595. intel_connector->panel.fixed_mode);
  3596. if (mode) {
  3597. drm_mode_probed_add(connector, mode);
  3598. return 1;
  3599. }
  3600. }
  3601. return 0;
  3602. }
  3603. static bool
  3604. intel_dp_detect_audio(struct drm_connector *connector)
  3605. {
  3606. bool has_audio = false;
  3607. struct edid *edid;
  3608. edid = to_intel_connector(connector)->detect_edid;
  3609. if (edid)
  3610. has_audio = drm_detect_monitor_audio(edid);
  3611. return has_audio;
  3612. }
  3613. static int
  3614. intel_dp_set_property(struct drm_connector *connector,
  3615. struct drm_property *property,
  3616. uint64_t val)
  3617. {
  3618. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  3619. struct intel_connector *intel_connector = to_intel_connector(connector);
  3620. struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
  3621. struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
  3622. int ret;
  3623. ret = drm_object_property_set_value(&connector->base, property, val);
  3624. if (ret)
  3625. return ret;
  3626. if (property == dev_priv->force_audio_property) {
  3627. int i = val;
  3628. bool has_audio;
  3629. if (i == intel_dp->force_audio)
  3630. return 0;
  3631. intel_dp->force_audio = i;
  3632. if (i == HDMI_AUDIO_AUTO)
  3633. has_audio = intel_dp_detect_audio(connector);
  3634. else
  3635. has_audio = (i == HDMI_AUDIO_ON);
  3636. if (has_audio == intel_dp->has_audio)
  3637. return 0;
  3638. intel_dp->has_audio = has_audio;
  3639. goto done;
  3640. }
  3641. if (property == dev_priv->broadcast_rgb_property) {
  3642. bool old_auto = intel_dp->color_range_auto;
  3643. bool old_range = intel_dp->limited_color_range;
  3644. switch (val) {
  3645. case INTEL_BROADCAST_RGB_AUTO:
  3646. intel_dp->color_range_auto = true;
  3647. break;
  3648. case INTEL_BROADCAST_RGB_FULL:
  3649. intel_dp->color_range_auto = false;
  3650. intel_dp->limited_color_range = false;
  3651. break;
  3652. case INTEL_BROADCAST_RGB_LIMITED:
  3653. intel_dp->color_range_auto = false;
  3654. intel_dp->limited_color_range = true;
  3655. break;
  3656. default:
  3657. return -EINVAL;
  3658. }
  3659. if (old_auto == intel_dp->color_range_auto &&
  3660. old_range == intel_dp->limited_color_range)
  3661. return 0;
  3662. goto done;
  3663. }
  3664. if (is_edp(intel_dp) &&
  3665. property == connector->dev->mode_config.scaling_mode_property) {
  3666. if (val == DRM_MODE_SCALE_NONE) {
  3667. DRM_DEBUG_KMS("no scaling not supported\n");
  3668. return -EINVAL;
  3669. }
  3670. if (HAS_GMCH_DISPLAY(dev_priv) &&
  3671. val == DRM_MODE_SCALE_CENTER) {
  3672. DRM_DEBUG_KMS("centering not supported\n");
  3673. return -EINVAL;
  3674. }
  3675. if (intel_connector->panel.fitting_mode == val) {
  3676. /* the eDP scaling property is not changed */
  3677. return 0;
  3678. }
  3679. intel_connector->panel.fitting_mode = val;
  3680. goto done;
  3681. }
  3682. return -EINVAL;
  3683. done:
  3684. if (intel_encoder->base.crtc)
  3685. intel_crtc_restore_mode(intel_encoder->base.crtc);
  3686. return 0;
  3687. }
  3688. static void
  3689. intel_dp_connector_destroy(struct drm_connector *connector)
  3690. {
  3691. struct intel_connector *intel_connector = to_intel_connector(connector);
  3692. kfree(intel_connector->detect_edid);
  3693. if (!IS_ERR_OR_NULL(intel_connector->edid))
  3694. kfree(intel_connector->edid);
  3695. /* Can't call is_edp() since the encoder may have been destroyed
  3696. * already. */
  3697. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  3698. intel_panel_fini(&intel_connector->panel);
  3699. drm_connector_cleanup(connector);
  3700. kfree(connector);
  3701. }
  3702. void intel_dp_encoder_destroy(struct drm_encoder *encoder)
  3703. {
  3704. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  3705. struct intel_dp *intel_dp = &intel_dig_port->dp;
  3706. intel_dp_mst_encoder_cleanup(intel_dig_port);
  3707. if (is_edp(intel_dp)) {
  3708. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  3709. /*
  3710. * vdd might still be enabled do to the delayed vdd off.
  3711. * Make sure vdd is actually turned off here.
  3712. */
  3713. pps_lock(intel_dp);
  3714. edp_panel_vdd_off_sync(intel_dp);
  3715. pps_unlock(intel_dp);
  3716. if (intel_dp->edp_notifier.notifier_call) {
  3717. unregister_reboot_notifier(&intel_dp->edp_notifier);
  3718. intel_dp->edp_notifier.notifier_call = NULL;
  3719. }
  3720. }
  3721. drm_encoder_cleanup(encoder);
  3722. kfree(intel_dig_port);
  3723. }
  3724. void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
  3725. {
  3726. struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
  3727. if (!is_edp(intel_dp))
  3728. return;
  3729. /*
  3730. * vdd might still be enabled do to the delayed vdd off.
  3731. * Make sure vdd is actually turned off here.
  3732. */
  3733. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  3734. pps_lock(intel_dp);
  3735. edp_panel_vdd_off_sync(intel_dp);
  3736. pps_unlock(intel_dp);
  3737. }
  3738. static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
  3739. {
  3740. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3741. struct drm_device *dev = intel_dig_port->base.base.dev;
  3742. struct drm_i915_private *dev_priv = dev->dev_private;
  3743. enum intel_display_power_domain power_domain;
  3744. lockdep_assert_held(&dev_priv->pps_mutex);
  3745. if (!edp_have_panel_vdd(intel_dp))
  3746. return;
  3747. /*
  3748. * The VDD bit needs a power domain reference, so if the bit is
  3749. * already enabled when we boot or resume, grab this reference and
  3750. * schedule a vdd off, so we don't hold on to the reference
  3751. * indefinitely.
  3752. */
  3753. DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
  3754. power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
  3755. intel_display_power_get(dev_priv, power_domain);
  3756. edp_panel_vdd_schedule_off(intel_dp);
  3757. }
  3758. void intel_dp_encoder_reset(struct drm_encoder *encoder)
  3759. {
  3760. struct intel_dp *intel_dp;
  3761. if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP)
  3762. return;
  3763. intel_dp = enc_to_intel_dp(encoder);
  3764. pps_lock(intel_dp);
  3765. /*
  3766. * Read out the current power sequencer assignment,
  3767. * in case the BIOS did something with it.
  3768. */
  3769. if (IS_VALLEYVIEW(encoder->dev) || IS_CHERRYVIEW(encoder->dev))
  3770. vlv_initial_power_sequencer_setup(intel_dp);
  3771. intel_edp_panel_vdd_sanitize(intel_dp);
  3772. pps_unlock(intel_dp);
  3773. }
  3774. static const struct drm_connector_funcs intel_dp_connector_funcs = {
  3775. .dpms = drm_atomic_helper_connector_dpms,
  3776. .detect = intel_dp_detect,
  3777. .force = intel_dp_force,
  3778. .fill_modes = drm_helper_probe_single_connector_modes,
  3779. .set_property = intel_dp_set_property,
  3780. .atomic_get_property = intel_connector_atomic_get_property,
  3781. .destroy = intel_dp_connector_destroy,
  3782. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  3783. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  3784. };
  3785. static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
  3786. .get_modes = intel_dp_get_modes,
  3787. .mode_valid = intel_dp_mode_valid,
  3788. .best_encoder = intel_best_encoder,
  3789. };
  3790. static const struct drm_encoder_funcs intel_dp_enc_funcs = {
  3791. .reset = intel_dp_encoder_reset,
  3792. .destroy = intel_dp_encoder_destroy,
  3793. };
  3794. enum irqreturn
  3795. intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
  3796. {
  3797. struct intel_dp *intel_dp = &intel_dig_port->dp;
  3798. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3799. struct drm_device *dev = intel_dig_port->base.base.dev;
  3800. struct drm_i915_private *dev_priv = dev->dev_private;
  3801. enum intel_display_power_domain power_domain;
  3802. enum irqreturn ret = IRQ_NONE;
  3803. if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
  3804. intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
  3805. intel_dig_port->base.type = INTEL_OUTPUT_DISPLAYPORT;
  3806. if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
  3807. /*
  3808. * vdd off can generate a long pulse on eDP which
  3809. * would require vdd on to handle it, and thus we
  3810. * would end up in an endless cycle of
  3811. * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
  3812. */
  3813. DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
  3814. port_name(intel_dig_port->port));
  3815. return IRQ_HANDLED;
  3816. }
  3817. DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
  3818. port_name(intel_dig_port->port),
  3819. long_hpd ? "long" : "short");
  3820. power_domain = intel_display_port_aux_power_domain(intel_encoder);
  3821. intel_display_power_get(dev_priv, power_domain);
  3822. if (long_hpd) {
  3823. /* indicate that we need to restart link training */
  3824. intel_dp->train_set_valid = false;
  3825. intel_dp_long_pulse(intel_dp->attached_connector);
  3826. if (intel_dp->is_mst)
  3827. ret = IRQ_HANDLED;
  3828. goto put_power;
  3829. } else {
  3830. if (intel_dp->is_mst) {
  3831. if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
  3832. /*
  3833. * If we were in MST mode, and device is not
  3834. * there, get out of MST mode
  3835. */
  3836. DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
  3837. intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
  3838. intel_dp->is_mst = false;
  3839. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
  3840. intel_dp->is_mst);
  3841. goto put_power;
  3842. }
  3843. }
  3844. if (!intel_dp->is_mst) {
  3845. if (!intel_dp_short_pulse(intel_dp)) {
  3846. intel_dp_long_pulse(intel_dp->attached_connector);
  3847. goto put_power;
  3848. }
  3849. }
  3850. }
  3851. ret = IRQ_HANDLED;
  3852. put_power:
  3853. intel_display_power_put(dev_priv, power_domain);
  3854. return ret;
  3855. }
  3856. /* check the VBT to see whether the eDP is on another port */
  3857. bool intel_dp_is_edp(struct drm_device *dev, enum port port)
  3858. {
  3859. struct drm_i915_private *dev_priv = dev->dev_private;
  3860. /*
  3861. * eDP not supported on g4x. so bail out early just
  3862. * for a bit extra safety in case the VBT is bonkers.
  3863. */
  3864. if (INTEL_INFO(dev)->gen < 5)
  3865. return false;
  3866. if (port == PORT_A)
  3867. return true;
  3868. return intel_bios_is_port_edp(dev_priv, port);
  3869. }
  3870. void
  3871. intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
  3872. {
  3873. struct intel_connector *intel_connector = to_intel_connector(connector);
  3874. intel_attach_force_audio_property(connector);
  3875. intel_attach_broadcast_rgb_property(connector);
  3876. intel_dp->color_range_auto = true;
  3877. if (is_edp(intel_dp)) {
  3878. drm_mode_create_scaling_mode_property(connector->dev);
  3879. drm_object_attach_property(
  3880. &connector->base,
  3881. connector->dev->mode_config.scaling_mode_property,
  3882. DRM_MODE_SCALE_ASPECT);
  3883. intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
  3884. }
  3885. }
  3886. static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
  3887. {
  3888. intel_dp->panel_power_off_time = ktime_get_boottime();
  3889. intel_dp->last_power_on = jiffies;
  3890. intel_dp->last_backlight_off = jiffies;
  3891. }
  3892. static void
  3893. intel_dp_init_panel_power_sequencer(struct drm_device *dev,
  3894. struct intel_dp *intel_dp)
  3895. {
  3896. struct drm_i915_private *dev_priv = dev->dev_private;
  3897. struct edp_power_seq cur, vbt, spec,
  3898. *final = &intel_dp->pps_delays;
  3899. u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
  3900. i915_reg_t pp_ctrl_reg, pp_on_reg, pp_off_reg, pp_div_reg;
  3901. lockdep_assert_held(&dev_priv->pps_mutex);
  3902. /* already initialized? */
  3903. if (final->t11_t12 != 0)
  3904. return;
  3905. if (IS_BROXTON(dev)) {
  3906. /*
  3907. * TODO: BXT has 2 sets of PPS registers.
  3908. * Correct Register for Broxton need to be identified
  3909. * using VBT. hardcoding for now
  3910. */
  3911. pp_ctrl_reg = BXT_PP_CONTROL(0);
  3912. pp_on_reg = BXT_PP_ON_DELAYS(0);
  3913. pp_off_reg = BXT_PP_OFF_DELAYS(0);
  3914. } else if (HAS_PCH_SPLIT(dev)) {
  3915. pp_ctrl_reg = PCH_PP_CONTROL;
  3916. pp_on_reg = PCH_PP_ON_DELAYS;
  3917. pp_off_reg = PCH_PP_OFF_DELAYS;
  3918. pp_div_reg = PCH_PP_DIVISOR;
  3919. } else {
  3920. enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
  3921. pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
  3922. pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
  3923. pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
  3924. pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
  3925. }
  3926. /* Workaround: Need to write PP_CONTROL with the unlock key as
  3927. * the very first thing. */
  3928. pp_ctl = ironlake_get_pp_control(intel_dp);
  3929. pp_on = I915_READ(pp_on_reg);
  3930. pp_off = I915_READ(pp_off_reg);
  3931. if (!IS_BROXTON(dev)) {
  3932. I915_WRITE(pp_ctrl_reg, pp_ctl);
  3933. pp_div = I915_READ(pp_div_reg);
  3934. }
  3935. /* Pull timing values out of registers */
  3936. cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
  3937. PANEL_POWER_UP_DELAY_SHIFT;
  3938. cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
  3939. PANEL_LIGHT_ON_DELAY_SHIFT;
  3940. cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
  3941. PANEL_LIGHT_OFF_DELAY_SHIFT;
  3942. cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
  3943. PANEL_POWER_DOWN_DELAY_SHIFT;
  3944. if (IS_BROXTON(dev)) {
  3945. u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
  3946. BXT_POWER_CYCLE_DELAY_SHIFT;
  3947. if (tmp > 0)
  3948. cur.t11_t12 = (tmp - 1) * 1000;
  3949. else
  3950. cur.t11_t12 = 0;
  3951. } else {
  3952. cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
  3953. PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
  3954. }
  3955. DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  3956. cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
  3957. vbt = dev_priv->vbt.edp.pps;
  3958. /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
  3959. * our hw here, which are all in 100usec. */
  3960. spec.t1_t3 = 210 * 10;
  3961. spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
  3962. spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
  3963. spec.t10 = 500 * 10;
  3964. /* This one is special and actually in units of 100ms, but zero
  3965. * based in the hw (so we need to add 100 ms). But the sw vbt
  3966. * table multiplies it with 1000 to make it in units of 100usec,
  3967. * too. */
  3968. spec.t11_t12 = (510 + 100) * 10;
  3969. DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  3970. vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
  3971. /* Use the max of the register settings and vbt. If both are
  3972. * unset, fall back to the spec limits. */
  3973. #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
  3974. spec.field : \
  3975. max(cur.field, vbt.field))
  3976. assign_final(t1_t3);
  3977. assign_final(t8);
  3978. assign_final(t9);
  3979. assign_final(t10);
  3980. assign_final(t11_t12);
  3981. #undef assign_final
  3982. #define get_delay(field) (DIV_ROUND_UP(final->field, 10))
  3983. intel_dp->panel_power_up_delay = get_delay(t1_t3);
  3984. intel_dp->backlight_on_delay = get_delay(t8);
  3985. intel_dp->backlight_off_delay = get_delay(t9);
  3986. intel_dp->panel_power_down_delay = get_delay(t10);
  3987. intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
  3988. #undef get_delay
  3989. DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
  3990. intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
  3991. intel_dp->panel_power_cycle_delay);
  3992. DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
  3993. intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
  3994. }
  3995. static void
  3996. intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
  3997. struct intel_dp *intel_dp)
  3998. {
  3999. struct drm_i915_private *dev_priv = dev->dev_private;
  4000. u32 pp_on, pp_off, pp_div, port_sel = 0;
  4001. int div = dev_priv->rawclk_freq / 1000;
  4002. i915_reg_t pp_on_reg, pp_off_reg, pp_div_reg, pp_ctrl_reg;
  4003. enum port port = dp_to_dig_port(intel_dp)->port;
  4004. const struct edp_power_seq *seq = &intel_dp->pps_delays;
  4005. lockdep_assert_held(&dev_priv->pps_mutex);
  4006. if (IS_BROXTON(dev)) {
  4007. /*
  4008. * TODO: BXT has 2 sets of PPS registers.
  4009. * Correct Register for Broxton need to be identified
  4010. * using VBT. hardcoding for now
  4011. */
  4012. pp_ctrl_reg = BXT_PP_CONTROL(0);
  4013. pp_on_reg = BXT_PP_ON_DELAYS(0);
  4014. pp_off_reg = BXT_PP_OFF_DELAYS(0);
  4015. } else if (HAS_PCH_SPLIT(dev)) {
  4016. pp_on_reg = PCH_PP_ON_DELAYS;
  4017. pp_off_reg = PCH_PP_OFF_DELAYS;
  4018. pp_div_reg = PCH_PP_DIVISOR;
  4019. } else {
  4020. enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
  4021. pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
  4022. pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
  4023. pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
  4024. }
  4025. /*
  4026. * And finally store the new values in the power sequencer. The
  4027. * backlight delays are set to 1 because we do manual waits on them. For
  4028. * T8, even BSpec recommends doing it. For T9, if we don't do this,
  4029. * we'll end up waiting for the backlight off delay twice: once when we
  4030. * do the manual sleep, and once when we disable the panel and wait for
  4031. * the PP_STATUS bit to become zero.
  4032. */
  4033. pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
  4034. (1 << PANEL_LIGHT_ON_DELAY_SHIFT);
  4035. pp_off = (1 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
  4036. (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
  4037. /* Compute the divisor for the pp clock, simply match the Bspec
  4038. * formula. */
  4039. if (IS_BROXTON(dev)) {
  4040. pp_div = I915_READ(pp_ctrl_reg);
  4041. pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
  4042. pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
  4043. << BXT_POWER_CYCLE_DELAY_SHIFT);
  4044. } else {
  4045. pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
  4046. pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
  4047. << PANEL_POWER_CYCLE_DELAY_SHIFT);
  4048. }
  4049. /* Haswell doesn't have any port selection bits for the panel
  4050. * power sequencer any more. */
  4051. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  4052. port_sel = PANEL_PORT_SELECT_VLV(port);
  4053. } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
  4054. if (port == PORT_A)
  4055. port_sel = PANEL_PORT_SELECT_DPA;
  4056. else
  4057. port_sel = PANEL_PORT_SELECT_DPD;
  4058. }
  4059. pp_on |= port_sel;
  4060. I915_WRITE(pp_on_reg, pp_on);
  4061. I915_WRITE(pp_off_reg, pp_off);
  4062. if (IS_BROXTON(dev))
  4063. I915_WRITE(pp_ctrl_reg, pp_div);
  4064. else
  4065. I915_WRITE(pp_div_reg, pp_div);
  4066. DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
  4067. I915_READ(pp_on_reg),
  4068. I915_READ(pp_off_reg),
  4069. IS_BROXTON(dev) ?
  4070. (I915_READ(pp_ctrl_reg) & BXT_POWER_CYCLE_DELAY_MASK) :
  4071. I915_READ(pp_div_reg));
  4072. }
  4073. /**
  4074. * intel_dp_set_drrs_state - program registers for RR switch to take effect
  4075. * @dev: DRM device
  4076. * @refresh_rate: RR to be programmed
  4077. *
  4078. * This function gets called when refresh rate (RR) has to be changed from
  4079. * one frequency to another. Switches can be between high and low RR
  4080. * supported by the panel or to any other RR based on media playback (in
  4081. * this case, RR value needs to be passed from user space).
  4082. *
  4083. * The caller of this function needs to take a lock on dev_priv->drrs.
  4084. */
  4085. static void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate)
  4086. {
  4087. struct drm_i915_private *dev_priv = dev->dev_private;
  4088. struct intel_encoder *encoder;
  4089. struct intel_digital_port *dig_port = NULL;
  4090. struct intel_dp *intel_dp = dev_priv->drrs.dp;
  4091. struct intel_crtc_state *config = NULL;
  4092. struct intel_crtc *intel_crtc = NULL;
  4093. enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
  4094. if (refresh_rate <= 0) {
  4095. DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
  4096. return;
  4097. }
  4098. if (intel_dp == NULL) {
  4099. DRM_DEBUG_KMS("DRRS not supported.\n");
  4100. return;
  4101. }
  4102. /*
  4103. * FIXME: This needs proper synchronization with psr state for some
  4104. * platforms that cannot have PSR and DRRS enabled at the same time.
  4105. */
  4106. dig_port = dp_to_dig_port(intel_dp);
  4107. encoder = &dig_port->base;
  4108. intel_crtc = to_intel_crtc(encoder->base.crtc);
  4109. if (!intel_crtc) {
  4110. DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
  4111. return;
  4112. }
  4113. config = intel_crtc->config;
  4114. if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
  4115. DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
  4116. return;
  4117. }
  4118. if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
  4119. refresh_rate)
  4120. index = DRRS_LOW_RR;
  4121. if (index == dev_priv->drrs.refresh_rate_type) {
  4122. DRM_DEBUG_KMS(
  4123. "DRRS requested for previously set RR...ignoring\n");
  4124. return;
  4125. }
  4126. if (!intel_crtc->active) {
  4127. DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
  4128. return;
  4129. }
  4130. if (INTEL_INFO(dev)->gen >= 8 && !IS_CHERRYVIEW(dev)) {
  4131. switch (index) {
  4132. case DRRS_HIGH_RR:
  4133. intel_dp_set_m_n(intel_crtc, M1_N1);
  4134. break;
  4135. case DRRS_LOW_RR:
  4136. intel_dp_set_m_n(intel_crtc, M2_N2);
  4137. break;
  4138. case DRRS_MAX_RR:
  4139. default:
  4140. DRM_ERROR("Unsupported refreshrate type\n");
  4141. }
  4142. } else if (INTEL_INFO(dev)->gen > 6) {
  4143. i915_reg_t reg = PIPECONF(intel_crtc->config->cpu_transcoder);
  4144. u32 val;
  4145. val = I915_READ(reg);
  4146. if (index > DRRS_HIGH_RR) {
  4147. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
  4148. val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
  4149. else
  4150. val |= PIPECONF_EDP_RR_MODE_SWITCH;
  4151. } else {
  4152. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
  4153. val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
  4154. else
  4155. val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
  4156. }
  4157. I915_WRITE(reg, val);
  4158. }
  4159. dev_priv->drrs.refresh_rate_type = index;
  4160. DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
  4161. }
  4162. /**
  4163. * intel_edp_drrs_enable - init drrs struct if supported
  4164. * @intel_dp: DP struct
  4165. *
  4166. * Initializes frontbuffer_bits and drrs.dp
  4167. */
  4168. void intel_edp_drrs_enable(struct intel_dp *intel_dp)
  4169. {
  4170. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  4171. struct drm_i915_private *dev_priv = dev->dev_private;
  4172. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  4173. struct drm_crtc *crtc = dig_port->base.base.crtc;
  4174. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4175. if (!intel_crtc->config->has_drrs) {
  4176. DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
  4177. return;
  4178. }
  4179. mutex_lock(&dev_priv->drrs.mutex);
  4180. if (WARN_ON(dev_priv->drrs.dp)) {
  4181. DRM_ERROR("DRRS already enabled\n");
  4182. goto unlock;
  4183. }
  4184. dev_priv->drrs.busy_frontbuffer_bits = 0;
  4185. dev_priv->drrs.dp = intel_dp;
  4186. unlock:
  4187. mutex_unlock(&dev_priv->drrs.mutex);
  4188. }
  4189. /**
  4190. * intel_edp_drrs_disable - Disable DRRS
  4191. * @intel_dp: DP struct
  4192. *
  4193. */
  4194. void intel_edp_drrs_disable(struct intel_dp *intel_dp)
  4195. {
  4196. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  4197. struct drm_i915_private *dev_priv = dev->dev_private;
  4198. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  4199. struct drm_crtc *crtc = dig_port->base.base.crtc;
  4200. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4201. if (!intel_crtc->config->has_drrs)
  4202. return;
  4203. mutex_lock(&dev_priv->drrs.mutex);
  4204. if (!dev_priv->drrs.dp) {
  4205. mutex_unlock(&dev_priv->drrs.mutex);
  4206. return;
  4207. }
  4208. if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
  4209. intel_dp_set_drrs_state(dev_priv->dev,
  4210. intel_dp->attached_connector->panel.
  4211. fixed_mode->vrefresh);
  4212. dev_priv->drrs.dp = NULL;
  4213. mutex_unlock(&dev_priv->drrs.mutex);
  4214. cancel_delayed_work_sync(&dev_priv->drrs.work);
  4215. }
  4216. static void intel_edp_drrs_downclock_work(struct work_struct *work)
  4217. {
  4218. struct drm_i915_private *dev_priv =
  4219. container_of(work, typeof(*dev_priv), drrs.work.work);
  4220. struct intel_dp *intel_dp;
  4221. mutex_lock(&dev_priv->drrs.mutex);
  4222. intel_dp = dev_priv->drrs.dp;
  4223. if (!intel_dp)
  4224. goto unlock;
  4225. /*
  4226. * The delayed work can race with an invalidate hence we need to
  4227. * recheck.
  4228. */
  4229. if (dev_priv->drrs.busy_frontbuffer_bits)
  4230. goto unlock;
  4231. if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR)
  4232. intel_dp_set_drrs_state(dev_priv->dev,
  4233. intel_dp->attached_connector->panel.
  4234. downclock_mode->vrefresh);
  4235. unlock:
  4236. mutex_unlock(&dev_priv->drrs.mutex);
  4237. }
  4238. /**
  4239. * intel_edp_drrs_invalidate - Disable Idleness DRRS
  4240. * @dev: DRM device
  4241. * @frontbuffer_bits: frontbuffer plane tracking bits
  4242. *
  4243. * This function gets called everytime rendering on the given planes start.
  4244. * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
  4245. *
  4246. * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
  4247. */
  4248. void intel_edp_drrs_invalidate(struct drm_device *dev,
  4249. unsigned frontbuffer_bits)
  4250. {
  4251. struct drm_i915_private *dev_priv = dev->dev_private;
  4252. struct drm_crtc *crtc;
  4253. enum pipe pipe;
  4254. if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
  4255. return;
  4256. cancel_delayed_work(&dev_priv->drrs.work);
  4257. mutex_lock(&dev_priv->drrs.mutex);
  4258. if (!dev_priv->drrs.dp) {
  4259. mutex_unlock(&dev_priv->drrs.mutex);
  4260. return;
  4261. }
  4262. crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
  4263. pipe = to_intel_crtc(crtc)->pipe;
  4264. frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
  4265. dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
  4266. /* invalidate means busy screen hence upclock */
  4267. if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
  4268. intel_dp_set_drrs_state(dev_priv->dev,
  4269. dev_priv->drrs.dp->attached_connector->panel.
  4270. fixed_mode->vrefresh);
  4271. mutex_unlock(&dev_priv->drrs.mutex);
  4272. }
  4273. /**
  4274. * intel_edp_drrs_flush - Restart Idleness DRRS
  4275. * @dev: DRM device
  4276. * @frontbuffer_bits: frontbuffer plane tracking bits
  4277. *
  4278. * This function gets called every time rendering on the given planes has
  4279. * completed or flip on a crtc is completed. So DRRS should be upclocked
  4280. * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
  4281. * if no other planes are dirty.
  4282. *
  4283. * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
  4284. */
  4285. void intel_edp_drrs_flush(struct drm_device *dev,
  4286. unsigned frontbuffer_bits)
  4287. {
  4288. struct drm_i915_private *dev_priv = dev->dev_private;
  4289. struct drm_crtc *crtc;
  4290. enum pipe pipe;
  4291. if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
  4292. return;
  4293. cancel_delayed_work(&dev_priv->drrs.work);
  4294. mutex_lock(&dev_priv->drrs.mutex);
  4295. if (!dev_priv->drrs.dp) {
  4296. mutex_unlock(&dev_priv->drrs.mutex);
  4297. return;
  4298. }
  4299. crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
  4300. pipe = to_intel_crtc(crtc)->pipe;
  4301. frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
  4302. dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
  4303. /* flush means busy screen hence upclock */
  4304. if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
  4305. intel_dp_set_drrs_state(dev_priv->dev,
  4306. dev_priv->drrs.dp->attached_connector->panel.
  4307. fixed_mode->vrefresh);
  4308. /*
  4309. * flush also means no more activity hence schedule downclock, if all
  4310. * other fbs are quiescent too
  4311. */
  4312. if (!dev_priv->drrs.busy_frontbuffer_bits)
  4313. schedule_delayed_work(&dev_priv->drrs.work,
  4314. msecs_to_jiffies(1000));
  4315. mutex_unlock(&dev_priv->drrs.mutex);
  4316. }
  4317. /**
  4318. * DOC: Display Refresh Rate Switching (DRRS)
  4319. *
  4320. * Display Refresh Rate Switching (DRRS) is a power conservation feature
  4321. * which enables swtching between low and high refresh rates,
  4322. * dynamically, based on the usage scenario. This feature is applicable
  4323. * for internal panels.
  4324. *
  4325. * Indication that the panel supports DRRS is given by the panel EDID, which
  4326. * would list multiple refresh rates for one resolution.
  4327. *
  4328. * DRRS is of 2 types - static and seamless.
  4329. * Static DRRS involves changing refresh rate (RR) by doing a full modeset
  4330. * (may appear as a blink on screen) and is used in dock-undock scenario.
  4331. * Seamless DRRS involves changing RR without any visual effect to the user
  4332. * and can be used during normal system usage. This is done by programming
  4333. * certain registers.
  4334. *
  4335. * Support for static/seamless DRRS may be indicated in the VBT based on
  4336. * inputs from the panel spec.
  4337. *
  4338. * DRRS saves power by switching to low RR based on usage scenarios.
  4339. *
  4340. * The implementation is based on frontbuffer tracking implementation. When
  4341. * there is a disturbance on the screen triggered by user activity or a periodic
  4342. * system activity, DRRS is disabled (RR is changed to high RR). When there is
  4343. * no movement on screen, after a timeout of 1 second, a switch to low RR is
  4344. * made.
  4345. *
  4346. * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
  4347. * and intel_edp_drrs_flush() are called.
  4348. *
  4349. * DRRS can be further extended to support other internal panels and also
  4350. * the scenario of video playback wherein RR is set based on the rate
  4351. * requested by userspace.
  4352. */
  4353. /**
  4354. * intel_dp_drrs_init - Init basic DRRS work and mutex.
  4355. * @intel_connector: eDP connector
  4356. * @fixed_mode: preferred mode of panel
  4357. *
  4358. * This function is called only once at driver load to initialize basic
  4359. * DRRS stuff.
  4360. *
  4361. * Returns:
  4362. * Downclock mode if panel supports it, else return NULL.
  4363. * DRRS support is determined by the presence of downclock mode (apart
  4364. * from VBT setting).
  4365. */
  4366. static struct drm_display_mode *
  4367. intel_dp_drrs_init(struct intel_connector *intel_connector,
  4368. struct drm_display_mode *fixed_mode)
  4369. {
  4370. struct drm_connector *connector = &intel_connector->base;
  4371. struct drm_device *dev = connector->dev;
  4372. struct drm_i915_private *dev_priv = dev->dev_private;
  4373. struct drm_display_mode *downclock_mode = NULL;
  4374. INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
  4375. mutex_init(&dev_priv->drrs.mutex);
  4376. if (INTEL_INFO(dev)->gen <= 6) {
  4377. DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
  4378. return NULL;
  4379. }
  4380. if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
  4381. DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
  4382. return NULL;
  4383. }
  4384. downclock_mode = intel_find_panel_downclock
  4385. (dev, fixed_mode, connector);
  4386. if (!downclock_mode) {
  4387. DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
  4388. return NULL;
  4389. }
  4390. dev_priv->drrs.type = dev_priv->vbt.drrs_type;
  4391. dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
  4392. DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
  4393. return downclock_mode;
  4394. }
  4395. static bool intel_edp_init_connector(struct intel_dp *intel_dp,
  4396. struct intel_connector *intel_connector)
  4397. {
  4398. struct drm_connector *connector = &intel_connector->base;
  4399. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  4400. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  4401. struct drm_device *dev = intel_encoder->base.dev;
  4402. struct drm_i915_private *dev_priv = dev->dev_private;
  4403. struct drm_display_mode *fixed_mode = NULL;
  4404. struct drm_display_mode *downclock_mode = NULL;
  4405. bool has_dpcd;
  4406. struct drm_display_mode *scan;
  4407. struct edid *edid;
  4408. enum pipe pipe = INVALID_PIPE;
  4409. if (!is_edp(intel_dp))
  4410. return true;
  4411. pps_lock(intel_dp);
  4412. intel_edp_panel_vdd_sanitize(intel_dp);
  4413. pps_unlock(intel_dp);
  4414. /* Cache DPCD and EDID for edp. */
  4415. has_dpcd = intel_dp_get_dpcd(intel_dp);
  4416. if (has_dpcd) {
  4417. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
  4418. dev_priv->no_aux_handshake =
  4419. intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
  4420. DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
  4421. } else {
  4422. /* if this fails, presume the device is a ghost */
  4423. DRM_INFO("failed to retrieve link info, disabling eDP\n");
  4424. return false;
  4425. }
  4426. /* We now know it's not a ghost, init power sequence regs. */
  4427. pps_lock(intel_dp);
  4428. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
  4429. pps_unlock(intel_dp);
  4430. mutex_lock(&dev->mode_config.mutex);
  4431. edid = drm_get_edid(connector, &intel_dp->aux.ddc);
  4432. if (edid) {
  4433. if (drm_add_edid_modes(connector, edid)) {
  4434. drm_mode_connector_update_edid_property(connector,
  4435. edid);
  4436. drm_edid_to_eld(connector, edid);
  4437. } else {
  4438. kfree(edid);
  4439. edid = ERR_PTR(-EINVAL);
  4440. }
  4441. } else {
  4442. edid = ERR_PTR(-ENOENT);
  4443. }
  4444. intel_connector->edid = edid;
  4445. /* prefer fixed mode from EDID if available */
  4446. list_for_each_entry(scan, &connector->probed_modes, head) {
  4447. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  4448. fixed_mode = drm_mode_duplicate(dev, scan);
  4449. downclock_mode = intel_dp_drrs_init(
  4450. intel_connector, fixed_mode);
  4451. break;
  4452. }
  4453. }
  4454. /* fallback to VBT if available for eDP */
  4455. if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
  4456. fixed_mode = drm_mode_duplicate(dev,
  4457. dev_priv->vbt.lfp_lvds_vbt_mode);
  4458. if (fixed_mode)
  4459. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  4460. }
  4461. mutex_unlock(&dev->mode_config.mutex);
  4462. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  4463. intel_dp->edp_notifier.notifier_call = edp_notify_handler;
  4464. register_reboot_notifier(&intel_dp->edp_notifier);
  4465. /*
  4466. * Figure out the current pipe for the initial backlight setup.
  4467. * If the current pipe isn't valid, try the PPS pipe, and if that
  4468. * fails just assume pipe A.
  4469. */
  4470. if (IS_CHERRYVIEW(dev))
  4471. pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP);
  4472. else
  4473. pipe = PORT_TO_PIPE(intel_dp->DP);
  4474. if (pipe != PIPE_A && pipe != PIPE_B)
  4475. pipe = intel_dp->pps_pipe;
  4476. if (pipe != PIPE_A && pipe != PIPE_B)
  4477. pipe = PIPE_A;
  4478. DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
  4479. pipe_name(pipe));
  4480. }
  4481. intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
  4482. intel_connector->panel.backlight.power = intel_edp_backlight_power;
  4483. intel_panel_setup_backlight(connector, pipe);
  4484. return true;
  4485. }
  4486. bool
  4487. intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
  4488. struct intel_connector *intel_connector)
  4489. {
  4490. struct drm_connector *connector = &intel_connector->base;
  4491. struct intel_dp *intel_dp = &intel_dig_port->dp;
  4492. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  4493. struct drm_device *dev = intel_encoder->base.dev;
  4494. struct drm_i915_private *dev_priv = dev->dev_private;
  4495. enum port port = intel_dig_port->port;
  4496. int type, ret;
  4497. if (WARN(intel_dig_port->max_lanes < 1,
  4498. "Not enough lanes (%d) for DP on port %c\n",
  4499. intel_dig_port->max_lanes, port_name(port)))
  4500. return false;
  4501. intel_dp->pps_pipe = INVALID_PIPE;
  4502. /* intel_dp vfuncs */
  4503. if (INTEL_INFO(dev)->gen >= 9)
  4504. intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
  4505. else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  4506. intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
  4507. else if (HAS_PCH_SPLIT(dev))
  4508. intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
  4509. else
  4510. intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
  4511. if (INTEL_INFO(dev)->gen >= 9)
  4512. intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
  4513. else
  4514. intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
  4515. if (HAS_DDI(dev))
  4516. intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
  4517. /* Preserve the current hw state. */
  4518. intel_dp->DP = I915_READ(intel_dp->output_reg);
  4519. intel_dp->attached_connector = intel_connector;
  4520. if (intel_dp_is_edp(dev, port))
  4521. type = DRM_MODE_CONNECTOR_eDP;
  4522. else
  4523. type = DRM_MODE_CONNECTOR_DisplayPort;
  4524. /*
  4525. * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
  4526. * for DP the encoder type can be set by the caller to
  4527. * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
  4528. */
  4529. if (type == DRM_MODE_CONNECTOR_eDP)
  4530. intel_encoder->type = INTEL_OUTPUT_EDP;
  4531. /* eDP only on port B and/or C on vlv/chv */
  4532. if (WARN_ON((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
  4533. is_edp(intel_dp) && port != PORT_B && port != PORT_C))
  4534. return false;
  4535. DRM_DEBUG_KMS("Adding %s connector on port %c\n",
  4536. type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
  4537. port_name(port));
  4538. drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
  4539. drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
  4540. connector->interlace_allowed = true;
  4541. connector->doublescan_allowed = 0;
  4542. INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
  4543. edp_panel_vdd_work);
  4544. intel_connector_attach_encoder(intel_connector, intel_encoder);
  4545. drm_connector_register(connector);
  4546. if (HAS_DDI(dev))
  4547. intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
  4548. else
  4549. intel_connector->get_hw_state = intel_connector_get_hw_state;
  4550. intel_connector->unregister = intel_dp_connector_unregister;
  4551. /* Set up the hotplug pin. */
  4552. switch (port) {
  4553. case PORT_A:
  4554. intel_encoder->hpd_pin = HPD_PORT_A;
  4555. break;
  4556. case PORT_B:
  4557. intel_encoder->hpd_pin = HPD_PORT_B;
  4558. if (IS_BXT_REVID(dev, 0, BXT_REVID_A1))
  4559. intel_encoder->hpd_pin = HPD_PORT_A;
  4560. break;
  4561. case PORT_C:
  4562. intel_encoder->hpd_pin = HPD_PORT_C;
  4563. break;
  4564. case PORT_D:
  4565. intel_encoder->hpd_pin = HPD_PORT_D;
  4566. break;
  4567. case PORT_E:
  4568. intel_encoder->hpd_pin = HPD_PORT_E;
  4569. break;
  4570. default:
  4571. BUG();
  4572. }
  4573. if (is_edp(intel_dp)) {
  4574. pps_lock(intel_dp);
  4575. intel_dp_init_panel_power_timestamps(intel_dp);
  4576. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
  4577. vlv_initial_power_sequencer_setup(intel_dp);
  4578. else
  4579. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  4580. pps_unlock(intel_dp);
  4581. }
  4582. ret = intel_dp_aux_init(intel_dp, intel_connector);
  4583. if (ret)
  4584. goto fail;
  4585. /* init MST on ports that can support it */
  4586. if (HAS_DP_MST(dev) &&
  4587. (port == PORT_B || port == PORT_C || port == PORT_D))
  4588. intel_dp_mst_encoder_init(intel_dig_port,
  4589. intel_connector->base.base.id);
  4590. if (!intel_edp_init_connector(intel_dp, intel_connector)) {
  4591. intel_dp_aux_fini(intel_dp);
  4592. intel_dp_mst_encoder_cleanup(intel_dig_port);
  4593. goto fail;
  4594. }
  4595. intel_dp_add_properties(intel_dp, connector);
  4596. /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
  4597. * 0xd. Failure to do so will result in spurious interrupts being
  4598. * generated on the port when a cable is not attached.
  4599. */
  4600. if (IS_G4X(dev) && !IS_GM45(dev)) {
  4601. u32 temp = I915_READ(PEG_BAND_GAP_DATA);
  4602. I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
  4603. }
  4604. i915_debugfs_connector_add(connector);
  4605. return true;
  4606. fail:
  4607. if (is_edp(intel_dp)) {
  4608. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  4609. /*
  4610. * vdd might still be enabled do to the delayed vdd off.
  4611. * Make sure vdd is actually turned off here.
  4612. */
  4613. pps_lock(intel_dp);
  4614. edp_panel_vdd_off_sync(intel_dp);
  4615. pps_unlock(intel_dp);
  4616. }
  4617. drm_connector_unregister(connector);
  4618. drm_connector_cleanup(connector);
  4619. return false;
  4620. }
  4621. void
  4622. intel_dp_init(struct drm_device *dev,
  4623. i915_reg_t output_reg, enum port port)
  4624. {
  4625. struct drm_i915_private *dev_priv = dev->dev_private;
  4626. struct intel_digital_port *intel_dig_port;
  4627. struct intel_encoder *intel_encoder;
  4628. struct drm_encoder *encoder;
  4629. struct intel_connector *intel_connector;
  4630. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  4631. if (!intel_dig_port)
  4632. return;
  4633. intel_connector = intel_connector_alloc();
  4634. if (!intel_connector)
  4635. goto err_connector_alloc;
  4636. intel_encoder = &intel_dig_port->base;
  4637. encoder = &intel_encoder->base;
  4638. if (drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
  4639. DRM_MODE_ENCODER_TMDS, NULL))
  4640. goto err_encoder_init;
  4641. intel_encoder->compute_config = intel_dp_compute_config;
  4642. intel_encoder->disable = intel_disable_dp;
  4643. intel_encoder->get_hw_state = intel_dp_get_hw_state;
  4644. intel_encoder->get_config = intel_dp_get_config;
  4645. intel_encoder->suspend = intel_dp_encoder_suspend;
  4646. if (IS_CHERRYVIEW(dev)) {
  4647. intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
  4648. intel_encoder->pre_enable = chv_pre_enable_dp;
  4649. intel_encoder->enable = vlv_enable_dp;
  4650. intel_encoder->post_disable = chv_post_disable_dp;
  4651. intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
  4652. } else if (IS_VALLEYVIEW(dev)) {
  4653. intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
  4654. intel_encoder->pre_enable = vlv_pre_enable_dp;
  4655. intel_encoder->enable = vlv_enable_dp;
  4656. intel_encoder->post_disable = vlv_post_disable_dp;
  4657. } else {
  4658. intel_encoder->pre_enable = g4x_pre_enable_dp;
  4659. intel_encoder->enable = g4x_enable_dp;
  4660. if (INTEL_INFO(dev)->gen >= 5)
  4661. intel_encoder->post_disable = ilk_post_disable_dp;
  4662. }
  4663. intel_dig_port->port = port;
  4664. intel_dig_port->dp.output_reg = output_reg;
  4665. intel_dig_port->max_lanes = 4;
  4666. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  4667. if (IS_CHERRYVIEW(dev)) {
  4668. if (port == PORT_D)
  4669. intel_encoder->crtc_mask = 1 << 2;
  4670. else
  4671. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  4672. } else {
  4673. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  4674. }
  4675. intel_encoder->cloneable = 0;
  4676. intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
  4677. dev_priv->hotplug.irq_port[port] = intel_dig_port;
  4678. if (!intel_dp_init_connector(intel_dig_port, intel_connector))
  4679. goto err_init_connector;
  4680. return;
  4681. err_init_connector:
  4682. drm_encoder_cleanup(encoder);
  4683. err_encoder_init:
  4684. kfree(intel_connector);
  4685. err_connector_alloc:
  4686. kfree(intel_dig_port);
  4687. return;
  4688. }
  4689. void intel_dp_mst_suspend(struct drm_device *dev)
  4690. {
  4691. struct drm_i915_private *dev_priv = dev->dev_private;
  4692. int i;
  4693. /* disable MST */
  4694. for (i = 0; i < I915_MAX_PORTS; i++) {
  4695. struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
  4696. if (!intel_dig_port)
  4697. continue;
  4698. if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {
  4699. if (!intel_dig_port->dp.can_mst)
  4700. continue;
  4701. if (intel_dig_port->dp.is_mst)
  4702. drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
  4703. }
  4704. }
  4705. }
  4706. void intel_dp_mst_resume(struct drm_device *dev)
  4707. {
  4708. struct drm_i915_private *dev_priv = dev->dev_private;
  4709. int i;
  4710. for (i = 0; i < I915_MAX_PORTS; i++) {
  4711. struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
  4712. if (!intel_dig_port)
  4713. continue;
  4714. if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {
  4715. int ret;
  4716. if (!intel_dig_port->dp.can_mst)
  4717. continue;
  4718. ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
  4719. if (ret != 0) {
  4720. intel_dp_check_mst_status(&intel_dig_port->dp);
  4721. }
  4722. }
  4723. }
  4724. }