intel_display.c 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523
  1. /*
  2. * Copyright © 2006-2007 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
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. */
  26. #include <linux/module.h>
  27. #include <linux/input.h>
  28. #include <linux/i2c.h>
  29. #include <linux/kernel.h>
  30. #include "drmP.h"
  31. #include "intel_drv.h"
  32. #include "i915_drm.h"
  33. #include "i915_drv.h"
  34. #include "intel_dp.h"
  35. #include "drm_crtc_helper.h"
  36. #define HAS_eDP (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
  37. bool intel_pipe_has_type (struct drm_crtc *crtc, int type);
  38. static void intel_update_watermarks(struct drm_device *dev);
  39. static void intel_increase_pllclock(struct drm_crtc *crtc, bool schedule);
  40. typedef struct {
  41. /* given values */
  42. int n;
  43. int m1, m2;
  44. int p1, p2;
  45. /* derived values */
  46. int dot;
  47. int vco;
  48. int m;
  49. int p;
  50. } intel_clock_t;
  51. typedef struct {
  52. int min, max;
  53. } intel_range_t;
  54. typedef struct {
  55. int dot_limit;
  56. int p2_slow, p2_fast;
  57. } intel_p2_t;
  58. #define INTEL_P2_NUM 2
  59. typedef struct intel_limit intel_limit_t;
  60. struct intel_limit {
  61. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  62. intel_p2_t p2;
  63. bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
  64. int, int, intel_clock_t *);
  65. bool (* find_reduced_pll)(const intel_limit_t *, struct drm_crtc *,
  66. int, int, intel_clock_t *);
  67. };
  68. #define I8XX_DOT_MIN 25000
  69. #define I8XX_DOT_MAX 350000
  70. #define I8XX_VCO_MIN 930000
  71. #define I8XX_VCO_MAX 1400000
  72. #define I8XX_N_MIN 3
  73. #define I8XX_N_MAX 16
  74. #define I8XX_M_MIN 96
  75. #define I8XX_M_MAX 140
  76. #define I8XX_M1_MIN 18
  77. #define I8XX_M1_MAX 26
  78. #define I8XX_M2_MIN 6
  79. #define I8XX_M2_MAX 16
  80. #define I8XX_P_MIN 4
  81. #define I8XX_P_MAX 128
  82. #define I8XX_P1_MIN 2
  83. #define I8XX_P1_MAX 33
  84. #define I8XX_P1_LVDS_MIN 1
  85. #define I8XX_P1_LVDS_MAX 6
  86. #define I8XX_P2_SLOW 4
  87. #define I8XX_P2_FAST 2
  88. #define I8XX_P2_LVDS_SLOW 14
  89. #define I8XX_P2_LVDS_FAST 7
  90. #define I8XX_P2_SLOW_LIMIT 165000
  91. #define I9XX_DOT_MIN 20000
  92. #define I9XX_DOT_MAX 400000
  93. #define I9XX_VCO_MIN 1400000
  94. #define I9XX_VCO_MAX 2800000
  95. #define IGD_VCO_MIN 1700000
  96. #define IGD_VCO_MAX 3500000
  97. #define I9XX_N_MIN 1
  98. #define I9XX_N_MAX 6
  99. /* IGD's Ncounter is a ring counter */
  100. #define IGD_N_MIN 3
  101. #define IGD_N_MAX 6
  102. #define I9XX_M_MIN 70
  103. #define I9XX_M_MAX 120
  104. #define IGD_M_MIN 2
  105. #define IGD_M_MAX 256
  106. #define I9XX_M1_MIN 10
  107. #define I9XX_M1_MAX 22
  108. #define I9XX_M2_MIN 5
  109. #define I9XX_M2_MAX 9
  110. /* IGD M1 is reserved, and must be 0 */
  111. #define IGD_M1_MIN 0
  112. #define IGD_M1_MAX 0
  113. #define IGD_M2_MIN 0
  114. #define IGD_M2_MAX 254
  115. #define I9XX_P_SDVO_DAC_MIN 5
  116. #define I9XX_P_SDVO_DAC_MAX 80
  117. #define I9XX_P_LVDS_MIN 7
  118. #define I9XX_P_LVDS_MAX 98
  119. #define IGD_P_LVDS_MIN 7
  120. #define IGD_P_LVDS_MAX 112
  121. #define I9XX_P1_MIN 1
  122. #define I9XX_P1_MAX 8
  123. #define I9XX_P2_SDVO_DAC_SLOW 10
  124. #define I9XX_P2_SDVO_DAC_FAST 5
  125. #define I9XX_P2_SDVO_DAC_SLOW_LIMIT 200000
  126. #define I9XX_P2_LVDS_SLOW 14
  127. #define I9XX_P2_LVDS_FAST 7
  128. #define I9XX_P2_LVDS_SLOW_LIMIT 112000
  129. /*The parameter is for SDVO on G4x platform*/
  130. #define G4X_DOT_SDVO_MIN 25000
  131. #define G4X_DOT_SDVO_MAX 270000
  132. #define G4X_VCO_MIN 1750000
  133. #define G4X_VCO_MAX 3500000
  134. #define G4X_N_SDVO_MIN 1
  135. #define G4X_N_SDVO_MAX 4
  136. #define G4X_M_SDVO_MIN 104
  137. #define G4X_M_SDVO_MAX 138
  138. #define G4X_M1_SDVO_MIN 17
  139. #define G4X_M1_SDVO_MAX 23
  140. #define G4X_M2_SDVO_MIN 5
  141. #define G4X_M2_SDVO_MAX 11
  142. #define G4X_P_SDVO_MIN 10
  143. #define G4X_P_SDVO_MAX 30
  144. #define G4X_P1_SDVO_MIN 1
  145. #define G4X_P1_SDVO_MAX 3
  146. #define G4X_P2_SDVO_SLOW 10
  147. #define G4X_P2_SDVO_FAST 10
  148. #define G4X_P2_SDVO_LIMIT 270000
  149. /*The parameter is for HDMI_DAC on G4x platform*/
  150. #define G4X_DOT_HDMI_DAC_MIN 22000
  151. #define G4X_DOT_HDMI_DAC_MAX 400000
  152. #define G4X_N_HDMI_DAC_MIN 1
  153. #define G4X_N_HDMI_DAC_MAX 4
  154. #define G4X_M_HDMI_DAC_MIN 104
  155. #define G4X_M_HDMI_DAC_MAX 138
  156. #define G4X_M1_HDMI_DAC_MIN 16
  157. #define G4X_M1_HDMI_DAC_MAX 23
  158. #define G4X_M2_HDMI_DAC_MIN 5
  159. #define G4X_M2_HDMI_DAC_MAX 11
  160. #define G4X_P_HDMI_DAC_MIN 5
  161. #define G4X_P_HDMI_DAC_MAX 80
  162. #define G4X_P1_HDMI_DAC_MIN 1
  163. #define G4X_P1_HDMI_DAC_MAX 8
  164. #define G4X_P2_HDMI_DAC_SLOW 10
  165. #define G4X_P2_HDMI_DAC_FAST 5
  166. #define G4X_P2_HDMI_DAC_LIMIT 165000
  167. /*The parameter is for SINGLE_CHANNEL_LVDS on G4x platform*/
  168. #define G4X_DOT_SINGLE_CHANNEL_LVDS_MIN 20000
  169. #define G4X_DOT_SINGLE_CHANNEL_LVDS_MAX 115000
  170. #define G4X_N_SINGLE_CHANNEL_LVDS_MIN 1
  171. #define G4X_N_SINGLE_CHANNEL_LVDS_MAX 3
  172. #define G4X_M_SINGLE_CHANNEL_LVDS_MIN 104
  173. #define G4X_M_SINGLE_CHANNEL_LVDS_MAX 138
  174. #define G4X_M1_SINGLE_CHANNEL_LVDS_MIN 17
  175. #define G4X_M1_SINGLE_CHANNEL_LVDS_MAX 23
  176. #define G4X_M2_SINGLE_CHANNEL_LVDS_MIN 5
  177. #define G4X_M2_SINGLE_CHANNEL_LVDS_MAX 11
  178. #define G4X_P_SINGLE_CHANNEL_LVDS_MIN 28
  179. #define G4X_P_SINGLE_CHANNEL_LVDS_MAX 112
  180. #define G4X_P1_SINGLE_CHANNEL_LVDS_MIN 2
  181. #define G4X_P1_SINGLE_CHANNEL_LVDS_MAX 8
  182. #define G4X_P2_SINGLE_CHANNEL_LVDS_SLOW 14
  183. #define G4X_P2_SINGLE_CHANNEL_LVDS_FAST 14
  184. #define G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT 0
  185. /*The parameter is for DUAL_CHANNEL_LVDS on G4x platform*/
  186. #define G4X_DOT_DUAL_CHANNEL_LVDS_MIN 80000
  187. #define G4X_DOT_DUAL_CHANNEL_LVDS_MAX 224000
  188. #define G4X_N_DUAL_CHANNEL_LVDS_MIN 1
  189. #define G4X_N_DUAL_CHANNEL_LVDS_MAX 3
  190. #define G4X_M_DUAL_CHANNEL_LVDS_MIN 104
  191. #define G4X_M_DUAL_CHANNEL_LVDS_MAX 138
  192. #define G4X_M1_DUAL_CHANNEL_LVDS_MIN 17
  193. #define G4X_M1_DUAL_CHANNEL_LVDS_MAX 23
  194. #define G4X_M2_DUAL_CHANNEL_LVDS_MIN 5
  195. #define G4X_M2_DUAL_CHANNEL_LVDS_MAX 11
  196. #define G4X_P_DUAL_CHANNEL_LVDS_MIN 14
  197. #define G4X_P_DUAL_CHANNEL_LVDS_MAX 42
  198. #define G4X_P1_DUAL_CHANNEL_LVDS_MIN 2
  199. #define G4X_P1_DUAL_CHANNEL_LVDS_MAX 6
  200. #define G4X_P2_DUAL_CHANNEL_LVDS_SLOW 7
  201. #define G4X_P2_DUAL_CHANNEL_LVDS_FAST 7
  202. #define G4X_P2_DUAL_CHANNEL_LVDS_LIMIT 0
  203. /*The parameter is for DISPLAY PORT on G4x platform*/
  204. #define G4X_DOT_DISPLAY_PORT_MIN 161670
  205. #define G4X_DOT_DISPLAY_PORT_MAX 227000
  206. #define G4X_N_DISPLAY_PORT_MIN 1
  207. #define G4X_N_DISPLAY_PORT_MAX 2
  208. #define G4X_M_DISPLAY_PORT_MIN 97
  209. #define G4X_M_DISPLAY_PORT_MAX 108
  210. #define G4X_M1_DISPLAY_PORT_MIN 0x10
  211. #define G4X_M1_DISPLAY_PORT_MAX 0x12
  212. #define G4X_M2_DISPLAY_PORT_MIN 0x05
  213. #define G4X_M2_DISPLAY_PORT_MAX 0x06
  214. #define G4X_P_DISPLAY_PORT_MIN 10
  215. #define G4X_P_DISPLAY_PORT_MAX 20
  216. #define G4X_P1_DISPLAY_PORT_MIN 1
  217. #define G4X_P1_DISPLAY_PORT_MAX 2
  218. #define G4X_P2_DISPLAY_PORT_SLOW 10
  219. #define G4X_P2_DISPLAY_PORT_FAST 10
  220. #define G4X_P2_DISPLAY_PORT_LIMIT 0
  221. /* IGDNG */
  222. /* as we calculate clock using (register_value + 2) for
  223. N/M1/M2, so here the range value for them is (actual_value-2).
  224. */
  225. #define IGDNG_DOT_MIN 25000
  226. #define IGDNG_DOT_MAX 350000
  227. #define IGDNG_VCO_MIN 1760000
  228. #define IGDNG_VCO_MAX 3510000
  229. #define IGDNG_N_MIN 1
  230. #define IGDNG_N_MAX 5
  231. #define IGDNG_M_MIN 79
  232. #define IGDNG_M_MAX 118
  233. #define IGDNG_M1_MIN 12
  234. #define IGDNG_M1_MAX 23
  235. #define IGDNG_M2_MIN 5
  236. #define IGDNG_M2_MAX 9
  237. #define IGDNG_P_SDVO_DAC_MIN 5
  238. #define IGDNG_P_SDVO_DAC_MAX 80
  239. #define IGDNG_P_LVDS_MIN 28
  240. #define IGDNG_P_LVDS_MAX 112
  241. #define IGDNG_P1_MIN 1
  242. #define IGDNG_P1_MAX 8
  243. #define IGDNG_P2_SDVO_DAC_SLOW 10
  244. #define IGDNG_P2_SDVO_DAC_FAST 5
  245. #define IGDNG_P2_LVDS_SLOW 14 /* single channel */
  246. #define IGDNG_P2_LVDS_FAST 7 /* double channel */
  247. #define IGDNG_P2_DOT_LIMIT 225000 /* 225Mhz */
  248. static bool
  249. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  250. int target, int refclk, intel_clock_t *best_clock);
  251. static bool
  252. intel_find_best_reduced_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  253. int target, int refclk, intel_clock_t *best_clock);
  254. static bool
  255. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  256. int target, int refclk, intel_clock_t *best_clock);
  257. static bool
  258. intel_igdng_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  259. int target, int refclk, intel_clock_t *best_clock);
  260. static bool
  261. intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc,
  262. int target, int refclk, intel_clock_t *best_clock);
  263. static bool
  264. intel_find_pll_igdng_dp(const intel_limit_t *, struct drm_crtc *crtc,
  265. int target, int refclk, intel_clock_t *best_clock);
  266. static const intel_limit_t intel_limits_i8xx_dvo = {
  267. .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
  268. .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
  269. .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
  270. .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
  271. .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
  272. .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
  273. .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
  274. .p1 = { .min = I8XX_P1_MIN, .max = I8XX_P1_MAX },
  275. .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
  276. .p2_slow = I8XX_P2_SLOW, .p2_fast = I8XX_P2_FAST },
  277. .find_pll = intel_find_best_PLL,
  278. .find_reduced_pll = intel_find_best_reduced_PLL,
  279. };
  280. static const intel_limit_t intel_limits_i8xx_lvds = {
  281. .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
  282. .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
  283. .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
  284. .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
  285. .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
  286. .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
  287. .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
  288. .p1 = { .min = I8XX_P1_LVDS_MIN, .max = I8XX_P1_LVDS_MAX },
  289. .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
  290. .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST },
  291. .find_pll = intel_find_best_PLL,
  292. .find_reduced_pll = intel_find_best_reduced_PLL,
  293. };
  294. static const intel_limit_t intel_limits_i9xx_sdvo = {
  295. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  296. .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
  297. .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
  298. .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
  299. .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
  300. .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
  301. .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX },
  302. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  303. .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
  304. .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
  305. .find_pll = intel_find_best_PLL,
  306. .find_reduced_pll = intel_find_best_reduced_PLL,
  307. };
  308. static const intel_limit_t intel_limits_i9xx_lvds = {
  309. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  310. .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
  311. .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
  312. .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
  313. .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
  314. .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
  315. .p = { .min = I9XX_P_LVDS_MIN, .max = I9XX_P_LVDS_MAX },
  316. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  317. /* The single-channel range is 25-112Mhz, and dual-channel
  318. * is 80-224Mhz. Prefer single channel as much as possible.
  319. */
  320. .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
  321. .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST },
  322. .find_pll = intel_find_best_PLL,
  323. .find_reduced_pll = intel_find_best_reduced_PLL,
  324. };
  325. /* below parameter and function is for G4X Chipset Family*/
  326. static const intel_limit_t intel_limits_g4x_sdvo = {
  327. .dot = { .min = G4X_DOT_SDVO_MIN, .max = G4X_DOT_SDVO_MAX },
  328. .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
  329. .n = { .min = G4X_N_SDVO_MIN, .max = G4X_N_SDVO_MAX },
  330. .m = { .min = G4X_M_SDVO_MIN, .max = G4X_M_SDVO_MAX },
  331. .m1 = { .min = G4X_M1_SDVO_MIN, .max = G4X_M1_SDVO_MAX },
  332. .m2 = { .min = G4X_M2_SDVO_MIN, .max = G4X_M2_SDVO_MAX },
  333. .p = { .min = G4X_P_SDVO_MIN, .max = G4X_P_SDVO_MAX },
  334. .p1 = { .min = G4X_P1_SDVO_MIN, .max = G4X_P1_SDVO_MAX},
  335. .p2 = { .dot_limit = G4X_P2_SDVO_LIMIT,
  336. .p2_slow = G4X_P2_SDVO_SLOW,
  337. .p2_fast = G4X_P2_SDVO_FAST
  338. },
  339. .find_pll = intel_g4x_find_best_PLL,
  340. .find_reduced_pll = intel_g4x_find_best_PLL,
  341. };
  342. static const intel_limit_t intel_limits_g4x_hdmi = {
  343. .dot = { .min = G4X_DOT_HDMI_DAC_MIN, .max = G4X_DOT_HDMI_DAC_MAX },
  344. .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
  345. .n = { .min = G4X_N_HDMI_DAC_MIN, .max = G4X_N_HDMI_DAC_MAX },
  346. .m = { .min = G4X_M_HDMI_DAC_MIN, .max = G4X_M_HDMI_DAC_MAX },
  347. .m1 = { .min = G4X_M1_HDMI_DAC_MIN, .max = G4X_M1_HDMI_DAC_MAX },
  348. .m2 = { .min = G4X_M2_HDMI_DAC_MIN, .max = G4X_M2_HDMI_DAC_MAX },
  349. .p = { .min = G4X_P_HDMI_DAC_MIN, .max = G4X_P_HDMI_DAC_MAX },
  350. .p1 = { .min = G4X_P1_HDMI_DAC_MIN, .max = G4X_P1_HDMI_DAC_MAX},
  351. .p2 = { .dot_limit = G4X_P2_HDMI_DAC_LIMIT,
  352. .p2_slow = G4X_P2_HDMI_DAC_SLOW,
  353. .p2_fast = G4X_P2_HDMI_DAC_FAST
  354. },
  355. .find_pll = intel_g4x_find_best_PLL,
  356. .find_reduced_pll = intel_g4x_find_best_PLL,
  357. };
  358. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  359. .dot = { .min = G4X_DOT_SINGLE_CHANNEL_LVDS_MIN,
  360. .max = G4X_DOT_SINGLE_CHANNEL_LVDS_MAX },
  361. .vco = { .min = G4X_VCO_MIN,
  362. .max = G4X_VCO_MAX },
  363. .n = { .min = G4X_N_SINGLE_CHANNEL_LVDS_MIN,
  364. .max = G4X_N_SINGLE_CHANNEL_LVDS_MAX },
  365. .m = { .min = G4X_M_SINGLE_CHANNEL_LVDS_MIN,
  366. .max = G4X_M_SINGLE_CHANNEL_LVDS_MAX },
  367. .m1 = { .min = G4X_M1_SINGLE_CHANNEL_LVDS_MIN,
  368. .max = G4X_M1_SINGLE_CHANNEL_LVDS_MAX },
  369. .m2 = { .min = G4X_M2_SINGLE_CHANNEL_LVDS_MIN,
  370. .max = G4X_M2_SINGLE_CHANNEL_LVDS_MAX },
  371. .p = { .min = G4X_P_SINGLE_CHANNEL_LVDS_MIN,
  372. .max = G4X_P_SINGLE_CHANNEL_LVDS_MAX },
  373. .p1 = { .min = G4X_P1_SINGLE_CHANNEL_LVDS_MIN,
  374. .max = G4X_P1_SINGLE_CHANNEL_LVDS_MAX },
  375. .p2 = { .dot_limit = G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT,
  376. .p2_slow = G4X_P2_SINGLE_CHANNEL_LVDS_SLOW,
  377. .p2_fast = G4X_P2_SINGLE_CHANNEL_LVDS_FAST
  378. },
  379. .find_pll = intel_g4x_find_best_PLL,
  380. .find_reduced_pll = intel_g4x_find_best_PLL,
  381. };
  382. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  383. .dot = { .min = G4X_DOT_DUAL_CHANNEL_LVDS_MIN,
  384. .max = G4X_DOT_DUAL_CHANNEL_LVDS_MAX },
  385. .vco = { .min = G4X_VCO_MIN,
  386. .max = G4X_VCO_MAX },
  387. .n = { .min = G4X_N_DUAL_CHANNEL_LVDS_MIN,
  388. .max = G4X_N_DUAL_CHANNEL_LVDS_MAX },
  389. .m = { .min = G4X_M_DUAL_CHANNEL_LVDS_MIN,
  390. .max = G4X_M_DUAL_CHANNEL_LVDS_MAX },
  391. .m1 = { .min = G4X_M1_DUAL_CHANNEL_LVDS_MIN,
  392. .max = G4X_M1_DUAL_CHANNEL_LVDS_MAX },
  393. .m2 = { .min = G4X_M2_DUAL_CHANNEL_LVDS_MIN,
  394. .max = G4X_M2_DUAL_CHANNEL_LVDS_MAX },
  395. .p = { .min = G4X_P_DUAL_CHANNEL_LVDS_MIN,
  396. .max = G4X_P_DUAL_CHANNEL_LVDS_MAX },
  397. .p1 = { .min = G4X_P1_DUAL_CHANNEL_LVDS_MIN,
  398. .max = G4X_P1_DUAL_CHANNEL_LVDS_MAX },
  399. .p2 = { .dot_limit = G4X_P2_DUAL_CHANNEL_LVDS_LIMIT,
  400. .p2_slow = G4X_P2_DUAL_CHANNEL_LVDS_SLOW,
  401. .p2_fast = G4X_P2_DUAL_CHANNEL_LVDS_FAST
  402. },
  403. .find_pll = intel_g4x_find_best_PLL,
  404. .find_reduced_pll = intel_g4x_find_best_PLL,
  405. };
  406. static const intel_limit_t intel_limits_g4x_display_port = {
  407. .dot = { .min = G4X_DOT_DISPLAY_PORT_MIN,
  408. .max = G4X_DOT_DISPLAY_PORT_MAX },
  409. .vco = { .min = G4X_VCO_MIN,
  410. .max = G4X_VCO_MAX},
  411. .n = { .min = G4X_N_DISPLAY_PORT_MIN,
  412. .max = G4X_N_DISPLAY_PORT_MAX },
  413. .m = { .min = G4X_M_DISPLAY_PORT_MIN,
  414. .max = G4X_M_DISPLAY_PORT_MAX },
  415. .m1 = { .min = G4X_M1_DISPLAY_PORT_MIN,
  416. .max = G4X_M1_DISPLAY_PORT_MAX },
  417. .m2 = { .min = G4X_M2_DISPLAY_PORT_MIN,
  418. .max = G4X_M2_DISPLAY_PORT_MAX },
  419. .p = { .min = G4X_P_DISPLAY_PORT_MIN,
  420. .max = G4X_P_DISPLAY_PORT_MAX },
  421. .p1 = { .min = G4X_P1_DISPLAY_PORT_MIN,
  422. .max = G4X_P1_DISPLAY_PORT_MAX},
  423. .p2 = { .dot_limit = G4X_P2_DISPLAY_PORT_LIMIT,
  424. .p2_slow = G4X_P2_DISPLAY_PORT_SLOW,
  425. .p2_fast = G4X_P2_DISPLAY_PORT_FAST },
  426. .find_pll = intel_find_pll_g4x_dp,
  427. };
  428. static const intel_limit_t intel_limits_igd_sdvo = {
  429. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX},
  430. .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX },
  431. .n = { .min = IGD_N_MIN, .max = IGD_N_MAX },
  432. .m = { .min = IGD_M_MIN, .max = IGD_M_MAX },
  433. .m1 = { .min = IGD_M1_MIN, .max = IGD_M1_MAX },
  434. .m2 = { .min = IGD_M2_MIN, .max = IGD_M2_MAX },
  435. .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX },
  436. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  437. .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
  438. .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
  439. .find_pll = intel_find_best_PLL,
  440. .find_reduced_pll = intel_find_best_reduced_PLL,
  441. };
  442. static const intel_limit_t intel_limits_igd_lvds = {
  443. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  444. .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX },
  445. .n = { .min = IGD_N_MIN, .max = IGD_N_MAX },
  446. .m = { .min = IGD_M_MIN, .max = IGD_M_MAX },
  447. .m1 = { .min = IGD_M1_MIN, .max = IGD_M1_MAX },
  448. .m2 = { .min = IGD_M2_MIN, .max = IGD_M2_MAX },
  449. .p = { .min = IGD_P_LVDS_MIN, .max = IGD_P_LVDS_MAX },
  450. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  451. /* IGD only supports single-channel mode. */
  452. .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
  453. .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_SLOW },
  454. .find_pll = intel_find_best_PLL,
  455. .find_reduced_pll = intel_find_best_reduced_PLL,
  456. };
  457. static const intel_limit_t intel_limits_igdng_sdvo = {
  458. .dot = { .min = IGDNG_DOT_MIN, .max = IGDNG_DOT_MAX },
  459. .vco = { .min = IGDNG_VCO_MIN, .max = IGDNG_VCO_MAX },
  460. .n = { .min = IGDNG_N_MIN, .max = IGDNG_N_MAX },
  461. .m = { .min = IGDNG_M_MIN, .max = IGDNG_M_MAX },
  462. .m1 = { .min = IGDNG_M1_MIN, .max = IGDNG_M1_MAX },
  463. .m2 = { .min = IGDNG_M2_MIN, .max = IGDNG_M2_MAX },
  464. .p = { .min = IGDNG_P_SDVO_DAC_MIN, .max = IGDNG_P_SDVO_DAC_MAX },
  465. .p1 = { .min = IGDNG_P1_MIN, .max = IGDNG_P1_MAX },
  466. .p2 = { .dot_limit = IGDNG_P2_DOT_LIMIT,
  467. .p2_slow = IGDNG_P2_SDVO_DAC_SLOW,
  468. .p2_fast = IGDNG_P2_SDVO_DAC_FAST },
  469. .find_pll = intel_igdng_find_best_PLL,
  470. };
  471. static const intel_limit_t intel_limits_igdng_lvds = {
  472. .dot = { .min = IGDNG_DOT_MIN, .max = IGDNG_DOT_MAX },
  473. .vco = { .min = IGDNG_VCO_MIN, .max = IGDNG_VCO_MAX },
  474. .n = { .min = IGDNG_N_MIN, .max = IGDNG_N_MAX },
  475. .m = { .min = IGDNG_M_MIN, .max = IGDNG_M_MAX },
  476. .m1 = { .min = IGDNG_M1_MIN, .max = IGDNG_M1_MAX },
  477. .m2 = { .min = IGDNG_M2_MIN, .max = IGDNG_M2_MAX },
  478. .p = { .min = IGDNG_P_LVDS_MIN, .max = IGDNG_P_LVDS_MAX },
  479. .p1 = { .min = IGDNG_P1_MIN, .max = IGDNG_P1_MAX },
  480. .p2 = { .dot_limit = IGDNG_P2_DOT_LIMIT,
  481. .p2_slow = IGDNG_P2_LVDS_SLOW,
  482. .p2_fast = IGDNG_P2_LVDS_FAST },
  483. .find_pll = intel_igdng_find_best_PLL,
  484. };
  485. static const intel_limit_t *intel_igdng_limit(struct drm_crtc *crtc)
  486. {
  487. const intel_limit_t *limit;
  488. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  489. limit = &intel_limits_igdng_lvds;
  490. else
  491. limit = &intel_limits_igdng_sdvo;
  492. return limit;
  493. }
  494. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  495. {
  496. struct drm_device *dev = crtc->dev;
  497. struct drm_i915_private *dev_priv = dev->dev_private;
  498. const intel_limit_t *limit;
  499. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  500. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  501. LVDS_CLKB_POWER_UP)
  502. /* LVDS with dual channel */
  503. limit = &intel_limits_g4x_dual_channel_lvds;
  504. else
  505. /* LVDS with dual channel */
  506. limit = &intel_limits_g4x_single_channel_lvds;
  507. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  508. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  509. limit = &intel_limits_g4x_hdmi;
  510. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  511. limit = &intel_limits_g4x_sdvo;
  512. } else if (intel_pipe_has_type (crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  513. limit = &intel_limits_g4x_display_port;
  514. } else /* The option is for other outputs */
  515. limit = &intel_limits_i9xx_sdvo;
  516. return limit;
  517. }
  518. static const intel_limit_t *intel_limit(struct drm_crtc *crtc)
  519. {
  520. struct drm_device *dev = crtc->dev;
  521. const intel_limit_t *limit;
  522. if (IS_IGDNG(dev))
  523. limit = intel_igdng_limit(crtc);
  524. else if (IS_G4X(dev)) {
  525. limit = intel_g4x_limit(crtc);
  526. } else if (IS_I9XX(dev) && !IS_IGD(dev)) {
  527. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  528. limit = &intel_limits_i9xx_lvds;
  529. else
  530. limit = &intel_limits_i9xx_sdvo;
  531. } else if (IS_IGD(dev)) {
  532. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  533. limit = &intel_limits_igd_lvds;
  534. else
  535. limit = &intel_limits_igd_sdvo;
  536. } else {
  537. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  538. limit = &intel_limits_i8xx_lvds;
  539. else
  540. limit = &intel_limits_i8xx_dvo;
  541. }
  542. return limit;
  543. }
  544. /* m1 is reserved as 0 in IGD, n is a ring counter */
  545. static void igd_clock(int refclk, intel_clock_t *clock)
  546. {
  547. clock->m = clock->m2 + 2;
  548. clock->p = clock->p1 * clock->p2;
  549. clock->vco = refclk * clock->m / clock->n;
  550. clock->dot = clock->vco / clock->p;
  551. }
  552. static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock)
  553. {
  554. if (IS_IGD(dev)) {
  555. igd_clock(refclk, clock);
  556. return;
  557. }
  558. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  559. clock->p = clock->p1 * clock->p2;
  560. clock->vco = refclk * clock->m / (clock->n + 2);
  561. clock->dot = clock->vco / clock->p;
  562. }
  563. /**
  564. * Returns whether any output on the specified pipe is of the specified type
  565. */
  566. bool intel_pipe_has_type (struct drm_crtc *crtc, int type)
  567. {
  568. struct drm_device *dev = crtc->dev;
  569. struct drm_mode_config *mode_config = &dev->mode_config;
  570. struct drm_connector *l_entry;
  571. list_for_each_entry(l_entry, &mode_config->connector_list, head) {
  572. if (l_entry->encoder &&
  573. l_entry->encoder->crtc == crtc) {
  574. struct intel_output *intel_output = to_intel_output(l_entry);
  575. if (intel_output->type == type)
  576. return true;
  577. }
  578. }
  579. return false;
  580. }
  581. struct drm_connector *
  582. intel_pipe_get_output (struct drm_crtc *crtc)
  583. {
  584. struct drm_device *dev = crtc->dev;
  585. struct drm_mode_config *mode_config = &dev->mode_config;
  586. struct drm_connector *l_entry, *ret = NULL;
  587. list_for_each_entry(l_entry, &mode_config->connector_list, head) {
  588. if (l_entry->encoder &&
  589. l_entry->encoder->crtc == crtc) {
  590. ret = l_entry;
  591. break;
  592. }
  593. }
  594. return ret;
  595. }
  596. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  597. /**
  598. * Returns whether the given set of divisors are valid for a given refclk with
  599. * the given connectors.
  600. */
  601. static bool intel_PLL_is_valid(struct drm_crtc *crtc, intel_clock_t *clock)
  602. {
  603. const intel_limit_t *limit = intel_limit (crtc);
  604. struct drm_device *dev = crtc->dev;
  605. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  606. INTELPllInvalid ("p1 out of range\n");
  607. if (clock->p < limit->p.min || limit->p.max < clock->p)
  608. INTELPllInvalid ("p out of range\n");
  609. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  610. INTELPllInvalid ("m2 out of range\n");
  611. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  612. INTELPllInvalid ("m1 out of range\n");
  613. if (clock->m1 <= clock->m2 && !IS_IGD(dev))
  614. INTELPllInvalid ("m1 <= m2\n");
  615. if (clock->m < limit->m.min || limit->m.max < clock->m)
  616. INTELPllInvalid ("m out of range\n");
  617. if (clock->n < limit->n.min || limit->n.max < clock->n)
  618. INTELPllInvalid ("n out of range\n");
  619. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  620. INTELPllInvalid ("vco out of range\n");
  621. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  622. * connector, etc., rather than just a single range.
  623. */
  624. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  625. INTELPllInvalid ("dot out of range\n");
  626. return true;
  627. }
  628. static bool
  629. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  630. int target, int refclk, intel_clock_t *best_clock)
  631. {
  632. struct drm_device *dev = crtc->dev;
  633. struct drm_i915_private *dev_priv = dev->dev_private;
  634. intel_clock_t clock;
  635. int err = target;
  636. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  637. (I915_READ(LVDS)) != 0) {
  638. /*
  639. * For LVDS, if the panel is on, just rely on its current
  640. * settings for dual-channel. We haven't figured out how to
  641. * reliably set up different single/dual channel state, if we
  642. * even can.
  643. */
  644. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  645. LVDS_CLKB_POWER_UP)
  646. clock.p2 = limit->p2.p2_fast;
  647. else
  648. clock.p2 = limit->p2.p2_slow;
  649. } else {
  650. if (target < limit->p2.dot_limit)
  651. clock.p2 = limit->p2.p2_slow;
  652. else
  653. clock.p2 = limit->p2.p2_fast;
  654. }
  655. memset (best_clock, 0, sizeof (*best_clock));
  656. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  657. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  658. clock.m1++) {
  659. for (clock.m2 = limit->m2.min;
  660. clock.m2 <= limit->m2.max; clock.m2++) {
  661. /* m1 is always 0 in IGD */
  662. if (clock.m2 >= clock.m1 && !IS_IGD(dev))
  663. break;
  664. for (clock.n = limit->n.min;
  665. clock.n <= limit->n.max; clock.n++) {
  666. int this_err;
  667. intel_clock(dev, refclk, &clock);
  668. if (!intel_PLL_is_valid(crtc, &clock))
  669. continue;
  670. this_err = abs(clock.dot - target);
  671. if (this_err < err) {
  672. *best_clock = clock;
  673. err = this_err;
  674. }
  675. }
  676. }
  677. }
  678. }
  679. return (err != target);
  680. }
  681. static bool
  682. intel_find_best_reduced_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  683. int target, int refclk, intel_clock_t *best_clock)
  684. {
  685. struct drm_device *dev = crtc->dev;
  686. intel_clock_t clock;
  687. int err = target;
  688. bool found = false;
  689. memcpy(&clock, best_clock, sizeof(intel_clock_t));
  690. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  691. for (clock.m2 = limit->m2.min; clock.m2 <= limit->m2.max; clock.m2++) {
  692. /* m1 is always 0 in IGD */
  693. if (clock.m2 >= clock.m1 && !IS_IGD(dev))
  694. break;
  695. for (clock.n = limit->n.min; clock.n <= limit->n.max;
  696. clock.n++) {
  697. int this_err;
  698. intel_clock(dev, refclk, &clock);
  699. if (!intel_PLL_is_valid(crtc, &clock))
  700. continue;
  701. this_err = abs(clock.dot - target);
  702. if (this_err < err) {
  703. *best_clock = clock;
  704. err = this_err;
  705. found = true;
  706. }
  707. }
  708. }
  709. }
  710. return found;
  711. }
  712. static bool
  713. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  714. int target, int refclk, intel_clock_t *best_clock)
  715. {
  716. struct drm_device *dev = crtc->dev;
  717. struct drm_i915_private *dev_priv = dev->dev_private;
  718. intel_clock_t clock;
  719. int max_n;
  720. bool found;
  721. /* approximately equals target * 0.00488 */
  722. int err_most = (target >> 8) + (target >> 10);
  723. found = false;
  724. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  725. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  726. LVDS_CLKB_POWER_UP)
  727. clock.p2 = limit->p2.p2_fast;
  728. else
  729. clock.p2 = limit->p2.p2_slow;
  730. } else {
  731. if (target < limit->p2.dot_limit)
  732. clock.p2 = limit->p2.p2_slow;
  733. else
  734. clock.p2 = limit->p2.p2_fast;
  735. }
  736. memset(best_clock, 0, sizeof(*best_clock));
  737. max_n = limit->n.max;
  738. /* based on hardware requriment prefer smaller n to precision */
  739. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  740. /* based on hardware requirment prefere larger m1,m2 */
  741. for (clock.m1 = limit->m1.max;
  742. clock.m1 >= limit->m1.min; clock.m1--) {
  743. for (clock.m2 = limit->m2.max;
  744. clock.m2 >= limit->m2.min; clock.m2--) {
  745. for (clock.p1 = limit->p1.max;
  746. clock.p1 >= limit->p1.min; clock.p1--) {
  747. int this_err;
  748. intel_clock(dev, refclk, &clock);
  749. if (!intel_PLL_is_valid(crtc, &clock))
  750. continue;
  751. this_err = abs(clock.dot - target) ;
  752. if (this_err < err_most) {
  753. *best_clock = clock;
  754. err_most = this_err;
  755. max_n = clock.n;
  756. found = true;
  757. }
  758. }
  759. }
  760. }
  761. }
  762. return found;
  763. }
  764. static bool
  765. intel_find_pll_igdng_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  766. int target, int refclk, intel_clock_t *best_clock)
  767. {
  768. struct drm_device *dev = crtc->dev;
  769. intel_clock_t clock;
  770. if (target < 200000) {
  771. clock.n = 1;
  772. clock.p1 = 2;
  773. clock.p2 = 10;
  774. clock.m1 = 12;
  775. clock.m2 = 9;
  776. } else {
  777. clock.n = 2;
  778. clock.p1 = 1;
  779. clock.p2 = 10;
  780. clock.m1 = 14;
  781. clock.m2 = 8;
  782. }
  783. intel_clock(dev, refclk, &clock);
  784. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  785. return true;
  786. }
  787. static bool
  788. intel_igdng_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  789. int target, int refclk, intel_clock_t *best_clock)
  790. {
  791. struct drm_device *dev = crtc->dev;
  792. struct drm_i915_private *dev_priv = dev->dev_private;
  793. intel_clock_t clock;
  794. int err_most = 47;
  795. int err_min = 10000;
  796. /* eDP has only 2 clock choice, no n/m/p setting */
  797. if (HAS_eDP)
  798. return true;
  799. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  800. return intel_find_pll_igdng_dp(limit, crtc, target,
  801. refclk, best_clock);
  802. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  803. if ((I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) ==
  804. LVDS_CLKB_POWER_UP)
  805. clock.p2 = limit->p2.p2_fast;
  806. else
  807. clock.p2 = limit->p2.p2_slow;
  808. } else {
  809. if (target < limit->p2.dot_limit)
  810. clock.p2 = limit->p2.p2_slow;
  811. else
  812. clock.p2 = limit->p2.p2_fast;
  813. }
  814. memset(best_clock, 0, sizeof(*best_clock));
  815. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  816. /* based on hardware requriment prefer smaller n to precision */
  817. for (clock.n = limit->n.min; clock.n <= limit->n.max; clock.n++) {
  818. /* based on hardware requirment prefere larger m1,m2 */
  819. for (clock.m1 = limit->m1.max;
  820. clock.m1 >= limit->m1.min; clock.m1--) {
  821. for (clock.m2 = limit->m2.max;
  822. clock.m2 >= limit->m2.min; clock.m2--) {
  823. int this_err;
  824. intel_clock(dev, refclk, &clock);
  825. if (!intel_PLL_is_valid(crtc, &clock))
  826. continue;
  827. this_err = abs((10000 - (target*10000/clock.dot)));
  828. if (this_err < err_most) {
  829. *best_clock = clock;
  830. /* found on first matching */
  831. goto out;
  832. } else if (this_err < err_min) {
  833. *best_clock = clock;
  834. err_min = this_err;
  835. }
  836. }
  837. }
  838. }
  839. }
  840. out:
  841. return true;
  842. }
  843. /* DisplayPort has only two frequencies, 162MHz and 270MHz */
  844. static bool
  845. intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  846. int target, int refclk, intel_clock_t *best_clock)
  847. {
  848. intel_clock_t clock;
  849. if (target < 200000) {
  850. clock.p1 = 2;
  851. clock.p2 = 10;
  852. clock.n = 2;
  853. clock.m1 = 23;
  854. clock.m2 = 8;
  855. } else {
  856. clock.p1 = 1;
  857. clock.p2 = 10;
  858. clock.n = 1;
  859. clock.m1 = 14;
  860. clock.m2 = 2;
  861. }
  862. clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
  863. clock.p = (clock.p1 * clock.p2);
  864. clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
  865. clock.vco = 0;
  866. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  867. return true;
  868. }
  869. void
  870. intel_wait_for_vblank(struct drm_device *dev)
  871. {
  872. /* Wait for 20ms, i.e. one cycle at 50hz. */
  873. mdelay(20);
  874. }
  875. /* Parameters have changed, update FBC info */
  876. static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  877. {
  878. struct drm_device *dev = crtc->dev;
  879. struct drm_i915_private *dev_priv = dev->dev_private;
  880. struct drm_framebuffer *fb = crtc->fb;
  881. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  882. struct drm_i915_gem_object *obj_priv = intel_fb->obj->driver_private;
  883. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  884. int plane, i;
  885. u32 fbc_ctl, fbc_ctl2;
  886. dev_priv->cfb_pitch = dev_priv->cfb_size / FBC_LL_SIZE;
  887. if (fb->pitch < dev_priv->cfb_pitch)
  888. dev_priv->cfb_pitch = fb->pitch;
  889. /* FBC_CTL wants 64B units */
  890. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  891. dev_priv->cfb_fence = obj_priv->fence_reg;
  892. dev_priv->cfb_plane = intel_crtc->plane;
  893. plane = dev_priv->cfb_plane == 0 ? FBC_CTL_PLANEA : FBC_CTL_PLANEB;
  894. /* Clear old tags */
  895. for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++)
  896. I915_WRITE(FBC_TAG + (i * 4), 0);
  897. /* Set it up... */
  898. fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | plane;
  899. if (obj_priv->tiling_mode != I915_TILING_NONE)
  900. fbc_ctl2 |= FBC_CTL_CPU_FENCE;
  901. I915_WRITE(FBC_CONTROL2, fbc_ctl2);
  902. I915_WRITE(FBC_FENCE_OFF, crtc->y);
  903. /* enable it... */
  904. fbc_ctl = FBC_CTL_EN | FBC_CTL_PERIODIC;
  905. fbc_ctl |= (dev_priv->cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT;
  906. fbc_ctl |= (interval & 0x2fff) << FBC_CTL_INTERVAL_SHIFT;
  907. if (obj_priv->tiling_mode != I915_TILING_NONE)
  908. fbc_ctl |= dev_priv->cfb_fence;
  909. I915_WRITE(FBC_CONTROL, fbc_ctl);
  910. DRM_DEBUG("enabled FBC, pitch %ld, yoff %d, plane %d, ",
  911. dev_priv->cfb_pitch, crtc->y, dev_priv->cfb_plane);
  912. }
  913. void i8xx_disable_fbc(struct drm_device *dev)
  914. {
  915. struct drm_i915_private *dev_priv = dev->dev_private;
  916. u32 fbc_ctl;
  917. if (!I915_HAS_FBC(dev))
  918. return;
  919. /* Disable compression */
  920. fbc_ctl = I915_READ(FBC_CONTROL);
  921. fbc_ctl &= ~FBC_CTL_EN;
  922. I915_WRITE(FBC_CONTROL, fbc_ctl);
  923. /* Wait for compressing bit to clear */
  924. while (I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING)
  925. ; /* nothing */
  926. intel_wait_for_vblank(dev);
  927. DRM_DEBUG("disabled FBC\n");
  928. }
  929. static bool i8xx_fbc_enabled(struct drm_crtc *crtc)
  930. {
  931. struct drm_device *dev = crtc->dev;
  932. struct drm_i915_private *dev_priv = dev->dev_private;
  933. return I915_READ(FBC_CONTROL) & FBC_CTL_EN;
  934. }
  935. static void g4x_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  936. {
  937. struct drm_device *dev = crtc->dev;
  938. struct drm_i915_private *dev_priv = dev->dev_private;
  939. struct drm_framebuffer *fb = crtc->fb;
  940. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  941. struct drm_i915_gem_object *obj_priv = intel_fb->obj->driver_private;
  942. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  943. int plane = (intel_crtc->plane == 0 ? DPFC_CTL_PLANEA :
  944. DPFC_CTL_PLANEB);
  945. unsigned long stall_watermark = 200;
  946. u32 dpfc_ctl;
  947. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  948. dev_priv->cfb_fence = obj_priv->fence_reg;
  949. dev_priv->cfb_plane = intel_crtc->plane;
  950. dpfc_ctl = plane | DPFC_SR_EN | DPFC_CTL_LIMIT_1X;
  951. if (obj_priv->tiling_mode != I915_TILING_NONE) {
  952. dpfc_ctl |= DPFC_CTL_FENCE_EN | dev_priv->cfb_fence;
  953. I915_WRITE(DPFC_CHICKEN, DPFC_HT_MODIFY);
  954. } else {
  955. I915_WRITE(DPFC_CHICKEN, ~DPFC_HT_MODIFY);
  956. }
  957. I915_WRITE(DPFC_CONTROL, dpfc_ctl);
  958. I915_WRITE(DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN |
  959. (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) |
  960. (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT));
  961. I915_WRITE(DPFC_FENCE_YOFF, crtc->y);
  962. /* enable it... */
  963. I915_WRITE(DPFC_CONTROL, I915_READ(DPFC_CONTROL) | DPFC_CTL_EN);
  964. DRM_DEBUG("enabled fbc on plane %d\n", intel_crtc->plane);
  965. }
  966. void g4x_disable_fbc(struct drm_device *dev)
  967. {
  968. struct drm_i915_private *dev_priv = dev->dev_private;
  969. u32 dpfc_ctl;
  970. /* Disable compression */
  971. dpfc_ctl = I915_READ(DPFC_CONTROL);
  972. dpfc_ctl &= ~DPFC_CTL_EN;
  973. I915_WRITE(DPFC_CONTROL, dpfc_ctl);
  974. intel_wait_for_vblank(dev);
  975. DRM_DEBUG("disabled FBC\n");
  976. }
  977. static bool g4x_fbc_enabled(struct drm_crtc *crtc)
  978. {
  979. struct drm_device *dev = crtc->dev;
  980. struct drm_i915_private *dev_priv = dev->dev_private;
  981. return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN;
  982. }
  983. /**
  984. * intel_update_fbc - enable/disable FBC as needed
  985. * @crtc: CRTC to point the compressor at
  986. * @mode: mode in use
  987. *
  988. * Set up the framebuffer compression hardware at mode set time. We
  989. * enable it if possible:
  990. * - plane A only (on pre-965)
  991. * - no pixel mulitply/line duplication
  992. * - no alpha buffer discard
  993. * - no dual wide
  994. * - framebuffer <= 2048 in width, 1536 in height
  995. *
  996. * We can't assume that any compression will take place (worst case),
  997. * so the compressed buffer has to be the same size as the uncompressed
  998. * one. It also must reside (along with the line length buffer) in
  999. * stolen memory.
  1000. *
  1001. * We need to enable/disable FBC on a global basis.
  1002. */
  1003. static void intel_update_fbc(struct drm_crtc *crtc,
  1004. struct drm_display_mode *mode)
  1005. {
  1006. struct drm_device *dev = crtc->dev;
  1007. struct drm_i915_private *dev_priv = dev->dev_private;
  1008. struct drm_framebuffer *fb = crtc->fb;
  1009. struct intel_framebuffer *intel_fb;
  1010. struct drm_i915_gem_object *obj_priv;
  1011. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1012. int plane = intel_crtc->plane;
  1013. if (!i915_powersave)
  1014. return;
  1015. if (!dev_priv->display.fbc_enabled ||
  1016. !dev_priv->display.enable_fbc ||
  1017. !dev_priv->display.disable_fbc)
  1018. return;
  1019. if (!crtc->fb)
  1020. return;
  1021. intel_fb = to_intel_framebuffer(fb);
  1022. obj_priv = intel_fb->obj->driver_private;
  1023. /*
  1024. * If FBC is already on, we just have to verify that we can
  1025. * keep it that way...
  1026. * Need to disable if:
  1027. * - changing FBC params (stride, fence, mode)
  1028. * - new fb is too large to fit in compressed buffer
  1029. * - going to an unsupported config (interlace, pixel multiply, etc.)
  1030. */
  1031. if (intel_fb->obj->size > dev_priv->cfb_size) {
  1032. DRM_DEBUG("framebuffer too large, disabling compression\n");
  1033. goto out_disable;
  1034. }
  1035. if ((mode->flags & DRM_MODE_FLAG_INTERLACE) ||
  1036. (mode->flags & DRM_MODE_FLAG_DBLSCAN)) {
  1037. DRM_DEBUG("mode incompatible with compression, disabling\n");
  1038. goto out_disable;
  1039. }
  1040. if ((mode->hdisplay > 2048) ||
  1041. (mode->vdisplay > 1536)) {
  1042. DRM_DEBUG("mode too large for compression, disabling\n");
  1043. goto out_disable;
  1044. }
  1045. if ((IS_I915GM(dev) || IS_I945GM(dev)) && plane != 0) {
  1046. DRM_DEBUG("plane not 0, disabling compression\n");
  1047. goto out_disable;
  1048. }
  1049. if (obj_priv->tiling_mode != I915_TILING_X) {
  1050. DRM_DEBUG("framebuffer not tiled, disabling compression\n");
  1051. goto out_disable;
  1052. }
  1053. if (dev_priv->display.fbc_enabled(crtc)) {
  1054. /* We can re-enable it in this case, but need to update pitch */
  1055. if (fb->pitch > dev_priv->cfb_pitch)
  1056. dev_priv->display.disable_fbc(dev);
  1057. if (obj_priv->fence_reg != dev_priv->cfb_fence)
  1058. dev_priv->display.disable_fbc(dev);
  1059. if (plane != dev_priv->cfb_plane)
  1060. dev_priv->display.disable_fbc(dev);
  1061. }
  1062. if (!dev_priv->display.fbc_enabled(crtc)) {
  1063. /* Now try to turn it back on if possible */
  1064. dev_priv->display.enable_fbc(crtc, 500);
  1065. }
  1066. return;
  1067. out_disable:
  1068. DRM_DEBUG("unsupported config, disabling FBC\n");
  1069. /* Multiple disables should be harmless */
  1070. if (dev_priv->display.fbc_enabled(crtc))
  1071. dev_priv->display.disable_fbc(dev);
  1072. }
  1073. static int
  1074. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  1075. struct drm_framebuffer *old_fb)
  1076. {
  1077. struct drm_device *dev = crtc->dev;
  1078. struct drm_i915_private *dev_priv = dev->dev_private;
  1079. struct drm_i915_master_private *master_priv;
  1080. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1081. struct intel_framebuffer *intel_fb;
  1082. struct drm_i915_gem_object *obj_priv;
  1083. struct drm_gem_object *obj;
  1084. int pipe = intel_crtc->pipe;
  1085. int plane = intel_crtc->plane;
  1086. unsigned long Start, Offset;
  1087. int dspbase = (plane == 0 ? DSPAADDR : DSPBADDR);
  1088. int dspsurf = (plane == 0 ? DSPASURF : DSPBSURF);
  1089. int dspstride = (plane == 0) ? DSPASTRIDE : DSPBSTRIDE;
  1090. int dsptileoff = (plane == 0 ? DSPATILEOFF : DSPBTILEOFF);
  1091. int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR;
  1092. u32 dspcntr, alignment;
  1093. int ret;
  1094. /* no fb bound */
  1095. if (!crtc->fb) {
  1096. DRM_DEBUG("No FB bound\n");
  1097. return 0;
  1098. }
  1099. switch (plane) {
  1100. case 0:
  1101. case 1:
  1102. break;
  1103. default:
  1104. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1105. return -EINVAL;
  1106. }
  1107. intel_fb = to_intel_framebuffer(crtc->fb);
  1108. obj = intel_fb->obj;
  1109. obj_priv = obj->driver_private;
  1110. switch (obj_priv->tiling_mode) {
  1111. case I915_TILING_NONE:
  1112. alignment = 64 * 1024;
  1113. break;
  1114. case I915_TILING_X:
  1115. /* pin() will align the object as required by fence */
  1116. alignment = 0;
  1117. break;
  1118. case I915_TILING_Y:
  1119. /* FIXME: Is this true? */
  1120. DRM_ERROR("Y tiled not allowed for scan out buffers\n");
  1121. return -EINVAL;
  1122. default:
  1123. BUG();
  1124. }
  1125. mutex_lock(&dev->struct_mutex);
  1126. ret = i915_gem_object_pin(obj, alignment);
  1127. if (ret != 0) {
  1128. mutex_unlock(&dev->struct_mutex);
  1129. return ret;
  1130. }
  1131. ret = i915_gem_object_set_to_gtt_domain(obj, 1);
  1132. if (ret != 0) {
  1133. i915_gem_object_unpin(obj);
  1134. mutex_unlock(&dev->struct_mutex);
  1135. return ret;
  1136. }
  1137. /* Install a fence for tiled scan-out. Pre-i965 always needs a fence,
  1138. * whereas 965+ only requires a fence if using framebuffer compression.
  1139. * For simplicity, we always install a fence as the cost is not that onerous.
  1140. */
  1141. if (obj_priv->fence_reg == I915_FENCE_REG_NONE &&
  1142. obj_priv->tiling_mode != I915_TILING_NONE) {
  1143. ret = i915_gem_object_get_fence_reg(obj);
  1144. if (ret != 0) {
  1145. i915_gem_object_unpin(obj);
  1146. mutex_unlock(&dev->struct_mutex);
  1147. return ret;
  1148. }
  1149. }
  1150. dspcntr = I915_READ(dspcntr_reg);
  1151. /* Mask out pixel format bits in case we change it */
  1152. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1153. switch (crtc->fb->bits_per_pixel) {
  1154. case 8:
  1155. dspcntr |= DISPPLANE_8BPP;
  1156. break;
  1157. case 16:
  1158. if (crtc->fb->depth == 15)
  1159. dspcntr |= DISPPLANE_15_16BPP;
  1160. else
  1161. dspcntr |= DISPPLANE_16BPP;
  1162. break;
  1163. case 24:
  1164. case 32:
  1165. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  1166. break;
  1167. default:
  1168. DRM_ERROR("Unknown color depth\n");
  1169. i915_gem_object_unpin(obj);
  1170. mutex_unlock(&dev->struct_mutex);
  1171. return -EINVAL;
  1172. }
  1173. if (IS_I965G(dev)) {
  1174. if (obj_priv->tiling_mode != I915_TILING_NONE)
  1175. dspcntr |= DISPPLANE_TILED;
  1176. else
  1177. dspcntr &= ~DISPPLANE_TILED;
  1178. }
  1179. if (IS_IGDNG(dev))
  1180. /* must disable */
  1181. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  1182. I915_WRITE(dspcntr_reg, dspcntr);
  1183. Start = obj_priv->gtt_offset;
  1184. Offset = y * crtc->fb->pitch + x * (crtc->fb->bits_per_pixel / 8);
  1185. DRM_DEBUG("Writing base %08lX %08lX %d %d\n", Start, Offset, x, y);
  1186. I915_WRITE(dspstride, crtc->fb->pitch);
  1187. if (IS_I965G(dev)) {
  1188. I915_WRITE(dspbase, Offset);
  1189. I915_READ(dspbase);
  1190. I915_WRITE(dspsurf, Start);
  1191. I915_READ(dspsurf);
  1192. I915_WRITE(dsptileoff, (y << 16) | x);
  1193. } else {
  1194. I915_WRITE(dspbase, Start + Offset);
  1195. I915_READ(dspbase);
  1196. }
  1197. if ((IS_I965G(dev) || plane == 0))
  1198. intel_update_fbc(crtc, &crtc->mode);
  1199. intel_wait_for_vblank(dev);
  1200. if (old_fb) {
  1201. intel_fb = to_intel_framebuffer(old_fb);
  1202. obj_priv = intel_fb->obj->driver_private;
  1203. i915_gem_object_unpin(intel_fb->obj);
  1204. }
  1205. intel_increase_pllclock(crtc, true);
  1206. mutex_unlock(&dev->struct_mutex);
  1207. if (!dev->primary->master)
  1208. return 0;
  1209. master_priv = dev->primary->master->driver_priv;
  1210. if (!master_priv->sarea_priv)
  1211. return 0;
  1212. if (pipe) {
  1213. master_priv->sarea_priv->pipeB_x = x;
  1214. master_priv->sarea_priv->pipeB_y = y;
  1215. } else {
  1216. master_priv->sarea_priv->pipeA_x = x;
  1217. master_priv->sarea_priv->pipeA_y = y;
  1218. }
  1219. return 0;
  1220. }
  1221. /* Disable the VGA plane that we never use */
  1222. static void i915_disable_vga (struct drm_device *dev)
  1223. {
  1224. struct drm_i915_private *dev_priv = dev->dev_private;
  1225. u8 sr1;
  1226. u32 vga_reg;
  1227. if (IS_IGDNG(dev))
  1228. vga_reg = CPU_VGACNTRL;
  1229. else
  1230. vga_reg = VGACNTRL;
  1231. if (I915_READ(vga_reg) & VGA_DISP_DISABLE)
  1232. return;
  1233. I915_WRITE8(VGA_SR_INDEX, 1);
  1234. sr1 = I915_READ8(VGA_SR_DATA);
  1235. I915_WRITE8(VGA_SR_DATA, sr1 | (1 << 5));
  1236. udelay(100);
  1237. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  1238. }
  1239. static void igdng_disable_pll_edp (struct drm_crtc *crtc)
  1240. {
  1241. struct drm_device *dev = crtc->dev;
  1242. struct drm_i915_private *dev_priv = dev->dev_private;
  1243. u32 dpa_ctl;
  1244. DRM_DEBUG("\n");
  1245. dpa_ctl = I915_READ(DP_A);
  1246. dpa_ctl &= ~DP_PLL_ENABLE;
  1247. I915_WRITE(DP_A, dpa_ctl);
  1248. }
  1249. static void igdng_enable_pll_edp (struct drm_crtc *crtc)
  1250. {
  1251. struct drm_device *dev = crtc->dev;
  1252. struct drm_i915_private *dev_priv = dev->dev_private;
  1253. u32 dpa_ctl;
  1254. dpa_ctl = I915_READ(DP_A);
  1255. dpa_ctl |= DP_PLL_ENABLE;
  1256. I915_WRITE(DP_A, dpa_ctl);
  1257. udelay(200);
  1258. }
  1259. static void igdng_set_pll_edp (struct drm_crtc *crtc, int clock)
  1260. {
  1261. struct drm_device *dev = crtc->dev;
  1262. struct drm_i915_private *dev_priv = dev->dev_private;
  1263. u32 dpa_ctl;
  1264. DRM_DEBUG("eDP PLL enable for clock %d\n", clock);
  1265. dpa_ctl = I915_READ(DP_A);
  1266. dpa_ctl &= ~DP_PLL_FREQ_MASK;
  1267. if (clock < 200000) {
  1268. u32 temp;
  1269. dpa_ctl |= DP_PLL_FREQ_160MHZ;
  1270. /* workaround for 160Mhz:
  1271. 1) program 0x4600c bits 15:0 = 0x8124
  1272. 2) program 0x46010 bit 0 = 1
  1273. 3) program 0x46034 bit 24 = 1
  1274. 4) program 0x64000 bit 14 = 1
  1275. */
  1276. temp = I915_READ(0x4600c);
  1277. temp &= 0xffff0000;
  1278. I915_WRITE(0x4600c, temp | 0x8124);
  1279. temp = I915_READ(0x46010);
  1280. I915_WRITE(0x46010, temp | 1);
  1281. temp = I915_READ(0x46034);
  1282. I915_WRITE(0x46034, temp | (1 << 24));
  1283. } else {
  1284. dpa_ctl |= DP_PLL_FREQ_270MHZ;
  1285. }
  1286. I915_WRITE(DP_A, dpa_ctl);
  1287. udelay(500);
  1288. }
  1289. static void igdng_crtc_dpms(struct drm_crtc *crtc, int mode)
  1290. {
  1291. struct drm_device *dev = crtc->dev;
  1292. struct drm_i915_private *dev_priv = dev->dev_private;
  1293. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1294. int pipe = intel_crtc->pipe;
  1295. int plane = intel_crtc->plane;
  1296. int pch_dpll_reg = (pipe == 0) ? PCH_DPLL_A : PCH_DPLL_B;
  1297. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  1298. int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR;
  1299. int dspbase_reg = (plane == 0) ? DSPAADDR : DSPBADDR;
  1300. int fdi_tx_reg = (pipe == 0) ? FDI_TXA_CTL : FDI_TXB_CTL;
  1301. int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL;
  1302. int fdi_rx_iir_reg = (pipe == 0) ? FDI_RXA_IIR : FDI_RXB_IIR;
  1303. int fdi_rx_imr_reg = (pipe == 0) ? FDI_RXA_IMR : FDI_RXB_IMR;
  1304. int transconf_reg = (pipe == 0) ? TRANSACONF : TRANSBCONF;
  1305. int pf_ctl_reg = (pipe == 0) ? PFA_CTL_1 : PFB_CTL_1;
  1306. int pf_win_size = (pipe == 0) ? PFA_WIN_SZ : PFB_WIN_SZ;
  1307. int pf_win_pos = (pipe == 0) ? PFA_WIN_POS : PFB_WIN_POS;
  1308. int cpu_htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
  1309. int cpu_hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
  1310. int cpu_hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
  1311. int cpu_vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
  1312. int cpu_vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
  1313. int cpu_vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
  1314. int trans_htot_reg = (pipe == 0) ? TRANS_HTOTAL_A : TRANS_HTOTAL_B;
  1315. int trans_hblank_reg = (pipe == 0) ? TRANS_HBLANK_A : TRANS_HBLANK_B;
  1316. int trans_hsync_reg = (pipe == 0) ? TRANS_HSYNC_A : TRANS_HSYNC_B;
  1317. int trans_vtot_reg = (pipe == 0) ? TRANS_VTOTAL_A : TRANS_VTOTAL_B;
  1318. int trans_vblank_reg = (pipe == 0) ? TRANS_VBLANK_A : TRANS_VBLANK_B;
  1319. int trans_vsync_reg = (pipe == 0) ? TRANS_VSYNC_A : TRANS_VSYNC_B;
  1320. u32 temp;
  1321. int tries = 5, j, n;
  1322. /* XXX: When our outputs are all unaware of DPMS modes other than off
  1323. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  1324. */
  1325. switch (mode) {
  1326. case DRM_MODE_DPMS_ON:
  1327. case DRM_MODE_DPMS_STANDBY:
  1328. case DRM_MODE_DPMS_SUSPEND:
  1329. DRM_DEBUG("crtc %d dpms on\n", pipe);
  1330. if (HAS_eDP) {
  1331. /* enable eDP PLL */
  1332. igdng_enable_pll_edp(crtc);
  1333. } else {
  1334. /* enable PCH DPLL */
  1335. temp = I915_READ(pch_dpll_reg);
  1336. if ((temp & DPLL_VCO_ENABLE) == 0) {
  1337. I915_WRITE(pch_dpll_reg, temp | DPLL_VCO_ENABLE);
  1338. I915_READ(pch_dpll_reg);
  1339. }
  1340. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  1341. temp = I915_READ(fdi_rx_reg);
  1342. I915_WRITE(fdi_rx_reg, temp | FDI_RX_PLL_ENABLE |
  1343. FDI_SEL_PCDCLK |
  1344. FDI_DP_PORT_WIDTH_X4); /* default 4 lanes */
  1345. I915_READ(fdi_rx_reg);
  1346. udelay(200);
  1347. /* Enable CPU FDI TX PLL, always on for IGDNG */
  1348. temp = I915_READ(fdi_tx_reg);
  1349. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  1350. I915_WRITE(fdi_tx_reg, temp | FDI_TX_PLL_ENABLE);
  1351. I915_READ(fdi_tx_reg);
  1352. udelay(100);
  1353. }
  1354. }
  1355. /* Enable panel fitting for LVDS */
  1356. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  1357. temp = I915_READ(pf_ctl_reg);
  1358. I915_WRITE(pf_ctl_reg, temp | PF_ENABLE | PF_FILTER_MED_3x3);
  1359. /* currently full aspect */
  1360. I915_WRITE(pf_win_pos, 0);
  1361. I915_WRITE(pf_win_size,
  1362. (dev_priv->panel_fixed_mode->hdisplay << 16) |
  1363. (dev_priv->panel_fixed_mode->vdisplay));
  1364. }
  1365. /* Enable CPU pipe */
  1366. temp = I915_READ(pipeconf_reg);
  1367. if ((temp & PIPEACONF_ENABLE) == 0) {
  1368. I915_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE);
  1369. I915_READ(pipeconf_reg);
  1370. udelay(100);
  1371. }
  1372. /* configure and enable CPU plane */
  1373. temp = I915_READ(dspcntr_reg);
  1374. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  1375. I915_WRITE(dspcntr_reg, temp | DISPLAY_PLANE_ENABLE);
  1376. /* Flush the plane changes */
  1377. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1378. }
  1379. if (!HAS_eDP) {
  1380. /* enable CPU FDI TX and PCH FDI RX */
  1381. temp = I915_READ(fdi_tx_reg);
  1382. temp |= FDI_TX_ENABLE;
  1383. temp |= FDI_DP_PORT_WIDTH_X4; /* default */
  1384. temp &= ~FDI_LINK_TRAIN_NONE;
  1385. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1386. I915_WRITE(fdi_tx_reg, temp);
  1387. I915_READ(fdi_tx_reg);
  1388. temp = I915_READ(fdi_rx_reg);
  1389. temp &= ~FDI_LINK_TRAIN_NONE;
  1390. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1391. I915_WRITE(fdi_rx_reg, temp | FDI_RX_ENABLE);
  1392. I915_READ(fdi_rx_reg);
  1393. udelay(150);
  1394. /* Train FDI. */
  1395. /* umask FDI RX Interrupt symbol_lock and bit_lock bit
  1396. for train result */
  1397. temp = I915_READ(fdi_rx_imr_reg);
  1398. temp &= ~FDI_RX_SYMBOL_LOCK;
  1399. temp &= ~FDI_RX_BIT_LOCK;
  1400. I915_WRITE(fdi_rx_imr_reg, temp);
  1401. I915_READ(fdi_rx_imr_reg);
  1402. udelay(150);
  1403. temp = I915_READ(fdi_rx_iir_reg);
  1404. DRM_DEBUG("FDI_RX_IIR 0x%x\n", temp);
  1405. if ((temp & FDI_RX_BIT_LOCK) == 0) {
  1406. for (j = 0; j < tries; j++) {
  1407. temp = I915_READ(fdi_rx_iir_reg);
  1408. DRM_DEBUG("FDI_RX_IIR 0x%x\n", temp);
  1409. if (temp & FDI_RX_BIT_LOCK)
  1410. break;
  1411. udelay(200);
  1412. }
  1413. if (j != tries)
  1414. I915_WRITE(fdi_rx_iir_reg,
  1415. temp | FDI_RX_BIT_LOCK);
  1416. else
  1417. DRM_DEBUG("train 1 fail\n");
  1418. } else {
  1419. I915_WRITE(fdi_rx_iir_reg,
  1420. temp | FDI_RX_BIT_LOCK);
  1421. DRM_DEBUG("train 1 ok 2!\n");
  1422. }
  1423. temp = I915_READ(fdi_tx_reg);
  1424. temp &= ~FDI_LINK_TRAIN_NONE;
  1425. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1426. I915_WRITE(fdi_tx_reg, temp);
  1427. temp = I915_READ(fdi_rx_reg);
  1428. temp &= ~FDI_LINK_TRAIN_NONE;
  1429. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1430. I915_WRITE(fdi_rx_reg, temp);
  1431. udelay(150);
  1432. temp = I915_READ(fdi_rx_iir_reg);
  1433. DRM_DEBUG("FDI_RX_IIR 0x%x\n", temp);
  1434. if ((temp & FDI_RX_SYMBOL_LOCK) == 0) {
  1435. for (j = 0; j < tries; j++) {
  1436. temp = I915_READ(fdi_rx_iir_reg);
  1437. DRM_DEBUG("FDI_RX_IIR 0x%x\n", temp);
  1438. if (temp & FDI_RX_SYMBOL_LOCK)
  1439. break;
  1440. udelay(200);
  1441. }
  1442. if (j != tries) {
  1443. I915_WRITE(fdi_rx_iir_reg,
  1444. temp | FDI_RX_SYMBOL_LOCK);
  1445. DRM_DEBUG("train 2 ok 1!\n");
  1446. } else
  1447. DRM_DEBUG("train 2 fail\n");
  1448. } else {
  1449. I915_WRITE(fdi_rx_iir_reg,
  1450. temp | FDI_RX_SYMBOL_LOCK);
  1451. DRM_DEBUG("train 2 ok 2!\n");
  1452. }
  1453. DRM_DEBUG("train done\n");
  1454. /* set transcoder timing */
  1455. I915_WRITE(trans_htot_reg, I915_READ(cpu_htot_reg));
  1456. I915_WRITE(trans_hblank_reg, I915_READ(cpu_hblank_reg));
  1457. I915_WRITE(trans_hsync_reg, I915_READ(cpu_hsync_reg));
  1458. I915_WRITE(trans_vtot_reg, I915_READ(cpu_vtot_reg));
  1459. I915_WRITE(trans_vblank_reg, I915_READ(cpu_vblank_reg));
  1460. I915_WRITE(trans_vsync_reg, I915_READ(cpu_vsync_reg));
  1461. /* enable PCH transcoder */
  1462. temp = I915_READ(transconf_reg);
  1463. I915_WRITE(transconf_reg, temp | TRANS_ENABLE);
  1464. I915_READ(transconf_reg);
  1465. while ((I915_READ(transconf_reg) & TRANS_STATE_ENABLE) == 0)
  1466. ;
  1467. /* enable normal */
  1468. temp = I915_READ(fdi_tx_reg);
  1469. temp &= ~FDI_LINK_TRAIN_NONE;
  1470. I915_WRITE(fdi_tx_reg, temp | FDI_LINK_TRAIN_NONE |
  1471. FDI_TX_ENHANCE_FRAME_ENABLE);
  1472. I915_READ(fdi_tx_reg);
  1473. temp = I915_READ(fdi_rx_reg);
  1474. temp &= ~FDI_LINK_TRAIN_NONE;
  1475. I915_WRITE(fdi_rx_reg, temp | FDI_LINK_TRAIN_NONE |
  1476. FDI_RX_ENHANCE_FRAME_ENABLE);
  1477. I915_READ(fdi_rx_reg);
  1478. /* wait one idle pattern time */
  1479. udelay(100);
  1480. }
  1481. intel_crtc_load_lut(crtc);
  1482. break;
  1483. case DRM_MODE_DPMS_OFF:
  1484. DRM_DEBUG("crtc %d dpms off\n", pipe);
  1485. i915_disable_vga(dev);
  1486. /* Disable display plane */
  1487. temp = I915_READ(dspcntr_reg);
  1488. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  1489. I915_WRITE(dspcntr_reg, temp & ~DISPLAY_PLANE_ENABLE);
  1490. /* Flush the plane changes */
  1491. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1492. I915_READ(dspbase_reg);
  1493. }
  1494. /* disable cpu pipe, disable after all planes disabled */
  1495. temp = I915_READ(pipeconf_reg);
  1496. if ((temp & PIPEACONF_ENABLE) != 0) {
  1497. I915_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE);
  1498. I915_READ(pipeconf_reg);
  1499. n = 0;
  1500. /* wait for cpu pipe off, pipe state */
  1501. while ((I915_READ(pipeconf_reg) & I965_PIPECONF_ACTIVE) != 0) {
  1502. n++;
  1503. if (n < 60) {
  1504. udelay(500);
  1505. continue;
  1506. } else {
  1507. DRM_DEBUG("pipe %d off delay\n", pipe);
  1508. break;
  1509. }
  1510. }
  1511. } else
  1512. DRM_DEBUG("crtc %d is disabled\n", pipe);
  1513. if (HAS_eDP) {
  1514. igdng_disable_pll_edp(crtc);
  1515. }
  1516. /* disable CPU FDI tx and PCH FDI rx */
  1517. temp = I915_READ(fdi_tx_reg);
  1518. I915_WRITE(fdi_tx_reg, temp & ~FDI_TX_ENABLE);
  1519. I915_READ(fdi_tx_reg);
  1520. temp = I915_READ(fdi_rx_reg);
  1521. I915_WRITE(fdi_rx_reg, temp & ~FDI_RX_ENABLE);
  1522. I915_READ(fdi_rx_reg);
  1523. udelay(100);
  1524. /* still set train pattern 1 */
  1525. temp = I915_READ(fdi_tx_reg);
  1526. temp &= ~FDI_LINK_TRAIN_NONE;
  1527. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1528. I915_WRITE(fdi_tx_reg, temp);
  1529. temp = I915_READ(fdi_rx_reg);
  1530. temp &= ~FDI_LINK_TRAIN_NONE;
  1531. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1532. I915_WRITE(fdi_rx_reg, temp);
  1533. udelay(100);
  1534. /* disable PCH transcoder */
  1535. temp = I915_READ(transconf_reg);
  1536. if ((temp & TRANS_ENABLE) != 0) {
  1537. I915_WRITE(transconf_reg, temp & ~TRANS_ENABLE);
  1538. I915_READ(transconf_reg);
  1539. n = 0;
  1540. /* wait for PCH transcoder off, transcoder state */
  1541. while ((I915_READ(transconf_reg) & TRANS_STATE_ENABLE) != 0) {
  1542. n++;
  1543. if (n < 60) {
  1544. udelay(500);
  1545. continue;
  1546. } else {
  1547. DRM_DEBUG("transcoder %d off delay\n", pipe);
  1548. break;
  1549. }
  1550. }
  1551. }
  1552. /* disable PCH DPLL */
  1553. temp = I915_READ(pch_dpll_reg);
  1554. if ((temp & DPLL_VCO_ENABLE) != 0) {
  1555. I915_WRITE(pch_dpll_reg, temp & ~DPLL_VCO_ENABLE);
  1556. I915_READ(pch_dpll_reg);
  1557. }
  1558. temp = I915_READ(fdi_rx_reg);
  1559. if ((temp & FDI_RX_PLL_ENABLE) != 0) {
  1560. temp &= ~FDI_SEL_PCDCLK;
  1561. temp &= ~FDI_RX_PLL_ENABLE;
  1562. I915_WRITE(fdi_rx_reg, temp);
  1563. I915_READ(fdi_rx_reg);
  1564. }
  1565. /* Disable CPU FDI TX PLL */
  1566. temp = I915_READ(fdi_tx_reg);
  1567. if ((temp & FDI_TX_PLL_ENABLE) != 0) {
  1568. I915_WRITE(fdi_tx_reg, temp & ~FDI_TX_PLL_ENABLE);
  1569. I915_READ(fdi_tx_reg);
  1570. udelay(100);
  1571. }
  1572. /* Disable PF */
  1573. temp = I915_READ(pf_ctl_reg);
  1574. if ((temp & PF_ENABLE) != 0) {
  1575. I915_WRITE(pf_ctl_reg, temp & ~PF_ENABLE);
  1576. I915_READ(pf_ctl_reg);
  1577. }
  1578. I915_WRITE(pf_win_size, 0);
  1579. /* Wait for the clocks to turn off. */
  1580. udelay(150);
  1581. break;
  1582. }
  1583. }
  1584. static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode)
  1585. {
  1586. struct drm_device *dev = crtc->dev;
  1587. struct drm_i915_private *dev_priv = dev->dev_private;
  1588. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1589. int pipe = intel_crtc->pipe;
  1590. int plane = intel_crtc->plane;
  1591. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  1592. int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR;
  1593. int dspbase_reg = (plane == 0) ? DSPAADDR : DSPBADDR;
  1594. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  1595. u32 temp;
  1596. /* XXX: When our outputs are all unaware of DPMS modes other than off
  1597. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  1598. */
  1599. switch (mode) {
  1600. case DRM_MODE_DPMS_ON:
  1601. case DRM_MODE_DPMS_STANDBY:
  1602. case DRM_MODE_DPMS_SUSPEND:
  1603. intel_update_watermarks(dev);
  1604. /* Enable the DPLL */
  1605. temp = I915_READ(dpll_reg);
  1606. if ((temp & DPLL_VCO_ENABLE) == 0) {
  1607. I915_WRITE(dpll_reg, temp);
  1608. I915_READ(dpll_reg);
  1609. /* Wait for the clocks to stabilize. */
  1610. udelay(150);
  1611. I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  1612. I915_READ(dpll_reg);
  1613. /* Wait for the clocks to stabilize. */
  1614. udelay(150);
  1615. I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  1616. I915_READ(dpll_reg);
  1617. /* Wait for the clocks to stabilize. */
  1618. udelay(150);
  1619. }
  1620. /* Enable the pipe */
  1621. temp = I915_READ(pipeconf_reg);
  1622. if ((temp & PIPEACONF_ENABLE) == 0)
  1623. I915_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE);
  1624. /* Enable the plane */
  1625. temp = I915_READ(dspcntr_reg);
  1626. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  1627. I915_WRITE(dspcntr_reg, temp | DISPLAY_PLANE_ENABLE);
  1628. /* Flush the plane changes */
  1629. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1630. }
  1631. intel_crtc_load_lut(crtc);
  1632. if ((IS_I965G(dev) || plane == 0))
  1633. intel_update_fbc(crtc, &crtc->mode);
  1634. /* Give the overlay scaler a chance to enable if it's on this pipe */
  1635. //intel_crtc_dpms_video(crtc, true); TODO
  1636. break;
  1637. case DRM_MODE_DPMS_OFF:
  1638. intel_update_watermarks(dev);
  1639. /* Give the overlay scaler a chance to disable if it's on this pipe */
  1640. //intel_crtc_dpms_video(crtc, FALSE); TODO
  1641. if (dev_priv->cfb_plane == plane &&
  1642. dev_priv->display.disable_fbc)
  1643. dev_priv->display.disable_fbc(dev);
  1644. /* Disable the VGA plane that we never use */
  1645. i915_disable_vga(dev);
  1646. /* Disable display plane */
  1647. temp = I915_READ(dspcntr_reg);
  1648. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  1649. I915_WRITE(dspcntr_reg, temp & ~DISPLAY_PLANE_ENABLE);
  1650. /* Flush the plane changes */
  1651. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1652. I915_READ(dspbase_reg);
  1653. }
  1654. if (!IS_I9XX(dev)) {
  1655. /* Wait for vblank for the disable to take effect */
  1656. intel_wait_for_vblank(dev);
  1657. }
  1658. /* Next, disable display pipes */
  1659. temp = I915_READ(pipeconf_reg);
  1660. if ((temp & PIPEACONF_ENABLE) != 0) {
  1661. I915_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE);
  1662. I915_READ(pipeconf_reg);
  1663. }
  1664. /* Wait for vblank for the disable to take effect. */
  1665. intel_wait_for_vblank(dev);
  1666. temp = I915_READ(dpll_reg);
  1667. if ((temp & DPLL_VCO_ENABLE) != 0) {
  1668. I915_WRITE(dpll_reg, temp & ~DPLL_VCO_ENABLE);
  1669. I915_READ(dpll_reg);
  1670. }
  1671. /* Wait for the clocks to turn off. */
  1672. udelay(150);
  1673. break;
  1674. }
  1675. }
  1676. /**
  1677. * Sets the power management mode of the pipe and plane.
  1678. *
  1679. * This code should probably grow support for turning the cursor off and back
  1680. * on appropriately at the same time as we're turning the pipe off/on.
  1681. */
  1682. static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
  1683. {
  1684. struct drm_device *dev = crtc->dev;
  1685. struct drm_i915_private *dev_priv = dev->dev_private;
  1686. struct drm_i915_master_private *master_priv;
  1687. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1688. int pipe = intel_crtc->pipe;
  1689. bool enabled;
  1690. dev_priv->display.dpms(crtc, mode);
  1691. intel_crtc->dpms_mode = mode;
  1692. if (!dev->primary->master)
  1693. return;
  1694. master_priv = dev->primary->master->driver_priv;
  1695. if (!master_priv->sarea_priv)
  1696. return;
  1697. enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
  1698. switch (pipe) {
  1699. case 0:
  1700. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  1701. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  1702. break;
  1703. case 1:
  1704. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  1705. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  1706. break;
  1707. default:
  1708. DRM_ERROR("Can't update pipe %d in SAREA\n", pipe);
  1709. break;
  1710. }
  1711. }
  1712. static void intel_crtc_prepare (struct drm_crtc *crtc)
  1713. {
  1714. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  1715. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  1716. }
  1717. static void intel_crtc_commit (struct drm_crtc *crtc)
  1718. {
  1719. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  1720. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  1721. }
  1722. void intel_encoder_prepare (struct drm_encoder *encoder)
  1723. {
  1724. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  1725. /* lvds has its own version of prepare see intel_lvds_prepare */
  1726. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
  1727. }
  1728. void intel_encoder_commit (struct drm_encoder *encoder)
  1729. {
  1730. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  1731. /* lvds has its own version of commit see intel_lvds_commit */
  1732. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  1733. }
  1734. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  1735. struct drm_display_mode *mode,
  1736. struct drm_display_mode *adjusted_mode)
  1737. {
  1738. struct drm_device *dev = crtc->dev;
  1739. if (IS_IGDNG(dev)) {
  1740. /* FDI link clock is fixed at 2.7G */
  1741. if (mode->clock * 3 > 27000 * 4)
  1742. return MODE_CLOCK_HIGH;
  1743. }
  1744. return true;
  1745. }
  1746. static int i945_get_display_clock_speed(struct drm_device *dev)
  1747. {
  1748. return 400000;
  1749. }
  1750. static int i915_get_display_clock_speed(struct drm_device *dev)
  1751. {
  1752. return 333000;
  1753. }
  1754. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  1755. {
  1756. return 200000;
  1757. }
  1758. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  1759. {
  1760. u16 gcfgc = 0;
  1761. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  1762. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  1763. return 133000;
  1764. else {
  1765. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  1766. case GC_DISPLAY_CLOCK_333_MHZ:
  1767. return 333000;
  1768. default:
  1769. case GC_DISPLAY_CLOCK_190_200_MHZ:
  1770. return 190000;
  1771. }
  1772. }
  1773. }
  1774. static int i865_get_display_clock_speed(struct drm_device *dev)
  1775. {
  1776. return 266000;
  1777. }
  1778. static int i855_get_display_clock_speed(struct drm_device *dev)
  1779. {
  1780. u16 hpllcc = 0;
  1781. /* Assume that the hardware is in the high speed state. This
  1782. * should be the default.
  1783. */
  1784. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  1785. case GC_CLOCK_133_200:
  1786. case GC_CLOCK_100_200:
  1787. return 200000;
  1788. case GC_CLOCK_166_250:
  1789. return 250000;
  1790. case GC_CLOCK_100_133:
  1791. return 133000;
  1792. }
  1793. /* Shouldn't happen */
  1794. return 0;
  1795. }
  1796. static int i830_get_display_clock_speed(struct drm_device *dev)
  1797. {
  1798. return 133000;
  1799. }
  1800. /**
  1801. * Return the pipe currently connected to the panel fitter,
  1802. * or -1 if the panel fitter is not present or not in use
  1803. */
  1804. static int intel_panel_fitter_pipe (struct drm_device *dev)
  1805. {
  1806. struct drm_i915_private *dev_priv = dev->dev_private;
  1807. u32 pfit_control;
  1808. /* i830 doesn't have a panel fitter */
  1809. if (IS_I830(dev))
  1810. return -1;
  1811. pfit_control = I915_READ(PFIT_CONTROL);
  1812. /* See if the panel fitter is in use */
  1813. if ((pfit_control & PFIT_ENABLE) == 0)
  1814. return -1;
  1815. /* 965 can place panel fitter on either pipe */
  1816. if (IS_I965G(dev))
  1817. return (pfit_control >> 29) & 0x3;
  1818. /* older chips can only use pipe 1 */
  1819. return 1;
  1820. }
  1821. struct fdi_m_n {
  1822. u32 tu;
  1823. u32 gmch_m;
  1824. u32 gmch_n;
  1825. u32 link_m;
  1826. u32 link_n;
  1827. };
  1828. static void
  1829. fdi_reduce_ratio(u32 *num, u32 *den)
  1830. {
  1831. while (*num > 0xffffff || *den > 0xffffff) {
  1832. *num >>= 1;
  1833. *den >>= 1;
  1834. }
  1835. }
  1836. #define DATA_N 0x800000
  1837. #define LINK_N 0x80000
  1838. static void
  1839. igdng_compute_m_n(int bits_per_pixel, int nlanes,
  1840. int pixel_clock, int link_clock,
  1841. struct fdi_m_n *m_n)
  1842. {
  1843. u64 temp;
  1844. m_n->tu = 64; /* default size */
  1845. temp = (u64) DATA_N * pixel_clock;
  1846. temp = div_u64(temp, link_clock);
  1847. m_n->gmch_m = div_u64(temp * bits_per_pixel, nlanes);
  1848. m_n->gmch_m >>= 3; /* convert to bytes_per_pixel */
  1849. m_n->gmch_n = DATA_N;
  1850. fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  1851. temp = (u64) LINK_N * pixel_clock;
  1852. m_n->link_m = div_u64(temp, link_clock);
  1853. m_n->link_n = LINK_N;
  1854. fdi_reduce_ratio(&m_n->link_m, &m_n->link_n);
  1855. }
  1856. struct intel_watermark_params {
  1857. unsigned long fifo_size;
  1858. unsigned long max_wm;
  1859. unsigned long default_wm;
  1860. unsigned long guard_size;
  1861. unsigned long cacheline_size;
  1862. };
  1863. /* IGD has different values for various configs */
  1864. static struct intel_watermark_params igd_display_wm = {
  1865. IGD_DISPLAY_FIFO,
  1866. IGD_MAX_WM,
  1867. IGD_DFT_WM,
  1868. IGD_GUARD_WM,
  1869. IGD_FIFO_LINE_SIZE
  1870. };
  1871. static struct intel_watermark_params igd_display_hplloff_wm = {
  1872. IGD_DISPLAY_FIFO,
  1873. IGD_MAX_WM,
  1874. IGD_DFT_HPLLOFF_WM,
  1875. IGD_GUARD_WM,
  1876. IGD_FIFO_LINE_SIZE
  1877. };
  1878. static struct intel_watermark_params igd_cursor_wm = {
  1879. IGD_CURSOR_FIFO,
  1880. IGD_CURSOR_MAX_WM,
  1881. IGD_CURSOR_DFT_WM,
  1882. IGD_CURSOR_GUARD_WM,
  1883. IGD_FIFO_LINE_SIZE,
  1884. };
  1885. static struct intel_watermark_params igd_cursor_hplloff_wm = {
  1886. IGD_CURSOR_FIFO,
  1887. IGD_CURSOR_MAX_WM,
  1888. IGD_CURSOR_DFT_WM,
  1889. IGD_CURSOR_GUARD_WM,
  1890. IGD_FIFO_LINE_SIZE
  1891. };
  1892. static struct intel_watermark_params g4x_wm_info = {
  1893. G4X_FIFO_SIZE,
  1894. G4X_MAX_WM,
  1895. G4X_MAX_WM,
  1896. 2,
  1897. G4X_FIFO_LINE_SIZE,
  1898. };
  1899. static struct intel_watermark_params i945_wm_info = {
  1900. I945_FIFO_SIZE,
  1901. I915_MAX_WM,
  1902. 1,
  1903. 2,
  1904. I915_FIFO_LINE_SIZE
  1905. };
  1906. static struct intel_watermark_params i915_wm_info = {
  1907. I915_FIFO_SIZE,
  1908. I915_MAX_WM,
  1909. 1,
  1910. 2,
  1911. I915_FIFO_LINE_SIZE
  1912. };
  1913. static struct intel_watermark_params i855_wm_info = {
  1914. I855GM_FIFO_SIZE,
  1915. I915_MAX_WM,
  1916. 1,
  1917. 2,
  1918. I830_FIFO_LINE_SIZE
  1919. };
  1920. static struct intel_watermark_params i830_wm_info = {
  1921. I830_FIFO_SIZE,
  1922. I915_MAX_WM,
  1923. 1,
  1924. 2,
  1925. I830_FIFO_LINE_SIZE
  1926. };
  1927. /**
  1928. * intel_calculate_wm - calculate watermark level
  1929. * @clock_in_khz: pixel clock
  1930. * @wm: chip FIFO params
  1931. * @pixel_size: display pixel size
  1932. * @latency_ns: memory latency for the platform
  1933. *
  1934. * Calculate the watermark level (the level at which the display plane will
  1935. * start fetching from memory again). Each chip has a different display
  1936. * FIFO size and allocation, so the caller needs to figure that out and pass
  1937. * in the correct intel_watermark_params structure.
  1938. *
  1939. * As the pixel clock runs, the FIFO will be drained at a rate that depends
  1940. * on the pixel size. When it reaches the watermark level, it'll start
  1941. * fetching FIFO line sized based chunks from memory until the FIFO fills
  1942. * past the watermark point. If the FIFO drains completely, a FIFO underrun
  1943. * will occur, and a display engine hang could result.
  1944. */
  1945. static unsigned long intel_calculate_wm(unsigned long clock_in_khz,
  1946. struct intel_watermark_params *wm,
  1947. int pixel_size,
  1948. unsigned long latency_ns)
  1949. {
  1950. long entries_required, wm_size;
  1951. /*
  1952. * Note: we need to make sure we don't overflow for various clock &
  1953. * latency values.
  1954. * clocks go from a few thousand to several hundred thousand.
  1955. * latency is usually a few thousand
  1956. */
  1957. entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) /
  1958. 1000;
  1959. entries_required /= wm->cacheline_size;
  1960. DRM_DEBUG("FIFO entries required for mode: %d\n", entries_required);
  1961. wm_size = wm->fifo_size - (entries_required + wm->guard_size);
  1962. DRM_DEBUG("FIFO watermark level: %d\n", wm_size);
  1963. /* Don't promote wm_size to unsigned... */
  1964. if (wm_size > (long)wm->max_wm)
  1965. wm_size = wm->max_wm;
  1966. if (wm_size <= 0)
  1967. wm_size = wm->default_wm;
  1968. return wm_size;
  1969. }
  1970. struct cxsr_latency {
  1971. int is_desktop;
  1972. unsigned long fsb_freq;
  1973. unsigned long mem_freq;
  1974. unsigned long display_sr;
  1975. unsigned long display_hpll_disable;
  1976. unsigned long cursor_sr;
  1977. unsigned long cursor_hpll_disable;
  1978. };
  1979. static struct cxsr_latency cxsr_latency_table[] = {
  1980. {1, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
  1981. {1, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
  1982. {1, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
  1983. {1, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
  1984. {1, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
  1985. {1, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
  1986. {1, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
  1987. {1, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
  1988. {1, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
  1989. {0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
  1990. {0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
  1991. {0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
  1992. {0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
  1993. {0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
  1994. {0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
  1995. {0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
  1996. {0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
  1997. {0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
  1998. };
  1999. static struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, int fsb,
  2000. int mem)
  2001. {
  2002. int i;
  2003. struct cxsr_latency *latency;
  2004. if (fsb == 0 || mem == 0)
  2005. return NULL;
  2006. for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
  2007. latency = &cxsr_latency_table[i];
  2008. if (is_desktop == latency->is_desktop &&
  2009. fsb == latency->fsb_freq && mem == latency->mem_freq)
  2010. return latency;
  2011. }
  2012. DRM_DEBUG("Unknown FSB/MEM found, disable CxSR\n");
  2013. return NULL;
  2014. }
  2015. static void igd_disable_cxsr(struct drm_device *dev)
  2016. {
  2017. struct drm_i915_private *dev_priv = dev->dev_private;
  2018. u32 reg;
  2019. /* deactivate cxsr */
  2020. reg = I915_READ(DSPFW3);
  2021. reg &= ~(IGD_SELF_REFRESH_EN);
  2022. I915_WRITE(DSPFW3, reg);
  2023. DRM_INFO("Big FIFO is disabled\n");
  2024. }
  2025. static void igd_enable_cxsr(struct drm_device *dev, unsigned long clock,
  2026. int pixel_size)
  2027. {
  2028. struct drm_i915_private *dev_priv = dev->dev_private;
  2029. u32 reg;
  2030. unsigned long wm;
  2031. struct cxsr_latency *latency;
  2032. latency = intel_get_cxsr_latency(IS_IGDG(dev), dev_priv->fsb_freq,
  2033. dev_priv->mem_freq);
  2034. if (!latency) {
  2035. DRM_DEBUG("Unknown FSB/MEM found, disable CxSR\n");
  2036. igd_disable_cxsr(dev);
  2037. return;
  2038. }
  2039. /* Display SR */
  2040. wm = intel_calculate_wm(clock, &igd_display_wm, pixel_size,
  2041. latency->display_sr);
  2042. reg = I915_READ(DSPFW1);
  2043. reg &= 0x7fffff;
  2044. reg |= wm << 23;
  2045. I915_WRITE(DSPFW1, reg);
  2046. DRM_DEBUG("DSPFW1 register is %x\n", reg);
  2047. /* cursor SR */
  2048. wm = intel_calculate_wm(clock, &igd_cursor_wm, pixel_size,
  2049. latency->cursor_sr);
  2050. reg = I915_READ(DSPFW3);
  2051. reg &= ~(0x3f << 24);
  2052. reg |= (wm & 0x3f) << 24;
  2053. I915_WRITE(DSPFW3, reg);
  2054. /* Display HPLL off SR */
  2055. wm = intel_calculate_wm(clock, &igd_display_hplloff_wm,
  2056. latency->display_hpll_disable, I915_FIFO_LINE_SIZE);
  2057. reg = I915_READ(DSPFW3);
  2058. reg &= 0xfffffe00;
  2059. reg |= wm & 0x1ff;
  2060. I915_WRITE(DSPFW3, reg);
  2061. /* cursor HPLL off SR */
  2062. wm = intel_calculate_wm(clock, &igd_cursor_hplloff_wm, pixel_size,
  2063. latency->cursor_hpll_disable);
  2064. reg = I915_READ(DSPFW3);
  2065. reg &= ~(0x3f << 16);
  2066. reg |= (wm & 0x3f) << 16;
  2067. I915_WRITE(DSPFW3, reg);
  2068. DRM_DEBUG("DSPFW3 register is %x\n", reg);
  2069. /* activate cxsr */
  2070. reg = I915_READ(DSPFW3);
  2071. reg |= IGD_SELF_REFRESH_EN;
  2072. I915_WRITE(DSPFW3, reg);
  2073. DRM_INFO("Big FIFO is enabled\n");
  2074. return;
  2075. }
  2076. /*
  2077. * Latency for FIFO fetches is dependent on several factors:
  2078. * - memory configuration (speed, channels)
  2079. * - chipset
  2080. * - current MCH state
  2081. * It can be fairly high in some situations, so here we assume a fairly
  2082. * pessimal value. It's a tradeoff between extra memory fetches (if we
  2083. * set this value too high, the FIFO will fetch frequently to stay full)
  2084. * and power consumption (set it too low to save power and we might see
  2085. * FIFO underruns and display "flicker").
  2086. *
  2087. * A value of 5us seems to be a good balance; safe for very low end
  2088. * platforms but not overly aggressive on lower latency configs.
  2089. */
  2090. const static int latency_ns = 5000;
  2091. static int i9xx_get_fifo_size(struct drm_device *dev, int plane)
  2092. {
  2093. struct drm_i915_private *dev_priv = dev->dev_private;
  2094. uint32_t dsparb = I915_READ(DSPARB);
  2095. int size;
  2096. if (plane == 0)
  2097. size = dsparb & 0x7f;
  2098. else
  2099. size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) -
  2100. (dsparb & 0x7f);
  2101. DRM_DEBUG("FIFO size - (0x%08x) %s: %d\n", dsparb, plane ? "B" : "A",
  2102. size);
  2103. return size;
  2104. }
  2105. static int i85x_get_fifo_size(struct drm_device *dev, int plane)
  2106. {
  2107. struct drm_i915_private *dev_priv = dev->dev_private;
  2108. uint32_t dsparb = I915_READ(DSPARB);
  2109. int size;
  2110. if (plane == 0)
  2111. size = dsparb & 0x1ff;
  2112. else
  2113. size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) -
  2114. (dsparb & 0x1ff);
  2115. size >>= 1; /* Convert to cachelines */
  2116. DRM_DEBUG("FIFO size - (0x%08x) %s: %d\n", dsparb, plane ? "B" : "A",
  2117. size);
  2118. return size;
  2119. }
  2120. static int i845_get_fifo_size(struct drm_device *dev, int plane)
  2121. {
  2122. struct drm_i915_private *dev_priv = dev->dev_private;
  2123. uint32_t dsparb = I915_READ(DSPARB);
  2124. int size;
  2125. size = dsparb & 0x7f;
  2126. size >>= 2; /* Convert to cachelines */
  2127. DRM_DEBUG("FIFO size - (0x%08x) %s: %d\n", dsparb, plane ? "B" : "A",
  2128. size);
  2129. return size;
  2130. }
  2131. static int i830_get_fifo_size(struct drm_device *dev, int plane)
  2132. {
  2133. struct drm_i915_private *dev_priv = dev->dev_private;
  2134. uint32_t dsparb = I915_READ(DSPARB);
  2135. int size;
  2136. size = dsparb & 0x7f;
  2137. size >>= 1; /* Convert to cachelines */
  2138. DRM_DEBUG("FIFO size - (0x%08x) %s: %d\n", dsparb, plane ? "B" : "A",
  2139. size);
  2140. return size;
  2141. }
  2142. static void g4x_update_wm(struct drm_device *dev, int planea_clock,
  2143. int planeb_clock, int sr_hdisplay, int pixel_size)
  2144. {
  2145. struct drm_i915_private *dev_priv = dev->dev_private;
  2146. int total_size, cacheline_size;
  2147. int planea_wm, planeb_wm, cursora_wm, cursorb_wm, cursor_sr;
  2148. struct intel_watermark_params planea_params, planeb_params;
  2149. unsigned long line_time_us;
  2150. int sr_clock, sr_entries = 0, entries_required;
  2151. /* Create copies of the base settings for each pipe */
  2152. planea_params = planeb_params = g4x_wm_info;
  2153. /* Grab a couple of global values before we overwrite them */
  2154. total_size = planea_params.fifo_size;
  2155. cacheline_size = planea_params.cacheline_size;
  2156. /*
  2157. * Note: we need to make sure we don't overflow for various clock &
  2158. * latency values.
  2159. * clocks go from a few thousand to several hundred thousand.
  2160. * latency is usually a few thousand
  2161. */
  2162. entries_required = ((planea_clock / 1000) * pixel_size * latency_ns) /
  2163. 1000;
  2164. entries_required /= G4X_FIFO_LINE_SIZE;
  2165. planea_wm = entries_required + planea_params.guard_size;
  2166. entries_required = ((planeb_clock / 1000) * pixel_size * latency_ns) /
  2167. 1000;
  2168. entries_required /= G4X_FIFO_LINE_SIZE;
  2169. planeb_wm = entries_required + planeb_params.guard_size;
  2170. cursora_wm = cursorb_wm = 16;
  2171. cursor_sr = 32;
  2172. DRM_DEBUG("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
  2173. /* Calc sr entries for one plane configs */
  2174. if (sr_hdisplay && (!planea_clock || !planeb_clock)) {
  2175. /* self-refresh has much higher latency */
  2176. const static int sr_latency_ns = 12000;
  2177. sr_clock = planea_clock ? planea_clock : planeb_clock;
  2178. line_time_us = ((sr_hdisplay * 1000) / sr_clock);
  2179. /* Use ns/us then divide to preserve precision */
  2180. sr_entries = (((sr_latency_ns / line_time_us) + 1) *
  2181. pixel_size * sr_hdisplay) / 1000;
  2182. sr_entries = roundup(sr_entries / cacheline_size, 1);
  2183. DRM_DEBUG("self-refresh entries: %d\n", sr_entries);
  2184. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
  2185. }
  2186. DRM_DEBUG("Setting FIFO watermarks - A: %d, B: %d, SR %d\n",
  2187. planea_wm, planeb_wm, sr_entries);
  2188. planea_wm &= 0x3f;
  2189. planeb_wm &= 0x3f;
  2190. I915_WRITE(DSPFW1, (sr_entries << DSPFW_SR_SHIFT) |
  2191. (cursorb_wm << DSPFW_CURSORB_SHIFT) |
  2192. (planeb_wm << DSPFW_PLANEB_SHIFT) | planea_wm);
  2193. I915_WRITE(DSPFW2, (I915_READ(DSPFW2) & DSPFW_CURSORA_MASK) |
  2194. (cursora_wm << DSPFW_CURSORA_SHIFT));
  2195. /* HPLL off in SR has some issues on G4x... disable it */
  2196. I915_WRITE(DSPFW3, (I915_READ(DSPFW3) & ~DSPFW_HPLL_SR_EN) |
  2197. (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  2198. }
  2199. static void i965_update_wm(struct drm_device *dev, int unused, int unused2,
  2200. int unused3, int unused4)
  2201. {
  2202. struct drm_i915_private *dev_priv = dev->dev_private;
  2203. DRM_DEBUG("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR 8\n");
  2204. /* 965 has limitations... */
  2205. I915_WRITE(DSPFW1, (8 << 16) | (8 << 8) | (8 << 0));
  2206. I915_WRITE(DSPFW2, (8 << 8) | (8 << 0));
  2207. }
  2208. static void i9xx_update_wm(struct drm_device *dev, int planea_clock,
  2209. int planeb_clock, int sr_hdisplay, int pixel_size)
  2210. {
  2211. struct drm_i915_private *dev_priv = dev->dev_private;
  2212. uint32_t fwater_lo;
  2213. uint32_t fwater_hi;
  2214. int total_size, cacheline_size, cwm, srwm = 1;
  2215. int planea_wm, planeb_wm;
  2216. struct intel_watermark_params planea_params, planeb_params;
  2217. unsigned long line_time_us;
  2218. int sr_clock, sr_entries = 0;
  2219. /* Create copies of the base settings for each pipe */
  2220. if (IS_I965GM(dev) || IS_I945GM(dev))
  2221. planea_params = planeb_params = i945_wm_info;
  2222. else if (IS_I9XX(dev))
  2223. planea_params = planeb_params = i915_wm_info;
  2224. else
  2225. planea_params = planeb_params = i855_wm_info;
  2226. /* Grab a couple of global values before we overwrite them */
  2227. total_size = planea_params.fifo_size;
  2228. cacheline_size = planea_params.cacheline_size;
  2229. /* Update per-plane FIFO sizes */
  2230. planea_params.fifo_size = dev_priv->display.get_fifo_size(dev, 0);
  2231. planeb_params.fifo_size = dev_priv->display.get_fifo_size(dev, 1);
  2232. planea_wm = intel_calculate_wm(planea_clock, &planea_params,
  2233. pixel_size, latency_ns);
  2234. planeb_wm = intel_calculate_wm(planeb_clock, &planeb_params,
  2235. pixel_size, latency_ns);
  2236. DRM_DEBUG("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
  2237. /*
  2238. * Overlay gets an aggressive default since video jitter is bad.
  2239. */
  2240. cwm = 2;
  2241. /* Calc sr entries for one plane configs */
  2242. if (HAS_FW_BLC(dev) && sr_hdisplay &&
  2243. (!planea_clock || !planeb_clock)) {
  2244. /* self-refresh has much higher latency */
  2245. const static int sr_latency_ns = 6000;
  2246. sr_clock = planea_clock ? planea_clock : planeb_clock;
  2247. line_time_us = ((sr_hdisplay * 1000) / sr_clock);
  2248. /* Use ns/us then divide to preserve precision */
  2249. sr_entries = (((sr_latency_ns / line_time_us) + 1) *
  2250. pixel_size * sr_hdisplay) / 1000;
  2251. sr_entries = roundup(sr_entries / cacheline_size, 1);
  2252. DRM_DEBUG("self-refresh entries: %d\n", sr_entries);
  2253. srwm = total_size - sr_entries;
  2254. if (srwm < 0)
  2255. srwm = 1;
  2256. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN | (srwm & 0x3f));
  2257. }
  2258. DRM_DEBUG("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
  2259. planea_wm, planeb_wm, cwm, srwm);
  2260. fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
  2261. fwater_hi = (cwm & 0x1f);
  2262. /* Set request length to 8 cachelines per fetch */
  2263. fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
  2264. fwater_hi = fwater_hi | (1 << 8);
  2265. I915_WRITE(FW_BLC, fwater_lo);
  2266. I915_WRITE(FW_BLC2, fwater_hi);
  2267. }
  2268. static void i830_update_wm(struct drm_device *dev, int planea_clock, int unused,
  2269. int unused2, int pixel_size)
  2270. {
  2271. struct drm_i915_private *dev_priv = dev->dev_private;
  2272. uint32_t fwater_lo = I915_READ(FW_BLC) & ~0xfff;
  2273. int planea_wm;
  2274. i830_wm_info.fifo_size = dev_priv->display.get_fifo_size(dev, 0);
  2275. planea_wm = intel_calculate_wm(planea_clock, &i830_wm_info,
  2276. pixel_size, latency_ns);
  2277. fwater_lo |= (3<<8) | planea_wm;
  2278. DRM_DEBUG("Setting FIFO watermarks - A: %d\n", planea_wm);
  2279. I915_WRITE(FW_BLC, fwater_lo);
  2280. }
  2281. /**
  2282. * intel_update_watermarks - update FIFO watermark values based on current modes
  2283. *
  2284. * Calculate watermark values for the various WM regs based on current mode
  2285. * and plane configuration.
  2286. *
  2287. * There are several cases to deal with here:
  2288. * - normal (i.e. non-self-refresh)
  2289. * - self-refresh (SR) mode
  2290. * - lines are large relative to FIFO size (buffer can hold up to 2)
  2291. * - lines are small relative to FIFO size (buffer can hold more than 2
  2292. * lines), so need to account for TLB latency
  2293. *
  2294. * The normal calculation is:
  2295. * watermark = dotclock * bytes per pixel * latency
  2296. * where latency is platform & configuration dependent (we assume pessimal
  2297. * values here).
  2298. *
  2299. * The SR calculation is:
  2300. * watermark = (trunc(latency/line time)+1) * surface width *
  2301. * bytes per pixel
  2302. * where
  2303. * line time = htotal / dotclock
  2304. * and latency is assumed to be high, as above.
  2305. *
  2306. * The final value programmed to the register should always be rounded up,
  2307. * and include an extra 2 entries to account for clock crossings.
  2308. *
  2309. * We don't use the sprite, so we can ignore that. And on Crestline we have
  2310. * to set the non-SR watermarks to 8.
  2311. */
  2312. static void intel_update_watermarks(struct drm_device *dev)
  2313. {
  2314. struct drm_i915_private *dev_priv = dev->dev_private;
  2315. struct drm_crtc *crtc;
  2316. struct intel_crtc *intel_crtc;
  2317. int sr_hdisplay = 0;
  2318. unsigned long planea_clock = 0, planeb_clock = 0, sr_clock = 0;
  2319. int enabled = 0, pixel_size = 0;
  2320. if (!dev_priv->display.update_wm)
  2321. return;
  2322. /* Get the clock config from both planes */
  2323. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  2324. intel_crtc = to_intel_crtc(crtc);
  2325. if (crtc->enabled) {
  2326. enabled++;
  2327. if (intel_crtc->plane == 0) {
  2328. DRM_DEBUG("plane A (pipe %d) clock: %d\n",
  2329. intel_crtc->pipe, crtc->mode.clock);
  2330. planea_clock = crtc->mode.clock;
  2331. } else {
  2332. DRM_DEBUG("plane B (pipe %d) clock: %d\n",
  2333. intel_crtc->pipe, crtc->mode.clock);
  2334. planeb_clock = crtc->mode.clock;
  2335. }
  2336. sr_hdisplay = crtc->mode.hdisplay;
  2337. sr_clock = crtc->mode.clock;
  2338. if (crtc->fb)
  2339. pixel_size = crtc->fb->bits_per_pixel / 8;
  2340. else
  2341. pixel_size = 4; /* by default */
  2342. }
  2343. }
  2344. if (enabled <= 0)
  2345. return;
  2346. /* Single plane configs can enable self refresh */
  2347. if (enabled == 1 && IS_IGD(dev))
  2348. igd_enable_cxsr(dev, sr_clock, pixel_size);
  2349. else if (IS_IGD(dev))
  2350. igd_disable_cxsr(dev);
  2351. dev_priv->display.update_wm(dev, planea_clock, planeb_clock,
  2352. sr_hdisplay, pixel_size);
  2353. }
  2354. static int intel_crtc_mode_set(struct drm_crtc *crtc,
  2355. struct drm_display_mode *mode,
  2356. struct drm_display_mode *adjusted_mode,
  2357. int x, int y,
  2358. struct drm_framebuffer *old_fb)
  2359. {
  2360. struct drm_device *dev = crtc->dev;
  2361. struct drm_i915_private *dev_priv = dev->dev_private;
  2362. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2363. int pipe = intel_crtc->pipe;
  2364. int plane = intel_crtc->plane;
  2365. int fp_reg = (pipe == 0) ? FPA0 : FPB0;
  2366. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  2367. int dpll_md_reg = (intel_crtc->pipe == 0) ? DPLL_A_MD : DPLL_B_MD;
  2368. int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR;
  2369. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  2370. int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
  2371. int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
  2372. int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
  2373. int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
  2374. int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
  2375. int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
  2376. int dspsize_reg = (plane == 0) ? DSPASIZE : DSPBSIZE;
  2377. int dsppos_reg = (plane == 0) ? DSPAPOS : DSPBPOS;
  2378. int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC;
  2379. int refclk, num_outputs = 0;
  2380. intel_clock_t clock, reduced_clock;
  2381. u32 dpll = 0, fp = 0, fp2 = 0, dspcntr, pipeconf;
  2382. bool ok, has_reduced_clock = false, is_sdvo = false, is_dvo = false;
  2383. bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false;
  2384. bool is_edp = false;
  2385. struct drm_mode_config *mode_config = &dev->mode_config;
  2386. struct drm_connector *connector;
  2387. const intel_limit_t *limit;
  2388. int ret;
  2389. struct fdi_m_n m_n = {0};
  2390. int data_m1_reg = (pipe == 0) ? PIPEA_DATA_M1 : PIPEB_DATA_M1;
  2391. int data_n1_reg = (pipe == 0) ? PIPEA_DATA_N1 : PIPEB_DATA_N1;
  2392. int link_m1_reg = (pipe == 0) ? PIPEA_LINK_M1 : PIPEB_LINK_M1;
  2393. int link_n1_reg = (pipe == 0) ? PIPEA_LINK_N1 : PIPEB_LINK_N1;
  2394. int pch_fp_reg = (pipe == 0) ? PCH_FPA0 : PCH_FPB0;
  2395. int pch_dpll_reg = (pipe == 0) ? PCH_DPLL_A : PCH_DPLL_B;
  2396. int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL;
  2397. int lvds_reg = LVDS;
  2398. u32 temp;
  2399. int sdvo_pixel_multiply;
  2400. int target_clock;
  2401. drm_vblank_pre_modeset(dev, pipe);
  2402. list_for_each_entry(connector, &mode_config->connector_list, head) {
  2403. struct intel_output *intel_output = to_intel_output(connector);
  2404. if (!connector->encoder || connector->encoder->crtc != crtc)
  2405. continue;
  2406. switch (intel_output->type) {
  2407. case INTEL_OUTPUT_LVDS:
  2408. is_lvds = true;
  2409. break;
  2410. case INTEL_OUTPUT_SDVO:
  2411. case INTEL_OUTPUT_HDMI:
  2412. is_sdvo = true;
  2413. if (intel_output->needs_tv_clock)
  2414. is_tv = true;
  2415. break;
  2416. case INTEL_OUTPUT_DVO:
  2417. is_dvo = true;
  2418. break;
  2419. case INTEL_OUTPUT_TVOUT:
  2420. is_tv = true;
  2421. break;
  2422. case INTEL_OUTPUT_ANALOG:
  2423. is_crt = true;
  2424. break;
  2425. case INTEL_OUTPUT_DISPLAYPORT:
  2426. is_dp = true;
  2427. break;
  2428. case INTEL_OUTPUT_EDP:
  2429. is_edp = true;
  2430. break;
  2431. }
  2432. num_outputs++;
  2433. }
  2434. if (is_lvds && dev_priv->lvds_use_ssc && num_outputs < 2) {
  2435. refclk = dev_priv->lvds_ssc_freq * 1000;
  2436. DRM_DEBUG("using SSC reference clock of %d MHz\n", refclk / 1000);
  2437. } else if (IS_I9XX(dev)) {
  2438. refclk = 96000;
  2439. if (IS_IGDNG(dev))
  2440. refclk = 120000; /* 120Mhz refclk */
  2441. } else {
  2442. refclk = 48000;
  2443. }
  2444. /*
  2445. * Returns a set of divisors for the desired target clock with the given
  2446. * refclk, or FALSE. The returned values represent the clock equation:
  2447. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  2448. */
  2449. limit = intel_limit(crtc);
  2450. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, &clock);
  2451. if (!ok) {
  2452. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  2453. drm_vblank_post_modeset(dev, pipe);
  2454. return -EINVAL;
  2455. }
  2456. if (limit->find_reduced_pll && dev_priv->lvds_downclock_avail) {
  2457. memcpy(&reduced_clock, &clock, sizeof(intel_clock_t));
  2458. has_reduced_clock = limit->find_reduced_pll(limit, crtc,
  2459. (adjusted_mode->clock*3/4),
  2460. refclk,
  2461. &reduced_clock);
  2462. }
  2463. /* SDVO TV has fixed PLL values depend on its clock range,
  2464. this mirrors vbios setting. */
  2465. if (is_sdvo && is_tv) {
  2466. if (adjusted_mode->clock >= 100000
  2467. && adjusted_mode->clock < 140500) {
  2468. clock.p1 = 2;
  2469. clock.p2 = 10;
  2470. clock.n = 3;
  2471. clock.m1 = 16;
  2472. clock.m2 = 8;
  2473. } else if (adjusted_mode->clock >= 140500
  2474. && adjusted_mode->clock <= 200000) {
  2475. clock.p1 = 1;
  2476. clock.p2 = 10;
  2477. clock.n = 6;
  2478. clock.m1 = 12;
  2479. clock.m2 = 8;
  2480. }
  2481. }
  2482. /* FDI link */
  2483. if (IS_IGDNG(dev)) {
  2484. int lane, link_bw, bpp;
  2485. /* eDP doesn't require FDI link, so just set DP M/N
  2486. according to current link config */
  2487. if (is_edp) {
  2488. struct drm_connector *edp;
  2489. target_clock = mode->clock;
  2490. edp = intel_pipe_get_output(crtc);
  2491. intel_edp_link_config(to_intel_output(edp),
  2492. &lane, &link_bw);
  2493. } else {
  2494. /* DP over FDI requires target mode clock
  2495. instead of link clock */
  2496. if (is_dp)
  2497. target_clock = mode->clock;
  2498. else
  2499. target_clock = adjusted_mode->clock;
  2500. lane = 4;
  2501. link_bw = 270000;
  2502. }
  2503. /* determine panel color depth */
  2504. temp = I915_READ(pipeconf_reg);
  2505. switch (temp & PIPE_BPC_MASK) {
  2506. case PIPE_8BPC:
  2507. bpp = 24;
  2508. break;
  2509. case PIPE_10BPC:
  2510. bpp = 30;
  2511. break;
  2512. case PIPE_6BPC:
  2513. bpp = 18;
  2514. break;
  2515. case PIPE_12BPC:
  2516. bpp = 36;
  2517. break;
  2518. default:
  2519. DRM_ERROR("unknown pipe bpc value\n");
  2520. bpp = 24;
  2521. }
  2522. igdng_compute_m_n(bpp, lane, target_clock,
  2523. link_bw, &m_n);
  2524. }
  2525. /* Ironlake: try to setup display ref clock before DPLL
  2526. * enabling. This is only under driver's control after
  2527. * PCH B stepping, previous chipset stepping should be
  2528. * ignoring this setting.
  2529. */
  2530. if (IS_IGDNG(dev)) {
  2531. temp = I915_READ(PCH_DREF_CONTROL);
  2532. /* Always enable nonspread source */
  2533. temp &= ~DREF_NONSPREAD_SOURCE_MASK;
  2534. temp |= DREF_NONSPREAD_SOURCE_ENABLE;
  2535. I915_WRITE(PCH_DREF_CONTROL, temp);
  2536. POSTING_READ(PCH_DREF_CONTROL);
  2537. temp &= ~DREF_SSC_SOURCE_MASK;
  2538. temp |= DREF_SSC_SOURCE_ENABLE;
  2539. I915_WRITE(PCH_DREF_CONTROL, temp);
  2540. POSTING_READ(PCH_DREF_CONTROL);
  2541. udelay(200);
  2542. if (is_edp) {
  2543. if (dev_priv->lvds_use_ssc) {
  2544. temp |= DREF_SSC1_ENABLE;
  2545. I915_WRITE(PCH_DREF_CONTROL, temp);
  2546. POSTING_READ(PCH_DREF_CONTROL);
  2547. udelay(200);
  2548. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  2549. temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  2550. I915_WRITE(PCH_DREF_CONTROL, temp);
  2551. POSTING_READ(PCH_DREF_CONTROL);
  2552. } else {
  2553. temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  2554. I915_WRITE(PCH_DREF_CONTROL, temp);
  2555. POSTING_READ(PCH_DREF_CONTROL);
  2556. }
  2557. }
  2558. }
  2559. if (IS_IGD(dev)) {
  2560. fp = (1 << clock.n) << 16 | clock.m1 << 8 | clock.m2;
  2561. if (has_reduced_clock)
  2562. fp2 = (1 << reduced_clock.n) << 16 |
  2563. reduced_clock.m1 << 8 | reduced_clock.m2;
  2564. } else {
  2565. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  2566. if (has_reduced_clock)
  2567. fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
  2568. reduced_clock.m2;
  2569. }
  2570. if (!IS_IGDNG(dev))
  2571. dpll = DPLL_VGA_MODE_DIS;
  2572. if (IS_I9XX(dev)) {
  2573. if (is_lvds)
  2574. dpll |= DPLLB_MODE_LVDS;
  2575. else
  2576. dpll |= DPLLB_MODE_DAC_SERIAL;
  2577. if (is_sdvo) {
  2578. dpll |= DPLL_DVO_HIGH_SPEED;
  2579. sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  2580. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  2581. dpll |= (sdvo_pixel_multiply - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  2582. else if (IS_IGDNG(dev))
  2583. dpll |= (sdvo_pixel_multiply - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  2584. }
  2585. if (is_dp)
  2586. dpll |= DPLL_DVO_HIGH_SPEED;
  2587. /* compute bitmask from p1 value */
  2588. if (IS_IGD(dev))
  2589. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_IGD;
  2590. else {
  2591. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  2592. /* also FPA1 */
  2593. if (IS_IGDNG(dev))
  2594. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  2595. if (IS_G4X(dev) && has_reduced_clock)
  2596. dpll |= (1 << (reduced_clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  2597. }
  2598. switch (clock.p2) {
  2599. case 5:
  2600. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  2601. break;
  2602. case 7:
  2603. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  2604. break;
  2605. case 10:
  2606. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  2607. break;
  2608. case 14:
  2609. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  2610. break;
  2611. }
  2612. if (IS_I965G(dev) && !IS_IGDNG(dev))
  2613. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  2614. } else {
  2615. if (is_lvds) {
  2616. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  2617. } else {
  2618. if (clock.p1 == 2)
  2619. dpll |= PLL_P1_DIVIDE_BY_TWO;
  2620. else
  2621. dpll |= (clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  2622. if (clock.p2 == 4)
  2623. dpll |= PLL_P2_DIVIDE_BY_4;
  2624. }
  2625. }
  2626. if (is_sdvo && is_tv)
  2627. dpll |= PLL_REF_INPUT_TVCLKINBC;
  2628. else if (is_tv)
  2629. /* XXX: just matching BIOS for now */
  2630. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  2631. dpll |= 3;
  2632. else if (is_lvds && dev_priv->lvds_use_ssc && num_outputs < 2)
  2633. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  2634. else
  2635. dpll |= PLL_REF_INPUT_DREFCLK;
  2636. /* setup pipeconf */
  2637. pipeconf = I915_READ(pipeconf_reg);
  2638. /* Set up the display plane register */
  2639. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2640. /* IGDNG's plane is forced to pipe, bit 24 is to
  2641. enable color space conversion */
  2642. if (!IS_IGDNG(dev)) {
  2643. if (pipe == 0)
  2644. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  2645. else
  2646. dspcntr |= DISPPLANE_SEL_PIPE_B;
  2647. }
  2648. if (pipe == 0 && !IS_I965G(dev)) {
  2649. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  2650. * core speed.
  2651. *
  2652. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  2653. * pipe == 0 check?
  2654. */
  2655. if (mode->clock >
  2656. dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
  2657. pipeconf |= PIPEACONF_DOUBLE_WIDE;
  2658. else
  2659. pipeconf &= ~PIPEACONF_DOUBLE_WIDE;
  2660. }
  2661. dspcntr |= DISPLAY_PLANE_ENABLE;
  2662. pipeconf |= PIPEACONF_ENABLE;
  2663. dpll |= DPLL_VCO_ENABLE;
  2664. /* Disable the panel fitter if it was on our pipe */
  2665. if (!IS_IGDNG(dev) && intel_panel_fitter_pipe(dev) == pipe)
  2666. I915_WRITE(PFIT_CONTROL, 0);
  2667. DRM_DEBUG("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  2668. drm_mode_debug_printmodeline(mode);
  2669. /* assign to IGDNG registers */
  2670. if (IS_IGDNG(dev)) {
  2671. fp_reg = pch_fp_reg;
  2672. dpll_reg = pch_dpll_reg;
  2673. }
  2674. if (is_edp) {
  2675. igdng_disable_pll_edp(crtc);
  2676. } else if ((dpll & DPLL_VCO_ENABLE)) {
  2677. I915_WRITE(fp_reg, fp);
  2678. I915_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE);
  2679. I915_READ(dpll_reg);
  2680. udelay(150);
  2681. }
  2682. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  2683. * This is an exception to the general rule that mode_set doesn't turn
  2684. * things on.
  2685. */
  2686. if (is_lvds) {
  2687. u32 lvds;
  2688. if (IS_IGDNG(dev))
  2689. lvds_reg = PCH_LVDS;
  2690. lvds = I915_READ(lvds_reg);
  2691. lvds |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP | LVDS_PIPEB_SELECT;
  2692. /* set the corresponsding LVDS_BORDER bit */
  2693. lvds |= dev_priv->lvds_border_bits;
  2694. /* Set the B0-B3 data pairs corresponding to whether we're going to
  2695. * set the DPLLs for dual-channel mode or not.
  2696. */
  2697. if (clock.p2 == 7)
  2698. lvds |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  2699. else
  2700. lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  2701. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  2702. * appropriately here, but we need to look more thoroughly into how
  2703. * panels behave in the two modes.
  2704. */
  2705. I915_WRITE(lvds_reg, lvds);
  2706. I915_READ(lvds_reg);
  2707. }
  2708. if (is_dp)
  2709. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  2710. if (!is_edp) {
  2711. I915_WRITE(fp_reg, fp);
  2712. I915_WRITE(dpll_reg, dpll);
  2713. I915_READ(dpll_reg);
  2714. /* Wait for the clocks to stabilize. */
  2715. udelay(150);
  2716. if (IS_I965G(dev) && !IS_IGDNG(dev)) {
  2717. if (is_sdvo) {
  2718. sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  2719. I915_WRITE(dpll_md_reg, (0 << DPLL_MD_UDI_DIVIDER_SHIFT) |
  2720. ((sdvo_pixel_multiply - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT));
  2721. } else
  2722. I915_WRITE(dpll_md_reg, 0);
  2723. } else {
  2724. /* write it again -- the BIOS does, after all */
  2725. I915_WRITE(dpll_reg, dpll);
  2726. }
  2727. I915_READ(dpll_reg);
  2728. /* Wait for the clocks to stabilize. */
  2729. udelay(150);
  2730. }
  2731. if (is_lvds && has_reduced_clock && i915_powersave) {
  2732. I915_WRITE(fp_reg + 4, fp2);
  2733. intel_crtc->lowfreq_avail = true;
  2734. if (HAS_PIPE_CXSR(dev)) {
  2735. DRM_DEBUG("enabling CxSR downclocking\n");
  2736. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  2737. }
  2738. } else {
  2739. I915_WRITE(fp_reg + 4, fp);
  2740. intel_crtc->lowfreq_avail = false;
  2741. if (HAS_PIPE_CXSR(dev)) {
  2742. DRM_DEBUG("disabling CxSR downclocking\n");
  2743. pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
  2744. }
  2745. }
  2746. I915_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) |
  2747. ((adjusted_mode->crtc_htotal - 1) << 16));
  2748. I915_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) |
  2749. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  2750. I915_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) |
  2751. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  2752. I915_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) |
  2753. ((adjusted_mode->crtc_vtotal - 1) << 16));
  2754. I915_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) |
  2755. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  2756. I915_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) |
  2757. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  2758. /* pipesrc and dspsize control the size that is scaled from, which should
  2759. * always be the user's requested size.
  2760. */
  2761. if (!IS_IGDNG(dev)) {
  2762. I915_WRITE(dspsize_reg, ((mode->vdisplay - 1) << 16) |
  2763. (mode->hdisplay - 1));
  2764. I915_WRITE(dsppos_reg, 0);
  2765. }
  2766. I915_WRITE(pipesrc_reg, ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  2767. if (IS_IGDNG(dev)) {
  2768. I915_WRITE(data_m1_reg, TU_SIZE(m_n.tu) | m_n.gmch_m);
  2769. I915_WRITE(data_n1_reg, TU_SIZE(m_n.tu) | m_n.gmch_n);
  2770. I915_WRITE(link_m1_reg, m_n.link_m);
  2771. I915_WRITE(link_n1_reg, m_n.link_n);
  2772. if (is_edp) {
  2773. igdng_set_pll_edp(crtc, adjusted_mode->clock);
  2774. } else {
  2775. /* enable FDI RX PLL too */
  2776. temp = I915_READ(fdi_rx_reg);
  2777. I915_WRITE(fdi_rx_reg, temp | FDI_RX_PLL_ENABLE);
  2778. udelay(200);
  2779. }
  2780. }
  2781. I915_WRITE(pipeconf_reg, pipeconf);
  2782. I915_READ(pipeconf_reg);
  2783. intel_wait_for_vblank(dev);
  2784. if (IS_IGDNG(dev)) {
  2785. /* enable address swizzle for tiling buffer */
  2786. temp = I915_READ(DISP_ARB_CTL);
  2787. I915_WRITE(DISP_ARB_CTL, temp | DISP_TILE_SURFACE_SWIZZLING);
  2788. }
  2789. I915_WRITE(dspcntr_reg, dspcntr);
  2790. /* Flush the plane changes */
  2791. ret = intel_pipe_set_base(crtc, x, y, old_fb);
  2792. if ((IS_I965G(dev) || plane == 0))
  2793. intel_update_fbc(crtc, &crtc->mode);
  2794. intel_update_watermarks(dev);
  2795. drm_vblank_post_modeset(dev, pipe);
  2796. return ret;
  2797. }
  2798. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  2799. void intel_crtc_load_lut(struct drm_crtc *crtc)
  2800. {
  2801. struct drm_device *dev = crtc->dev;
  2802. struct drm_i915_private *dev_priv = dev->dev_private;
  2803. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2804. int palreg = (intel_crtc->pipe == 0) ? PALETTE_A : PALETTE_B;
  2805. int i;
  2806. /* The clocks have to be on to load the palette. */
  2807. if (!crtc->enabled)
  2808. return;
  2809. /* use legacy palette for IGDNG */
  2810. if (IS_IGDNG(dev))
  2811. palreg = (intel_crtc->pipe == 0) ? LGC_PALETTE_A :
  2812. LGC_PALETTE_B;
  2813. for (i = 0; i < 256; i++) {
  2814. I915_WRITE(palreg + 4 * i,
  2815. (intel_crtc->lut_r[i] << 16) |
  2816. (intel_crtc->lut_g[i] << 8) |
  2817. intel_crtc->lut_b[i]);
  2818. }
  2819. }
  2820. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  2821. struct drm_file *file_priv,
  2822. uint32_t handle,
  2823. uint32_t width, uint32_t height)
  2824. {
  2825. struct drm_device *dev = crtc->dev;
  2826. struct drm_i915_private *dev_priv = dev->dev_private;
  2827. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2828. struct drm_gem_object *bo;
  2829. struct drm_i915_gem_object *obj_priv;
  2830. int pipe = intel_crtc->pipe;
  2831. uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR;
  2832. uint32_t base = (pipe == 0) ? CURABASE : CURBBASE;
  2833. uint32_t temp = I915_READ(control);
  2834. size_t addr;
  2835. int ret;
  2836. DRM_DEBUG("\n");
  2837. /* if we want to turn off the cursor ignore width and height */
  2838. if (!handle) {
  2839. DRM_DEBUG("cursor off\n");
  2840. if (IS_MOBILE(dev) || IS_I9XX(dev)) {
  2841. temp &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  2842. temp |= CURSOR_MODE_DISABLE;
  2843. } else {
  2844. temp &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
  2845. }
  2846. addr = 0;
  2847. bo = NULL;
  2848. mutex_lock(&dev->struct_mutex);
  2849. goto finish;
  2850. }
  2851. /* Currently we only support 64x64 cursors */
  2852. if (width != 64 || height != 64) {
  2853. DRM_ERROR("we currently only support 64x64 cursors\n");
  2854. return -EINVAL;
  2855. }
  2856. bo = drm_gem_object_lookup(dev, file_priv, handle);
  2857. if (!bo)
  2858. return -ENOENT;
  2859. obj_priv = bo->driver_private;
  2860. if (bo->size < width * height * 4) {
  2861. DRM_ERROR("buffer is to small\n");
  2862. ret = -ENOMEM;
  2863. goto fail;
  2864. }
  2865. /* we only need to pin inside GTT if cursor is non-phy */
  2866. mutex_lock(&dev->struct_mutex);
  2867. if (!dev_priv->cursor_needs_physical) {
  2868. ret = i915_gem_object_pin(bo, PAGE_SIZE);
  2869. if (ret) {
  2870. DRM_ERROR("failed to pin cursor bo\n");
  2871. goto fail_locked;
  2872. }
  2873. addr = obj_priv->gtt_offset;
  2874. } else {
  2875. ret = i915_gem_attach_phys_object(dev, bo, (pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1);
  2876. if (ret) {
  2877. DRM_ERROR("failed to attach phys object\n");
  2878. goto fail_locked;
  2879. }
  2880. addr = obj_priv->phys_obj->handle->busaddr;
  2881. }
  2882. if (!IS_I9XX(dev))
  2883. I915_WRITE(CURSIZE, (height << 12) | width);
  2884. /* Hooray for CUR*CNTR differences */
  2885. if (IS_MOBILE(dev) || IS_I9XX(dev)) {
  2886. temp &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
  2887. temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  2888. temp |= (pipe << 28); /* Connect to correct pipe */
  2889. } else {
  2890. temp &= ~(CURSOR_FORMAT_MASK);
  2891. temp |= CURSOR_ENABLE;
  2892. temp |= CURSOR_FORMAT_ARGB | CURSOR_GAMMA_ENABLE;
  2893. }
  2894. finish:
  2895. I915_WRITE(control, temp);
  2896. I915_WRITE(base, addr);
  2897. if (intel_crtc->cursor_bo) {
  2898. if (dev_priv->cursor_needs_physical) {
  2899. if (intel_crtc->cursor_bo != bo)
  2900. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  2901. } else
  2902. i915_gem_object_unpin(intel_crtc->cursor_bo);
  2903. drm_gem_object_unreference(intel_crtc->cursor_bo);
  2904. }
  2905. mutex_unlock(&dev->struct_mutex);
  2906. intel_crtc->cursor_addr = addr;
  2907. intel_crtc->cursor_bo = bo;
  2908. return 0;
  2909. fail:
  2910. mutex_lock(&dev->struct_mutex);
  2911. fail_locked:
  2912. drm_gem_object_unreference(bo);
  2913. mutex_unlock(&dev->struct_mutex);
  2914. return ret;
  2915. }
  2916. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  2917. {
  2918. struct drm_device *dev = crtc->dev;
  2919. struct drm_i915_private *dev_priv = dev->dev_private;
  2920. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2921. struct intel_framebuffer *intel_fb;
  2922. int pipe = intel_crtc->pipe;
  2923. uint32_t temp = 0;
  2924. uint32_t adder;
  2925. if (crtc->fb) {
  2926. intel_fb = to_intel_framebuffer(crtc->fb);
  2927. intel_mark_busy(dev, intel_fb->obj);
  2928. }
  2929. if (x < 0) {
  2930. temp |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  2931. x = -x;
  2932. }
  2933. if (y < 0) {
  2934. temp |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  2935. y = -y;
  2936. }
  2937. temp |= x << CURSOR_X_SHIFT;
  2938. temp |= y << CURSOR_Y_SHIFT;
  2939. adder = intel_crtc->cursor_addr;
  2940. I915_WRITE((pipe == 0) ? CURAPOS : CURBPOS, temp);
  2941. I915_WRITE((pipe == 0) ? CURABASE : CURBBASE, adder);
  2942. return 0;
  2943. }
  2944. /** Sets the color ramps on behalf of RandR */
  2945. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  2946. u16 blue, int regno)
  2947. {
  2948. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2949. intel_crtc->lut_r[regno] = red >> 8;
  2950. intel_crtc->lut_g[regno] = green >> 8;
  2951. intel_crtc->lut_b[regno] = blue >> 8;
  2952. }
  2953. void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  2954. u16 *blue, int regno)
  2955. {
  2956. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2957. *red = intel_crtc->lut_r[regno] << 8;
  2958. *green = intel_crtc->lut_g[regno] << 8;
  2959. *blue = intel_crtc->lut_b[regno] << 8;
  2960. }
  2961. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  2962. u16 *blue, uint32_t size)
  2963. {
  2964. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2965. int i;
  2966. if (size != 256)
  2967. return;
  2968. for (i = 0; i < 256; i++) {
  2969. intel_crtc->lut_r[i] = red[i] >> 8;
  2970. intel_crtc->lut_g[i] = green[i] >> 8;
  2971. intel_crtc->lut_b[i] = blue[i] >> 8;
  2972. }
  2973. intel_crtc_load_lut(crtc);
  2974. }
  2975. /**
  2976. * Get a pipe with a simple mode set on it for doing load-based monitor
  2977. * detection.
  2978. *
  2979. * It will be up to the load-detect code to adjust the pipe as appropriate for
  2980. * its requirements. The pipe will be connected to no other outputs.
  2981. *
  2982. * Currently this code will only succeed if there is a pipe with no outputs
  2983. * configured for it. In the future, it could choose to temporarily disable
  2984. * some outputs to free up a pipe for its use.
  2985. *
  2986. * \return crtc, or NULL if no pipes are available.
  2987. */
  2988. /* VESA 640x480x72Hz mode to set on the pipe */
  2989. static struct drm_display_mode load_detect_mode = {
  2990. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  2991. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  2992. };
  2993. struct drm_crtc *intel_get_load_detect_pipe(struct intel_output *intel_output,
  2994. struct drm_display_mode *mode,
  2995. int *dpms_mode)
  2996. {
  2997. struct intel_crtc *intel_crtc;
  2998. struct drm_crtc *possible_crtc;
  2999. struct drm_crtc *supported_crtc =NULL;
  3000. struct drm_encoder *encoder = &intel_output->enc;
  3001. struct drm_crtc *crtc = NULL;
  3002. struct drm_device *dev = encoder->dev;
  3003. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  3004. struct drm_crtc_helper_funcs *crtc_funcs;
  3005. int i = -1;
  3006. /*
  3007. * Algorithm gets a little messy:
  3008. * - if the connector already has an assigned crtc, use it (but make
  3009. * sure it's on first)
  3010. * - try to find the first unused crtc that can drive this connector,
  3011. * and use that if we find one
  3012. * - if there are no unused crtcs available, try to use the first
  3013. * one we found that supports the connector
  3014. */
  3015. /* See if we already have a CRTC for this connector */
  3016. if (encoder->crtc) {
  3017. crtc = encoder->crtc;
  3018. /* Make sure the crtc and connector are running */
  3019. intel_crtc = to_intel_crtc(crtc);
  3020. *dpms_mode = intel_crtc->dpms_mode;
  3021. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  3022. crtc_funcs = crtc->helper_private;
  3023. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  3024. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  3025. }
  3026. return crtc;
  3027. }
  3028. /* Find an unused one (if possible) */
  3029. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  3030. i++;
  3031. if (!(encoder->possible_crtcs & (1 << i)))
  3032. continue;
  3033. if (!possible_crtc->enabled) {
  3034. crtc = possible_crtc;
  3035. break;
  3036. }
  3037. if (!supported_crtc)
  3038. supported_crtc = possible_crtc;
  3039. }
  3040. /*
  3041. * If we didn't find an unused CRTC, don't use any.
  3042. */
  3043. if (!crtc) {
  3044. return NULL;
  3045. }
  3046. encoder->crtc = crtc;
  3047. intel_output->base.encoder = encoder;
  3048. intel_output->load_detect_temp = true;
  3049. intel_crtc = to_intel_crtc(crtc);
  3050. *dpms_mode = intel_crtc->dpms_mode;
  3051. if (!crtc->enabled) {
  3052. if (!mode)
  3053. mode = &load_detect_mode;
  3054. drm_crtc_helper_set_mode(crtc, mode, 0, 0, crtc->fb);
  3055. } else {
  3056. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  3057. crtc_funcs = crtc->helper_private;
  3058. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  3059. }
  3060. /* Add this connector to the crtc */
  3061. encoder_funcs->mode_set(encoder, &crtc->mode, &crtc->mode);
  3062. encoder_funcs->commit(encoder);
  3063. }
  3064. /* let the connector get through one full cycle before testing */
  3065. intel_wait_for_vblank(dev);
  3066. return crtc;
  3067. }
  3068. void intel_release_load_detect_pipe(struct intel_output *intel_output, int dpms_mode)
  3069. {
  3070. struct drm_encoder *encoder = &intel_output->enc;
  3071. struct drm_device *dev = encoder->dev;
  3072. struct drm_crtc *crtc = encoder->crtc;
  3073. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  3074. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  3075. if (intel_output->load_detect_temp) {
  3076. encoder->crtc = NULL;
  3077. intel_output->base.encoder = NULL;
  3078. intel_output->load_detect_temp = false;
  3079. crtc->enabled = drm_helper_crtc_in_use(crtc);
  3080. drm_helper_disable_unused_functions(dev);
  3081. }
  3082. /* Switch crtc and output back off if necessary */
  3083. if (crtc->enabled && dpms_mode != DRM_MODE_DPMS_ON) {
  3084. if (encoder->crtc == crtc)
  3085. encoder_funcs->dpms(encoder, dpms_mode);
  3086. crtc_funcs->dpms(crtc, dpms_mode);
  3087. }
  3088. }
  3089. /* Returns the clock of the currently programmed mode of the given pipe. */
  3090. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  3091. {
  3092. struct drm_i915_private *dev_priv = dev->dev_private;
  3093. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3094. int pipe = intel_crtc->pipe;
  3095. u32 dpll = I915_READ((pipe == 0) ? DPLL_A : DPLL_B);
  3096. u32 fp;
  3097. intel_clock_t clock;
  3098. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  3099. fp = I915_READ((pipe == 0) ? FPA0 : FPB0);
  3100. else
  3101. fp = I915_READ((pipe == 0) ? FPA1 : FPB1);
  3102. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  3103. if (IS_IGD(dev)) {
  3104. clock.n = ffs((fp & FP_N_IGD_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  3105. clock.m2 = (fp & FP_M2_IGD_DIV_MASK) >> FP_M2_DIV_SHIFT;
  3106. } else {
  3107. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  3108. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  3109. }
  3110. if (IS_I9XX(dev)) {
  3111. if (IS_IGD(dev))
  3112. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_IGD) >>
  3113. DPLL_FPA01_P1_POST_DIV_SHIFT_IGD);
  3114. else
  3115. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  3116. DPLL_FPA01_P1_POST_DIV_SHIFT);
  3117. switch (dpll & DPLL_MODE_MASK) {
  3118. case DPLLB_MODE_DAC_SERIAL:
  3119. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  3120. 5 : 10;
  3121. break;
  3122. case DPLLB_MODE_LVDS:
  3123. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  3124. 7 : 14;
  3125. break;
  3126. default:
  3127. DRM_DEBUG("Unknown DPLL mode %08x in programmed "
  3128. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  3129. return 0;
  3130. }
  3131. /* XXX: Handle the 100Mhz refclk */
  3132. intel_clock(dev, 96000, &clock);
  3133. } else {
  3134. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  3135. if (is_lvds) {
  3136. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  3137. DPLL_FPA01_P1_POST_DIV_SHIFT);
  3138. clock.p2 = 14;
  3139. if ((dpll & PLL_REF_INPUT_MASK) ==
  3140. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  3141. /* XXX: might not be 66MHz */
  3142. intel_clock(dev, 66000, &clock);
  3143. } else
  3144. intel_clock(dev, 48000, &clock);
  3145. } else {
  3146. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  3147. clock.p1 = 2;
  3148. else {
  3149. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  3150. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  3151. }
  3152. if (dpll & PLL_P2_DIVIDE_BY_4)
  3153. clock.p2 = 4;
  3154. else
  3155. clock.p2 = 2;
  3156. intel_clock(dev, 48000, &clock);
  3157. }
  3158. }
  3159. /* XXX: It would be nice to validate the clocks, but we can't reuse
  3160. * i830PllIsValid() because it relies on the xf86_config connector
  3161. * configuration being accurate, which it isn't necessarily.
  3162. */
  3163. return clock.dot;
  3164. }
  3165. /** Returns the currently programmed mode of the given pipe. */
  3166. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  3167. struct drm_crtc *crtc)
  3168. {
  3169. struct drm_i915_private *dev_priv = dev->dev_private;
  3170. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3171. int pipe = intel_crtc->pipe;
  3172. struct drm_display_mode *mode;
  3173. int htot = I915_READ((pipe == 0) ? HTOTAL_A : HTOTAL_B);
  3174. int hsync = I915_READ((pipe == 0) ? HSYNC_A : HSYNC_B);
  3175. int vtot = I915_READ((pipe == 0) ? VTOTAL_A : VTOTAL_B);
  3176. int vsync = I915_READ((pipe == 0) ? VSYNC_A : VSYNC_B);
  3177. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  3178. if (!mode)
  3179. return NULL;
  3180. mode->clock = intel_crtc_clock_get(dev, crtc);
  3181. mode->hdisplay = (htot & 0xffff) + 1;
  3182. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  3183. mode->hsync_start = (hsync & 0xffff) + 1;
  3184. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  3185. mode->vdisplay = (vtot & 0xffff) + 1;
  3186. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  3187. mode->vsync_start = (vsync & 0xffff) + 1;
  3188. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  3189. drm_mode_set_name(mode);
  3190. drm_mode_set_crtcinfo(mode, 0);
  3191. return mode;
  3192. }
  3193. #define GPU_IDLE_TIMEOUT 500 /* ms */
  3194. /* When this timer fires, we've been idle for awhile */
  3195. static void intel_gpu_idle_timer(unsigned long arg)
  3196. {
  3197. struct drm_device *dev = (struct drm_device *)arg;
  3198. drm_i915_private_t *dev_priv = dev->dev_private;
  3199. DRM_DEBUG("idle timer fired, downclocking\n");
  3200. dev_priv->busy = false;
  3201. queue_work(dev_priv->wq, &dev_priv->idle_work);
  3202. }
  3203. void intel_increase_renderclock(struct drm_device *dev, bool schedule)
  3204. {
  3205. drm_i915_private_t *dev_priv = dev->dev_private;
  3206. if (IS_IGDNG(dev))
  3207. return;
  3208. if (!dev_priv->render_reclock_avail) {
  3209. DRM_DEBUG("not reclocking render clock\n");
  3210. return;
  3211. }
  3212. /* Restore render clock frequency to original value */
  3213. if (IS_G4X(dev) || IS_I9XX(dev))
  3214. pci_write_config_word(dev->pdev, GCFGC, dev_priv->orig_clock);
  3215. else if (IS_I85X(dev))
  3216. pci_write_config_word(dev->pdev, HPLLCC, dev_priv->orig_clock);
  3217. DRM_DEBUG("increasing render clock frequency\n");
  3218. /* Schedule downclock */
  3219. if (schedule)
  3220. mod_timer(&dev_priv->idle_timer, jiffies +
  3221. msecs_to_jiffies(GPU_IDLE_TIMEOUT));
  3222. }
  3223. void intel_decrease_renderclock(struct drm_device *dev)
  3224. {
  3225. drm_i915_private_t *dev_priv = dev->dev_private;
  3226. if (IS_IGDNG(dev))
  3227. return;
  3228. if (!dev_priv->render_reclock_avail) {
  3229. DRM_DEBUG("not reclocking render clock\n");
  3230. return;
  3231. }
  3232. if (IS_G4X(dev)) {
  3233. u16 gcfgc;
  3234. /* Adjust render clock... */
  3235. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3236. /* Down to minimum... */
  3237. gcfgc &= ~GM45_GC_RENDER_CLOCK_MASK;
  3238. gcfgc |= GM45_GC_RENDER_CLOCK_266_MHZ;
  3239. pci_write_config_word(dev->pdev, GCFGC, gcfgc);
  3240. } else if (IS_I965G(dev)) {
  3241. u16 gcfgc;
  3242. /* Adjust render clock... */
  3243. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3244. /* Down to minimum... */
  3245. gcfgc &= ~I965_GC_RENDER_CLOCK_MASK;
  3246. gcfgc |= I965_GC_RENDER_CLOCK_267_MHZ;
  3247. pci_write_config_word(dev->pdev, GCFGC, gcfgc);
  3248. } else if (IS_I945G(dev) || IS_I945GM(dev)) {
  3249. u16 gcfgc;
  3250. /* Adjust render clock... */
  3251. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3252. /* Down to minimum... */
  3253. gcfgc &= ~I945_GC_RENDER_CLOCK_MASK;
  3254. gcfgc |= I945_GC_RENDER_CLOCK_166_MHZ;
  3255. pci_write_config_word(dev->pdev, GCFGC, gcfgc);
  3256. } else if (IS_I915G(dev)) {
  3257. u16 gcfgc;
  3258. /* Adjust render clock... */
  3259. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3260. /* Down to minimum... */
  3261. gcfgc &= ~I915_GC_RENDER_CLOCK_MASK;
  3262. gcfgc |= I915_GC_RENDER_CLOCK_166_MHZ;
  3263. pci_write_config_word(dev->pdev, GCFGC, gcfgc);
  3264. } else if (IS_I85X(dev)) {
  3265. u16 hpllcc;
  3266. /* Adjust render clock... */
  3267. pci_read_config_word(dev->pdev, HPLLCC, &hpllcc);
  3268. /* Up to maximum... */
  3269. hpllcc &= ~GC_CLOCK_CONTROL_MASK;
  3270. hpllcc |= GC_CLOCK_133_200;
  3271. pci_write_config_word(dev->pdev, HPLLCC, hpllcc);
  3272. }
  3273. DRM_DEBUG("decreasing render clock frequency\n");
  3274. }
  3275. /* Note that no increase function is needed for this - increase_renderclock()
  3276. * will also rewrite these bits
  3277. */
  3278. void intel_decrease_displayclock(struct drm_device *dev)
  3279. {
  3280. if (IS_IGDNG(dev))
  3281. return;
  3282. if (IS_I945G(dev) || IS_I945GM(dev) || IS_I915G(dev) ||
  3283. IS_I915GM(dev)) {
  3284. u16 gcfgc;
  3285. /* Adjust render clock... */
  3286. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3287. /* Down to minimum... */
  3288. gcfgc &= ~0xf0;
  3289. gcfgc |= 0x80;
  3290. pci_write_config_word(dev->pdev, GCFGC, gcfgc);
  3291. }
  3292. }
  3293. #define CRTC_IDLE_TIMEOUT 1000 /* ms */
  3294. static void intel_crtc_idle_timer(unsigned long arg)
  3295. {
  3296. struct intel_crtc *intel_crtc = (struct intel_crtc *)arg;
  3297. struct drm_crtc *crtc = &intel_crtc->base;
  3298. drm_i915_private_t *dev_priv = crtc->dev->dev_private;
  3299. DRM_DEBUG("idle timer fired, downclocking\n");
  3300. intel_crtc->busy = false;
  3301. queue_work(dev_priv->wq, &dev_priv->idle_work);
  3302. }
  3303. static void intel_increase_pllclock(struct drm_crtc *crtc, bool schedule)
  3304. {
  3305. struct drm_device *dev = crtc->dev;
  3306. drm_i915_private_t *dev_priv = dev->dev_private;
  3307. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3308. int pipe = intel_crtc->pipe;
  3309. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  3310. int dpll = I915_READ(dpll_reg);
  3311. if (IS_IGDNG(dev))
  3312. return;
  3313. if (!dev_priv->lvds_downclock_avail)
  3314. return;
  3315. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  3316. DRM_DEBUG("upclocking LVDS\n");
  3317. /* Unlock panel regs */
  3318. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) | (0xabcd << 16));
  3319. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  3320. I915_WRITE(dpll_reg, dpll);
  3321. dpll = I915_READ(dpll_reg);
  3322. intel_wait_for_vblank(dev);
  3323. dpll = I915_READ(dpll_reg);
  3324. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  3325. DRM_DEBUG("failed to upclock LVDS!\n");
  3326. /* ...and lock them again */
  3327. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
  3328. }
  3329. /* Schedule downclock */
  3330. if (schedule)
  3331. mod_timer(&intel_crtc->idle_timer, jiffies +
  3332. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  3333. }
  3334. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  3335. {
  3336. struct drm_device *dev = crtc->dev;
  3337. drm_i915_private_t *dev_priv = dev->dev_private;
  3338. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3339. int pipe = intel_crtc->pipe;
  3340. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  3341. int dpll = I915_READ(dpll_reg);
  3342. if (IS_IGDNG(dev))
  3343. return;
  3344. if (!dev_priv->lvds_downclock_avail)
  3345. return;
  3346. /*
  3347. * Since this is called by a timer, we should never get here in
  3348. * the manual case.
  3349. */
  3350. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  3351. DRM_DEBUG("downclocking LVDS\n");
  3352. /* Unlock panel regs */
  3353. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) | (0xabcd << 16));
  3354. dpll |= DISPLAY_RATE_SELECT_FPA1;
  3355. I915_WRITE(dpll_reg, dpll);
  3356. dpll = I915_READ(dpll_reg);
  3357. intel_wait_for_vblank(dev);
  3358. dpll = I915_READ(dpll_reg);
  3359. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  3360. DRM_DEBUG("failed to downclock LVDS!\n");
  3361. /* ...and lock them again */
  3362. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
  3363. }
  3364. }
  3365. /**
  3366. * intel_idle_update - adjust clocks for idleness
  3367. * @work: work struct
  3368. *
  3369. * Either the GPU or display (or both) went idle. Check the busy status
  3370. * here and adjust the CRTC and GPU clocks as necessary.
  3371. */
  3372. static void intel_idle_update(struct work_struct *work)
  3373. {
  3374. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  3375. idle_work);
  3376. struct drm_device *dev = dev_priv->dev;
  3377. struct drm_crtc *crtc;
  3378. struct intel_crtc *intel_crtc;
  3379. if (!i915_powersave)
  3380. return;
  3381. mutex_lock(&dev->struct_mutex);
  3382. /* GPU isn't processing, downclock it. */
  3383. if (!dev_priv->busy) {
  3384. intel_decrease_renderclock(dev);
  3385. intel_decrease_displayclock(dev);
  3386. }
  3387. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3388. /* Skip inactive CRTCs */
  3389. if (!crtc->fb)
  3390. continue;
  3391. intel_crtc = to_intel_crtc(crtc);
  3392. if (!intel_crtc->busy)
  3393. intel_decrease_pllclock(crtc);
  3394. }
  3395. mutex_unlock(&dev->struct_mutex);
  3396. }
  3397. /**
  3398. * intel_mark_busy - mark the GPU and possibly the display busy
  3399. * @dev: drm device
  3400. * @obj: object we're operating on
  3401. *
  3402. * Callers can use this function to indicate that the GPU is busy processing
  3403. * commands. If @obj matches one of the CRTC objects (i.e. it's a scanout
  3404. * buffer), we'll also mark the display as busy, so we know to increase its
  3405. * clock frequency.
  3406. */
  3407. void intel_mark_busy(struct drm_device *dev, struct drm_gem_object *obj)
  3408. {
  3409. drm_i915_private_t *dev_priv = dev->dev_private;
  3410. struct drm_crtc *crtc = NULL;
  3411. struct intel_framebuffer *intel_fb;
  3412. struct intel_crtc *intel_crtc;
  3413. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  3414. return;
  3415. dev_priv->busy = true;
  3416. intel_increase_renderclock(dev, true);
  3417. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3418. if (!crtc->fb)
  3419. continue;
  3420. intel_crtc = to_intel_crtc(crtc);
  3421. intel_fb = to_intel_framebuffer(crtc->fb);
  3422. if (intel_fb->obj == obj) {
  3423. if (!intel_crtc->busy) {
  3424. /* Non-busy -> busy, upclock */
  3425. intel_increase_pllclock(crtc, true);
  3426. intel_crtc->busy = true;
  3427. } else {
  3428. /* Busy -> busy, put off timer */
  3429. mod_timer(&intel_crtc->idle_timer, jiffies +
  3430. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  3431. }
  3432. }
  3433. }
  3434. }
  3435. static void intel_crtc_destroy(struct drm_crtc *crtc)
  3436. {
  3437. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3438. drm_crtc_cleanup(crtc);
  3439. kfree(intel_crtc);
  3440. }
  3441. static const struct drm_crtc_helper_funcs intel_helper_funcs = {
  3442. .dpms = intel_crtc_dpms,
  3443. .mode_fixup = intel_crtc_mode_fixup,
  3444. .mode_set = intel_crtc_mode_set,
  3445. .mode_set_base = intel_pipe_set_base,
  3446. .prepare = intel_crtc_prepare,
  3447. .commit = intel_crtc_commit,
  3448. .load_lut = intel_crtc_load_lut,
  3449. };
  3450. static const struct drm_crtc_funcs intel_crtc_funcs = {
  3451. .cursor_set = intel_crtc_cursor_set,
  3452. .cursor_move = intel_crtc_cursor_move,
  3453. .gamma_set = intel_crtc_gamma_set,
  3454. .set_config = drm_crtc_helper_set_config,
  3455. .destroy = intel_crtc_destroy,
  3456. };
  3457. static void intel_crtc_init(struct drm_device *dev, int pipe)
  3458. {
  3459. struct intel_crtc *intel_crtc;
  3460. int i;
  3461. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  3462. if (intel_crtc == NULL)
  3463. return;
  3464. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  3465. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  3466. intel_crtc->pipe = pipe;
  3467. intel_crtc->plane = pipe;
  3468. for (i = 0; i < 256; i++) {
  3469. intel_crtc->lut_r[i] = i;
  3470. intel_crtc->lut_g[i] = i;
  3471. intel_crtc->lut_b[i] = i;
  3472. }
  3473. /* Swap pipes & planes for FBC on pre-965 */
  3474. intel_crtc->pipe = pipe;
  3475. intel_crtc->plane = pipe;
  3476. if (IS_MOBILE(dev) && (IS_I9XX(dev) && !IS_I965G(dev))) {
  3477. DRM_DEBUG("swapping pipes & planes for FBC\n");
  3478. intel_crtc->plane = ((pipe == 0) ? 1 : 0);
  3479. }
  3480. intel_crtc->cursor_addr = 0;
  3481. intel_crtc->dpms_mode = DRM_MODE_DPMS_OFF;
  3482. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  3483. intel_crtc->busy = false;
  3484. setup_timer(&intel_crtc->idle_timer, intel_crtc_idle_timer,
  3485. (unsigned long)intel_crtc);
  3486. }
  3487. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  3488. struct drm_file *file_priv)
  3489. {
  3490. drm_i915_private_t *dev_priv = dev->dev_private;
  3491. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  3492. struct drm_mode_object *drmmode_obj;
  3493. struct intel_crtc *crtc;
  3494. if (!dev_priv) {
  3495. DRM_ERROR("called with no initialization\n");
  3496. return -EINVAL;
  3497. }
  3498. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  3499. DRM_MODE_OBJECT_CRTC);
  3500. if (!drmmode_obj) {
  3501. DRM_ERROR("no such CRTC id\n");
  3502. return -EINVAL;
  3503. }
  3504. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  3505. pipe_from_crtc_id->pipe = crtc->pipe;
  3506. return 0;
  3507. }
  3508. struct drm_crtc *intel_get_crtc_from_pipe(struct drm_device *dev, int pipe)
  3509. {
  3510. struct drm_crtc *crtc = NULL;
  3511. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3512. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3513. if (intel_crtc->pipe == pipe)
  3514. break;
  3515. }
  3516. return crtc;
  3517. }
  3518. static int intel_connector_clones(struct drm_device *dev, int type_mask)
  3519. {
  3520. int index_mask = 0;
  3521. struct drm_connector *connector;
  3522. int entry = 0;
  3523. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  3524. struct intel_output *intel_output = to_intel_output(connector);
  3525. if (type_mask & intel_output->clone_mask)
  3526. index_mask |= (1 << entry);
  3527. entry++;
  3528. }
  3529. return index_mask;
  3530. }
  3531. static void intel_setup_outputs(struct drm_device *dev)
  3532. {
  3533. struct drm_i915_private *dev_priv = dev->dev_private;
  3534. struct drm_connector *connector;
  3535. intel_crt_init(dev);
  3536. /* Set up integrated LVDS */
  3537. if (IS_MOBILE(dev) && !IS_I830(dev))
  3538. intel_lvds_init(dev);
  3539. if (IS_IGDNG(dev)) {
  3540. int found;
  3541. if (IS_MOBILE(dev) && (I915_READ(DP_A) & DP_DETECTED))
  3542. intel_dp_init(dev, DP_A);
  3543. if (I915_READ(HDMIB) & PORT_DETECTED) {
  3544. /* check SDVOB */
  3545. /* found = intel_sdvo_init(dev, HDMIB); */
  3546. found = 0;
  3547. if (!found)
  3548. intel_hdmi_init(dev, HDMIB);
  3549. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  3550. intel_dp_init(dev, PCH_DP_B);
  3551. }
  3552. if (I915_READ(HDMIC) & PORT_DETECTED)
  3553. intel_hdmi_init(dev, HDMIC);
  3554. if (I915_READ(HDMID) & PORT_DETECTED)
  3555. intel_hdmi_init(dev, HDMID);
  3556. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  3557. intel_dp_init(dev, PCH_DP_C);
  3558. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  3559. intel_dp_init(dev, PCH_DP_D);
  3560. } else if (IS_I9XX(dev)) {
  3561. bool found = false;
  3562. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  3563. found = intel_sdvo_init(dev, SDVOB);
  3564. if (!found && SUPPORTS_INTEGRATED_HDMI(dev))
  3565. intel_hdmi_init(dev, SDVOB);
  3566. if (!found && SUPPORTS_INTEGRATED_DP(dev))
  3567. intel_dp_init(dev, DP_B);
  3568. }
  3569. /* Before G4X SDVOC doesn't have its own detect register */
  3570. if (I915_READ(SDVOB) & SDVO_DETECTED)
  3571. found = intel_sdvo_init(dev, SDVOC);
  3572. if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
  3573. if (SUPPORTS_INTEGRATED_HDMI(dev))
  3574. intel_hdmi_init(dev, SDVOC);
  3575. if (SUPPORTS_INTEGRATED_DP(dev))
  3576. intel_dp_init(dev, DP_C);
  3577. }
  3578. if (SUPPORTS_INTEGRATED_DP(dev) && (I915_READ(DP_D) & DP_DETECTED))
  3579. intel_dp_init(dev, DP_D);
  3580. } else
  3581. intel_dvo_init(dev);
  3582. if (IS_I9XX(dev) && IS_MOBILE(dev) && !IS_IGDNG(dev))
  3583. intel_tv_init(dev);
  3584. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  3585. struct intel_output *intel_output = to_intel_output(connector);
  3586. struct drm_encoder *encoder = &intel_output->enc;
  3587. encoder->possible_crtcs = intel_output->crtc_mask;
  3588. encoder->possible_clones = intel_connector_clones(dev,
  3589. intel_output->clone_mask);
  3590. }
  3591. }
  3592. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  3593. {
  3594. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  3595. struct drm_device *dev = fb->dev;
  3596. if (fb->fbdev)
  3597. intelfb_remove(dev, fb);
  3598. drm_framebuffer_cleanup(fb);
  3599. mutex_lock(&dev->struct_mutex);
  3600. drm_gem_object_unreference(intel_fb->obj);
  3601. mutex_unlock(&dev->struct_mutex);
  3602. kfree(intel_fb);
  3603. }
  3604. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  3605. struct drm_file *file_priv,
  3606. unsigned int *handle)
  3607. {
  3608. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  3609. struct drm_gem_object *object = intel_fb->obj;
  3610. return drm_gem_handle_create(file_priv, object, handle);
  3611. }
  3612. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  3613. .destroy = intel_user_framebuffer_destroy,
  3614. .create_handle = intel_user_framebuffer_create_handle,
  3615. };
  3616. int intel_framebuffer_create(struct drm_device *dev,
  3617. struct drm_mode_fb_cmd *mode_cmd,
  3618. struct drm_framebuffer **fb,
  3619. struct drm_gem_object *obj)
  3620. {
  3621. struct intel_framebuffer *intel_fb;
  3622. int ret;
  3623. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  3624. if (!intel_fb)
  3625. return -ENOMEM;
  3626. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  3627. if (ret) {
  3628. DRM_ERROR("framebuffer init failed %d\n", ret);
  3629. return ret;
  3630. }
  3631. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  3632. intel_fb->obj = obj;
  3633. *fb = &intel_fb->base;
  3634. return 0;
  3635. }
  3636. static struct drm_framebuffer *
  3637. intel_user_framebuffer_create(struct drm_device *dev,
  3638. struct drm_file *filp,
  3639. struct drm_mode_fb_cmd *mode_cmd)
  3640. {
  3641. struct drm_gem_object *obj;
  3642. struct drm_framebuffer *fb;
  3643. int ret;
  3644. obj = drm_gem_object_lookup(dev, filp, mode_cmd->handle);
  3645. if (!obj)
  3646. return NULL;
  3647. ret = intel_framebuffer_create(dev, mode_cmd, &fb, obj);
  3648. if (ret) {
  3649. mutex_lock(&dev->struct_mutex);
  3650. drm_gem_object_unreference(obj);
  3651. mutex_unlock(&dev->struct_mutex);
  3652. return NULL;
  3653. }
  3654. return fb;
  3655. }
  3656. static const struct drm_mode_config_funcs intel_mode_funcs = {
  3657. .fb_create = intel_user_framebuffer_create,
  3658. .fb_changed = intelfb_probe,
  3659. };
  3660. void intel_init_clock_gating(struct drm_device *dev)
  3661. {
  3662. struct drm_i915_private *dev_priv = dev->dev_private;
  3663. /*
  3664. * Disable clock gating reported to work incorrectly according to the
  3665. * specs, but enable as much else as we can.
  3666. */
  3667. if (IS_IGDNG(dev)) {
  3668. return;
  3669. } else if (IS_G4X(dev)) {
  3670. uint32_t dspclk_gate;
  3671. I915_WRITE(RENCLK_GATE_D1, 0);
  3672. I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
  3673. GS_UNIT_CLOCK_GATE_DISABLE |
  3674. CL_UNIT_CLOCK_GATE_DISABLE);
  3675. I915_WRITE(RAMCLK_GATE_D, 0);
  3676. dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
  3677. OVRUNIT_CLOCK_GATE_DISABLE |
  3678. OVCUNIT_CLOCK_GATE_DISABLE;
  3679. if (IS_GM45(dev))
  3680. dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
  3681. I915_WRITE(DSPCLK_GATE_D, dspclk_gate);
  3682. } else if (IS_I965GM(dev)) {
  3683. I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
  3684. I915_WRITE(RENCLK_GATE_D2, 0);
  3685. I915_WRITE(DSPCLK_GATE_D, 0);
  3686. I915_WRITE(RAMCLK_GATE_D, 0);
  3687. I915_WRITE16(DEUC, 0);
  3688. } else if (IS_I965G(dev)) {
  3689. I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
  3690. I965_RCC_CLOCK_GATE_DISABLE |
  3691. I965_RCPB_CLOCK_GATE_DISABLE |
  3692. I965_ISC_CLOCK_GATE_DISABLE |
  3693. I965_FBC_CLOCK_GATE_DISABLE);
  3694. I915_WRITE(RENCLK_GATE_D2, 0);
  3695. } else if (IS_I9XX(dev)) {
  3696. u32 dstate = I915_READ(D_STATE);
  3697. dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
  3698. DSTATE_DOT_CLOCK_GATING;
  3699. I915_WRITE(D_STATE, dstate);
  3700. } else if (IS_I855(dev) || IS_I865G(dev)) {
  3701. I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
  3702. } else if (IS_I830(dev)) {
  3703. I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE);
  3704. }
  3705. /*
  3706. * GPU can automatically power down the render unit if given a page
  3707. * to save state.
  3708. */
  3709. if (I915_HAS_RC6(dev)) {
  3710. struct drm_gem_object *pwrctx;
  3711. struct drm_i915_gem_object *obj_priv;
  3712. int ret;
  3713. pwrctx = drm_gem_object_alloc(dev, 4096);
  3714. if (!pwrctx) {
  3715. DRM_DEBUG("failed to alloc power context, RC6 disabled\n");
  3716. goto out;
  3717. }
  3718. ret = i915_gem_object_pin(pwrctx, 4096);
  3719. if (ret) {
  3720. DRM_ERROR("failed to pin power context: %d\n", ret);
  3721. drm_gem_object_unreference(pwrctx);
  3722. goto out;
  3723. }
  3724. i915_gem_object_set_to_gtt_domain(pwrctx, 1);
  3725. obj_priv = pwrctx->driver_private;
  3726. I915_WRITE(PWRCTXA, obj_priv->gtt_offset | PWRCTX_EN);
  3727. I915_WRITE(MCHBAR_RENDER_STANDBY,
  3728. I915_READ(MCHBAR_RENDER_STANDBY) & ~RCX_SW_EXIT);
  3729. dev_priv->pwrctx = pwrctx;
  3730. }
  3731. out:
  3732. return;
  3733. }
  3734. /* Set up chip specific display functions */
  3735. static void intel_init_display(struct drm_device *dev)
  3736. {
  3737. struct drm_i915_private *dev_priv = dev->dev_private;
  3738. /* We always want a DPMS function */
  3739. if (IS_IGDNG(dev))
  3740. dev_priv->display.dpms = igdng_crtc_dpms;
  3741. else
  3742. dev_priv->display.dpms = i9xx_crtc_dpms;
  3743. /* Only mobile has FBC, leave pointers NULL for other chips */
  3744. if (IS_MOBILE(dev)) {
  3745. if (IS_GM45(dev)) {
  3746. dev_priv->display.fbc_enabled = g4x_fbc_enabled;
  3747. dev_priv->display.enable_fbc = g4x_enable_fbc;
  3748. dev_priv->display.disable_fbc = g4x_disable_fbc;
  3749. } else if (IS_I965GM(dev) || IS_I945GM(dev) || IS_I915GM(dev)) {
  3750. dev_priv->display.fbc_enabled = i8xx_fbc_enabled;
  3751. dev_priv->display.enable_fbc = i8xx_enable_fbc;
  3752. dev_priv->display.disable_fbc = i8xx_disable_fbc;
  3753. }
  3754. /* 855GM needs testing */
  3755. }
  3756. /* Returns the core display clock speed */
  3757. if (IS_I945G(dev))
  3758. dev_priv->display.get_display_clock_speed =
  3759. i945_get_display_clock_speed;
  3760. else if (IS_I915G(dev))
  3761. dev_priv->display.get_display_clock_speed =
  3762. i915_get_display_clock_speed;
  3763. else if (IS_I945GM(dev) || IS_845G(dev) || IS_IGDGM(dev))
  3764. dev_priv->display.get_display_clock_speed =
  3765. i9xx_misc_get_display_clock_speed;
  3766. else if (IS_I915GM(dev))
  3767. dev_priv->display.get_display_clock_speed =
  3768. i915gm_get_display_clock_speed;
  3769. else if (IS_I865G(dev))
  3770. dev_priv->display.get_display_clock_speed =
  3771. i865_get_display_clock_speed;
  3772. else if (IS_I855(dev))
  3773. dev_priv->display.get_display_clock_speed =
  3774. i855_get_display_clock_speed;
  3775. else /* 852, 830 */
  3776. dev_priv->display.get_display_clock_speed =
  3777. i830_get_display_clock_speed;
  3778. /* For FIFO watermark updates */
  3779. if (IS_IGDNG(dev))
  3780. dev_priv->display.update_wm = NULL;
  3781. else if (IS_G4X(dev))
  3782. dev_priv->display.update_wm = g4x_update_wm;
  3783. else if (IS_I965G(dev))
  3784. dev_priv->display.update_wm = i965_update_wm;
  3785. else if (IS_I9XX(dev) || IS_MOBILE(dev)) {
  3786. dev_priv->display.update_wm = i9xx_update_wm;
  3787. dev_priv->display.get_fifo_size = i9xx_get_fifo_size;
  3788. } else {
  3789. if (IS_I85X(dev))
  3790. dev_priv->display.get_fifo_size = i85x_get_fifo_size;
  3791. else if (IS_845G(dev))
  3792. dev_priv->display.get_fifo_size = i845_get_fifo_size;
  3793. else
  3794. dev_priv->display.get_fifo_size = i830_get_fifo_size;
  3795. dev_priv->display.update_wm = i830_update_wm;
  3796. }
  3797. }
  3798. void intel_modeset_init(struct drm_device *dev)
  3799. {
  3800. struct drm_i915_private *dev_priv = dev->dev_private;
  3801. int num_pipe;
  3802. int i;
  3803. drm_mode_config_init(dev);
  3804. dev->mode_config.min_width = 0;
  3805. dev->mode_config.min_height = 0;
  3806. dev->mode_config.funcs = (void *)&intel_mode_funcs;
  3807. intel_init_display(dev);
  3808. if (IS_I965G(dev)) {
  3809. dev->mode_config.max_width = 8192;
  3810. dev->mode_config.max_height = 8192;
  3811. } else if (IS_I9XX(dev)) {
  3812. dev->mode_config.max_width = 4096;
  3813. dev->mode_config.max_height = 4096;
  3814. } else {
  3815. dev->mode_config.max_width = 2048;
  3816. dev->mode_config.max_height = 2048;
  3817. }
  3818. /* set memory base */
  3819. if (IS_I9XX(dev))
  3820. dev->mode_config.fb_base = pci_resource_start(dev->pdev, 2);
  3821. else
  3822. dev->mode_config.fb_base = pci_resource_start(dev->pdev, 0);
  3823. if (IS_MOBILE(dev) || IS_I9XX(dev))
  3824. num_pipe = 2;
  3825. else
  3826. num_pipe = 1;
  3827. DRM_DEBUG("%d display pipe%s available.\n",
  3828. num_pipe, num_pipe > 1 ? "s" : "");
  3829. if (IS_I85X(dev))
  3830. pci_read_config_word(dev->pdev, HPLLCC, &dev_priv->orig_clock);
  3831. else if (IS_I9XX(dev) || IS_G4X(dev))
  3832. pci_read_config_word(dev->pdev, GCFGC, &dev_priv->orig_clock);
  3833. for (i = 0; i < num_pipe; i++) {
  3834. intel_crtc_init(dev, i);
  3835. }
  3836. intel_setup_outputs(dev);
  3837. intel_init_clock_gating(dev);
  3838. INIT_WORK(&dev_priv->idle_work, intel_idle_update);
  3839. setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer,
  3840. (unsigned long)dev);
  3841. }
  3842. void intel_modeset_cleanup(struct drm_device *dev)
  3843. {
  3844. struct drm_i915_private *dev_priv = dev->dev_private;
  3845. struct drm_crtc *crtc;
  3846. struct intel_crtc *intel_crtc;
  3847. mutex_lock(&dev->struct_mutex);
  3848. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3849. /* Skip inactive CRTCs */
  3850. if (!crtc->fb)
  3851. continue;
  3852. intel_crtc = to_intel_crtc(crtc);
  3853. intel_increase_pllclock(crtc, false);
  3854. del_timer_sync(&intel_crtc->idle_timer);
  3855. }
  3856. intel_increase_renderclock(dev, false);
  3857. del_timer_sync(&dev_priv->idle_timer);
  3858. mutex_unlock(&dev->struct_mutex);
  3859. if (dev_priv->display.disable_fbc)
  3860. dev_priv->display.disable_fbc(dev);
  3861. if (dev_priv->pwrctx) {
  3862. i915_gem_object_unpin(dev_priv->pwrctx);
  3863. drm_gem_object_unreference(dev_priv->pwrctx);
  3864. }
  3865. drm_mode_config_cleanup(dev);
  3866. }
  3867. /* current intel driver doesn't take advantage of encoders
  3868. always give back the encoder for the connector
  3869. */
  3870. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  3871. {
  3872. struct intel_output *intel_output = to_intel_output(connector);
  3873. return &intel_output->enc;
  3874. }
  3875. /*
  3876. * set vga decode state - true == enable VGA decode
  3877. */
  3878. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  3879. {
  3880. struct drm_i915_private *dev_priv = dev->dev_private;
  3881. u16 gmch_ctrl;
  3882. pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
  3883. if (state)
  3884. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  3885. else
  3886. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  3887. pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
  3888. return 0;
  3889. }