intel_dp.c 147 KB

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