intel_dp.c 147 KB

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