intel_display.c 118 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120
  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 max_n;
  795. bool found;
  796. int err_most = 47;
  797. found = false;
  798. /* eDP has only 2 clock choice, no n/m/p setting */
  799. if (HAS_eDP)
  800. return true;
  801. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  802. return intel_find_pll_igdng_dp(limit, crtc, target,
  803. refclk, best_clock);
  804. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  805. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  806. LVDS_CLKB_POWER_UP)
  807. clock.p2 = limit->p2.p2_fast;
  808. else
  809. clock.p2 = limit->p2.p2_slow;
  810. } else {
  811. if (target < limit->p2.dot_limit)
  812. clock.p2 = limit->p2.p2_slow;
  813. else
  814. clock.p2 = limit->p2.p2_fast;
  815. }
  816. memset(best_clock, 0, sizeof(*best_clock));
  817. max_n = limit->n.max;
  818. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  819. /* based on hardware requriment prefer smaller n to precision */
  820. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  821. /* based on hardware requirment prefere larger m1,m2 */
  822. for (clock.m1 = limit->m1.max;
  823. clock.m1 >= limit->m1.min; clock.m1--) {
  824. for (clock.m2 = limit->m2.max;
  825. clock.m2 >= limit->m2.min; clock.m2--) {
  826. int this_err;
  827. intel_clock(dev, refclk, &clock);
  828. if (!intel_PLL_is_valid(crtc, &clock))
  829. continue;
  830. this_err = abs((10000 - (target*10000/clock.dot)));
  831. if (this_err < err_most) {
  832. *best_clock = clock;
  833. err_most = this_err;
  834. max_n = clock.n;
  835. found = true;
  836. /* found on first matching */
  837. goto out;
  838. }
  839. }
  840. }
  841. }
  842. }
  843. out:
  844. return found;
  845. }
  846. /* DisplayPort has only two frequencies, 162MHz and 270MHz */
  847. static bool
  848. intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  849. int target, int refclk, intel_clock_t *best_clock)
  850. {
  851. intel_clock_t clock;
  852. if (target < 200000) {
  853. clock.p1 = 2;
  854. clock.p2 = 10;
  855. clock.n = 2;
  856. clock.m1 = 23;
  857. clock.m2 = 8;
  858. } else {
  859. clock.p1 = 1;
  860. clock.p2 = 10;
  861. clock.n = 1;
  862. clock.m1 = 14;
  863. clock.m2 = 2;
  864. }
  865. clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
  866. clock.p = (clock.p1 * clock.p2);
  867. clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
  868. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  869. return true;
  870. }
  871. void
  872. intel_wait_for_vblank(struct drm_device *dev)
  873. {
  874. /* Wait for 20ms, i.e. one cycle at 50hz. */
  875. mdelay(20);
  876. }
  877. /* Parameters have changed, update FBC info */
  878. static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  879. {
  880. struct drm_device *dev = crtc->dev;
  881. struct drm_i915_private *dev_priv = dev->dev_private;
  882. struct drm_framebuffer *fb = crtc->fb;
  883. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  884. struct drm_i915_gem_object *obj_priv = intel_fb->obj->driver_private;
  885. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  886. int plane, i;
  887. u32 fbc_ctl, fbc_ctl2;
  888. dev_priv->cfb_pitch = dev_priv->cfb_size / FBC_LL_SIZE;
  889. if (fb->pitch < dev_priv->cfb_pitch)
  890. dev_priv->cfb_pitch = fb->pitch;
  891. /* FBC_CTL wants 64B units */
  892. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  893. dev_priv->cfb_fence = obj_priv->fence_reg;
  894. dev_priv->cfb_plane = intel_crtc->plane;
  895. plane = dev_priv->cfb_plane == 0 ? FBC_CTL_PLANEA : FBC_CTL_PLANEB;
  896. /* Clear old tags */
  897. for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++)
  898. I915_WRITE(FBC_TAG + (i * 4), 0);
  899. /* Set it up... */
  900. fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | plane;
  901. if (obj_priv->tiling_mode != I915_TILING_NONE)
  902. fbc_ctl2 |= FBC_CTL_CPU_FENCE;
  903. I915_WRITE(FBC_CONTROL2, fbc_ctl2);
  904. I915_WRITE(FBC_FENCE_OFF, crtc->y);
  905. /* enable it... */
  906. fbc_ctl = FBC_CTL_EN | FBC_CTL_PERIODIC;
  907. fbc_ctl |= (dev_priv->cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT;
  908. fbc_ctl |= (interval & 0x2fff) << FBC_CTL_INTERVAL_SHIFT;
  909. if (obj_priv->tiling_mode != I915_TILING_NONE)
  910. fbc_ctl |= dev_priv->cfb_fence;
  911. I915_WRITE(FBC_CONTROL, fbc_ctl);
  912. DRM_DEBUG("enabled FBC, pitch %ld, yoff %d, plane %d, ",
  913. dev_priv->cfb_pitch, crtc->y, dev_priv->cfb_plane);
  914. }
  915. void i8xx_disable_fbc(struct drm_device *dev)
  916. {
  917. struct drm_i915_private *dev_priv = dev->dev_private;
  918. u32 fbc_ctl;
  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. /**
  936. * intel_update_fbc - enable/disable FBC as needed
  937. * @crtc: CRTC to point the compressor at
  938. * @mode: mode in use
  939. *
  940. * Set up the framebuffer compression hardware at mode set time. We
  941. * enable it if possible:
  942. * - plane A only (on pre-965)
  943. * - no pixel mulitply/line duplication
  944. * - no alpha buffer discard
  945. * - no dual wide
  946. * - framebuffer <= 2048 in width, 1536 in height
  947. *
  948. * We can't assume that any compression will take place (worst case),
  949. * so the compressed buffer has to be the same size as the uncompressed
  950. * one. It also must reside (along with the line length buffer) in
  951. * stolen memory.
  952. *
  953. * We need to enable/disable FBC on a global basis.
  954. */
  955. static void intel_update_fbc(struct drm_crtc *crtc,
  956. struct drm_display_mode *mode)
  957. {
  958. struct drm_device *dev = crtc->dev;
  959. struct drm_i915_private *dev_priv = dev->dev_private;
  960. struct drm_framebuffer *fb = crtc->fb;
  961. struct intel_framebuffer *intel_fb;
  962. struct drm_i915_gem_object *obj_priv;
  963. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  964. int plane = intel_crtc->plane;
  965. if (!i915_powersave)
  966. return;
  967. if (!crtc->fb)
  968. return;
  969. intel_fb = to_intel_framebuffer(fb);
  970. obj_priv = intel_fb->obj->driver_private;
  971. /*
  972. * If FBC is already on, we just have to verify that we can
  973. * keep it that way...
  974. * Need to disable if:
  975. * - changing FBC params (stride, fence, mode)
  976. * - new fb is too large to fit in compressed buffer
  977. * - going to an unsupported config (interlace, pixel multiply, etc.)
  978. */
  979. if (intel_fb->obj->size > dev_priv->cfb_size) {
  980. DRM_DEBUG("framebuffer too large, disabling compression\n");
  981. goto out_disable;
  982. }
  983. if ((mode->flags & DRM_MODE_FLAG_INTERLACE) ||
  984. (mode->flags & DRM_MODE_FLAG_DBLSCAN)) {
  985. DRM_DEBUG("mode incompatible with compression, disabling\n");
  986. goto out_disable;
  987. }
  988. if ((mode->hdisplay > 2048) ||
  989. (mode->vdisplay > 1536)) {
  990. DRM_DEBUG("mode too large for compression, disabling\n");
  991. goto out_disable;
  992. }
  993. if (IS_I9XX(dev) && plane != 0) {
  994. DRM_DEBUG("plane not 0, disabling compression\n");
  995. goto out_disable;
  996. }
  997. if (obj_priv->tiling_mode != I915_TILING_X) {
  998. DRM_DEBUG("framebuffer not tiled, disabling compression\n");
  999. goto out_disable;
  1000. }
  1001. if (i8xx_fbc_enabled(crtc)) {
  1002. /* We can re-enable it in this case, but need to update pitch */
  1003. if (fb->pitch > dev_priv->cfb_pitch)
  1004. i8xx_disable_fbc(dev);
  1005. if (obj_priv->fence_reg != dev_priv->cfb_fence)
  1006. i8xx_disable_fbc(dev);
  1007. if (plane != dev_priv->cfb_plane)
  1008. i8xx_disable_fbc(dev);
  1009. }
  1010. if (!i8xx_fbc_enabled(crtc)) {
  1011. /* Now try to turn it back on if possible */
  1012. i8xx_enable_fbc(crtc, 500);
  1013. }
  1014. return;
  1015. out_disable:
  1016. DRM_DEBUG("unsupported config, disabling FBC\n");
  1017. /* Multiple disables should be harmless */
  1018. if (i8xx_fbc_enabled(crtc))
  1019. i8xx_disable_fbc(dev);
  1020. }
  1021. static int
  1022. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  1023. struct drm_framebuffer *old_fb)
  1024. {
  1025. struct drm_device *dev = crtc->dev;
  1026. struct drm_i915_private *dev_priv = dev->dev_private;
  1027. struct drm_i915_master_private *master_priv;
  1028. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1029. struct intel_framebuffer *intel_fb;
  1030. struct drm_i915_gem_object *obj_priv;
  1031. struct drm_gem_object *obj;
  1032. int pipe = intel_crtc->pipe;
  1033. int plane = intel_crtc->plane;
  1034. unsigned long Start, Offset;
  1035. int dspbase = (plane == 0 ? DSPAADDR : DSPBADDR);
  1036. int dspsurf = (plane == 0 ? DSPASURF : DSPBSURF);
  1037. int dspstride = (plane == 0) ? DSPASTRIDE : DSPBSTRIDE;
  1038. int dsptileoff = (plane == 0 ? DSPATILEOFF : DSPBTILEOFF);
  1039. int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR;
  1040. u32 dspcntr, alignment;
  1041. int ret;
  1042. /* no fb bound */
  1043. if (!crtc->fb) {
  1044. DRM_DEBUG("No FB bound\n");
  1045. return 0;
  1046. }
  1047. switch (plane) {
  1048. case 0:
  1049. case 1:
  1050. break;
  1051. default:
  1052. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1053. return -EINVAL;
  1054. }
  1055. intel_fb = to_intel_framebuffer(crtc->fb);
  1056. obj = intel_fb->obj;
  1057. obj_priv = obj->driver_private;
  1058. switch (obj_priv->tiling_mode) {
  1059. case I915_TILING_NONE:
  1060. alignment = 64 * 1024;
  1061. break;
  1062. case I915_TILING_X:
  1063. /* pin() will align the object as required by fence */
  1064. alignment = 0;
  1065. break;
  1066. case I915_TILING_Y:
  1067. /* FIXME: Is this true? */
  1068. DRM_ERROR("Y tiled not allowed for scan out buffers\n");
  1069. return -EINVAL;
  1070. default:
  1071. BUG();
  1072. }
  1073. mutex_lock(&dev->struct_mutex);
  1074. ret = i915_gem_object_pin(obj, alignment);
  1075. if (ret != 0) {
  1076. mutex_unlock(&dev->struct_mutex);
  1077. return ret;
  1078. }
  1079. ret = i915_gem_object_set_to_gtt_domain(obj, 1);
  1080. if (ret != 0) {
  1081. i915_gem_object_unpin(obj);
  1082. mutex_unlock(&dev->struct_mutex);
  1083. return ret;
  1084. }
  1085. /* Pre-i965 needs to install a fence for tiled scan-out */
  1086. if (!IS_I965G(dev) &&
  1087. obj_priv->fence_reg == I915_FENCE_REG_NONE &&
  1088. obj_priv->tiling_mode != I915_TILING_NONE) {
  1089. ret = i915_gem_object_get_fence_reg(obj);
  1090. if (ret != 0) {
  1091. i915_gem_object_unpin(obj);
  1092. mutex_unlock(&dev->struct_mutex);
  1093. return ret;
  1094. }
  1095. }
  1096. dspcntr = I915_READ(dspcntr_reg);
  1097. /* Mask out pixel format bits in case we change it */
  1098. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1099. switch (crtc->fb->bits_per_pixel) {
  1100. case 8:
  1101. dspcntr |= DISPPLANE_8BPP;
  1102. break;
  1103. case 16:
  1104. if (crtc->fb->depth == 15)
  1105. dspcntr |= DISPPLANE_15_16BPP;
  1106. else
  1107. dspcntr |= DISPPLANE_16BPP;
  1108. break;
  1109. case 24:
  1110. case 32:
  1111. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  1112. break;
  1113. default:
  1114. DRM_ERROR("Unknown color depth\n");
  1115. i915_gem_object_unpin(obj);
  1116. mutex_unlock(&dev->struct_mutex);
  1117. return -EINVAL;
  1118. }
  1119. if (IS_I965G(dev)) {
  1120. if (obj_priv->tiling_mode != I915_TILING_NONE)
  1121. dspcntr |= DISPPLANE_TILED;
  1122. else
  1123. dspcntr &= ~DISPPLANE_TILED;
  1124. }
  1125. if (IS_IGDNG(dev))
  1126. /* must disable */
  1127. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  1128. I915_WRITE(dspcntr_reg, dspcntr);
  1129. Start = obj_priv->gtt_offset;
  1130. Offset = y * crtc->fb->pitch + x * (crtc->fb->bits_per_pixel / 8);
  1131. DRM_DEBUG("Writing base %08lX %08lX %d %d\n", Start, Offset, x, y);
  1132. I915_WRITE(dspstride, crtc->fb->pitch);
  1133. if (IS_I965G(dev)) {
  1134. I915_WRITE(dspbase, Offset);
  1135. I915_READ(dspbase);
  1136. I915_WRITE(dspsurf, Start);
  1137. I915_READ(dspsurf);
  1138. I915_WRITE(dsptileoff, (y << 16) | x);
  1139. } else {
  1140. I915_WRITE(dspbase, Start + Offset);
  1141. I915_READ(dspbase);
  1142. }
  1143. intel_wait_for_vblank(dev);
  1144. if (old_fb) {
  1145. intel_fb = to_intel_framebuffer(old_fb);
  1146. obj_priv = intel_fb->obj->driver_private;
  1147. i915_gem_object_unpin(intel_fb->obj);
  1148. }
  1149. intel_increase_pllclock(crtc, true);
  1150. mutex_unlock(&dev->struct_mutex);
  1151. if (!dev->primary->master)
  1152. return 0;
  1153. master_priv = dev->primary->master->driver_priv;
  1154. if (!master_priv->sarea_priv)
  1155. return 0;
  1156. if (pipe) {
  1157. master_priv->sarea_priv->pipeB_x = x;
  1158. master_priv->sarea_priv->pipeB_y = y;
  1159. } else {
  1160. master_priv->sarea_priv->pipeA_x = x;
  1161. master_priv->sarea_priv->pipeA_y = y;
  1162. }
  1163. if (I915_HAS_FBC(dev) && (IS_I965G(dev) || plane == 0))
  1164. intel_update_fbc(crtc, &crtc->mode);
  1165. return 0;
  1166. }
  1167. /* Disable the VGA plane that we never use */
  1168. static void i915_disable_vga (struct drm_device *dev)
  1169. {
  1170. struct drm_i915_private *dev_priv = dev->dev_private;
  1171. u8 sr1;
  1172. u32 vga_reg;
  1173. if (IS_IGDNG(dev))
  1174. vga_reg = CPU_VGACNTRL;
  1175. else
  1176. vga_reg = VGACNTRL;
  1177. if (I915_READ(vga_reg) & VGA_DISP_DISABLE)
  1178. return;
  1179. I915_WRITE8(VGA_SR_INDEX, 1);
  1180. sr1 = I915_READ8(VGA_SR_DATA);
  1181. I915_WRITE8(VGA_SR_DATA, sr1 | (1 << 5));
  1182. udelay(100);
  1183. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  1184. }
  1185. static void igdng_disable_pll_edp (struct drm_crtc *crtc)
  1186. {
  1187. struct drm_device *dev = crtc->dev;
  1188. struct drm_i915_private *dev_priv = dev->dev_private;
  1189. u32 dpa_ctl;
  1190. DRM_DEBUG("\n");
  1191. dpa_ctl = I915_READ(DP_A);
  1192. dpa_ctl &= ~DP_PLL_ENABLE;
  1193. I915_WRITE(DP_A, dpa_ctl);
  1194. }
  1195. static void igdng_enable_pll_edp (struct drm_crtc *crtc)
  1196. {
  1197. struct drm_device *dev = crtc->dev;
  1198. struct drm_i915_private *dev_priv = dev->dev_private;
  1199. u32 dpa_ctl;
  1200. dpa_ctl = I915_READ(DP_A);
  1201. dpa_ctl |= DP_PLL_ENABLE;
  1202. I915_WRITE(DP_A, dpa_ctl);
  1203. udelay(200);
  1204. }
  1205. static void igdng_set_pll_edp (struct drm_crtc *crtc, int clock)
  1206. {
  1207. struct drm_device *dev = crtc->dev;
  1208. struct drm_i915_private *dev_priv = dev->dev_private;
  1209. u32 dpa_ctl;
  1210. DRM_DEBUG("eDP PLL enable for clock %d\n", clock);
  1211. dpa_ctl = I915_READ(DP_A);
  1212. dpa_ctl &= ~DP_PLL_FREQ_MASK;
  1213. if (clock < 200000) {
  1214. u32 temp;
  1215. dpa_ctl |= DP_PLL_FREQ_160MHZ;
  1216. /* workaround for 160Mhz:
  1217. 1) program 0x4600c bits 15:0 = 0x8124
  1218. 2) program 0x46010 bit 0 = 1
  1219. 3) program 0x46034 bit 24 = 1
  1220. 4) program 0x64000 bit 14 = 1
  1221. */
  1222. temp = I915_READ(0x4600c);
  1223. temp &= 0xffff0000;
  1224. I915_WRITE(0x4600c, temp | 0x8124);
  1225. temp = I915_READ(0x46010);
  1226. I915_WRITE(0x46010, temp | 1);
  1227. temp = I915_READ(0x46034);
  1228. I915_WRITE(0x46034, temp | (1 << 24));
  1229. } else {
  1230. dpa_ctl |= DP_PLL_FREQ_270MHZ;
  1231. }
  1232. I915_WRITE(DP_A, dpa_ctl);
  1233. udelay(500);
  1234. }
  1235. static void igdng_crtc_dpms(struct drm_crtc *crtc, int mode)
  1236. {
  1237. struct drm_device *dev = crtc->dev;
  1238. struct drm_i915_private *dev_priv = dev->dev_private;
  1239. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1240. int pipe = intel_crtc->pipe;
  1241. int plane = intel_crtc->plane;
  1242. int pch_dpll_reg = (pipe == 0) ? PCH_DPLL_A : PCH_DPLL_B;
  1243. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  1244. int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR;
  1245. int dspbase_reg = (plane == 0) ? DSPAADDR : DSPBADDR;
  1246. int fdi_tx_reg = (pipe == 0) ? FDI_TXA_CTL : FDI_TXB_CTL;
  1247. int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL;
  1248. int fdi_rx_iir_reg = (pipe == 0) ? FDI_RXA_IIR : FDI_RXB_IIR;
  1249. int fdi_rx_imr_reg = (pipe == 0) ? FDI_RXA_IMR : FDI_RXB_IMR;
  1250. int transconf_reg = (pipe == 0) ? TRANSACONF : TRANSBCONF;
  1251. int pf_ctl_reg = (pipe == 0) ? PFA_CTL_1 : PFB_CTL_1;
  1252. int pf_win_size = (pipe == 0) ? PFA_WIN_SZ : PFB_WIN_SZ;
  1253. int cpu_htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
  1254. int cpu_hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
  1255. int cpu_hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
  1256. int cpu_vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
  1257. int cpu_vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
  1258. int cpu_vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
  1259. int trans_htot_reg = (pipe == 0) ? TRANS_HTOTAL_A : TRANS_HTOTAL_B;
  1260. int trans_hblank_reg = (pipe == 0) ? TRANS_HBLANK_A : TRANS_HBLANK_B;
  1261. int trans_hsync_reg = (pipe == 0) ? TRANS_HSYNC_A : TRANS_HSYNC_B;
  1262. int trans_vtot_reg = (pipe == 0) ? TRANS_VTOTAL_A : TRANS_VTOTAL_B;
  1263. int trans_vblank_reg = (pipe == 0) ? TRANS_VBLANK_A : TRANS_VBLANK_B;
  1264. int trans_vsync_reg = (pipe == 0) ? TRANS_VSYNC_A : TRANS_VSYNC_B;
  1265. u32 temp;
  1266. int tries = 5, j, n;
  1267. /* XXX: When our outputs are all unaware of DPMS modes other than off
  1268. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  1269. */
  1270. switch (mode) {
  1271. case DRM_MODE_DPMS_ON:
  1272. case DRM_MODE_DPMS_STANDBY:
  1273. case DRM_MODE_DPMS_SUSPEND:
  1274. DRM_DEBUG("crtc %d dpms on\n", pipe);
  1275. if (HAS_eDP) {
  1276. /* enable eDP PLL */
  1277. igdng_enable_pll_edp(crtc);
  1278. } else {
  1279. /* enable PCH DPLL */
  1280. temp = I915_READ(pch_dpll_reg);
  1281. if ((temp & DPLL_VCO_ENABLE) == 0) {
  1282. I915_WRITE(pch_dpll_reg, temp | DPLL_VCO_ENABLE);
  1283. I915_READ(pch_dpll_reg);
  1284. }
  1285. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  1286. temp = I915_READ(fdi_rx_reg);
  1287. I915_WRITE(fdi_rx_reg, temp | FDI_RX_PLL_ENABLE |
  1288. FDI_SEL_PCDCLK |
  1289. FDI_DP_PORT_WIDTH_X4); /* default 4 lanes */
  1290. I915_READ(fdi_rx_reg);
  1291. udelay(200);
  1292. /* Enable CPU FDI TX PLL, always on for IGDNG */
  1293. temp = I915_READ(fdi_tx_reg);
  1294. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  1295. I915_WRITE(fdi_tx_reg, temp | FDI_TX_PLL_ENABLE);
  1296. I915_READ(fdi_tx_reg);
  1297. udelay(100);
  1298. }
  1299. }
  1300. /* Enable CPU pipe */
  1301. temp = I915_READ(pipeconf_reg);
  1302. if ((temp & PIPEACONF_ENABLE) == 0) {
  1303. I915_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE);
  1304. I915_READ(pipeconf_reg);
  1305. udelay(100);
  1306. }
  1307. /* configure and enable CPU plane */
  1308. temp = I915_READ(dspcntr_reg);
  1309. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  1310. I915_WRITE(dspcntr_reg, temp | DISPLAY_PLANE_ENABLE);
  1311. /* Flush the plane changes */
  1312. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1313. }
  1314. if (!HAS_eDP) {
  1315. /* enable CPU FDI TX and PCH FDI RX */
  1316. temp = I915_READ(fdi_tx_reg);
  1317. temp |= FDI_TX_ENABLE;
  1318. temp |= FDI_DP_PORT_WIDTH_X4; /* default */
  1319. temp &= ~FDI_LINK_TRAIN_NONE;
  1320. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1321. I915_WRITE(fdi_tx_reg, temp);
  1322. I915_READ(fdi_tx_reg);
  1323. temp = I915_READ(fdi_rx_reg);
  1324. temp &= ~FDI_LINK_TRAIN_NONE;
  1325. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1326. I915_WRITE(fdi_rx_reg, temp | FDI_RX_ENABLE);
  1327. I915_READ(fdi_rx_reg);
  1328. udelay(150);
  1329. /* Train FDI. */
  1330. /* umask FDI RX Interrupt symbol_lock and bit_lock bit
  1331. for train result */
  1332. temp = I915_READ(fdi_rx_imr_reg);
  1333. temp &= ~FDI_RX_SYMBOL_LOCK;
  1334. temp &= ~FDI_RX_BIT_LOCK;
  1335. I915_WRITE(fdi_rx_imr_reg, temp);
  1336. I915_READ(fdi_rx_imr_reg);
  1337. udelay(150);
  1338. temp = I915_READ(fdi_rx_iir_reg);
  1339. DRM_DEBUG("FDI_RX_IIR 0x%x\n", temp);
  1340. if ((temp & FDI_RX_BIT_LOCK) == 0) {
  1341. for (j = 0; j < tries; j++) {
  1342. temp = I915_READ(fdi_rx_iir_reg);
  1343. DRM_DEBUG("FDI_RX_IIR 0x%x\n", temp);
  1344. if (temp & FDI_RX_BIT_LOCK)
  1345. break;
  1346. udelay(200);
  1347. }
  1348. if (j != tries)
  1349. I915_WRITE(fdi_rx_iir_reg,
  1350. temp | FDI_RX_BIT_LOCK);
  1351. else
  1352. DRM_DEBUG("train 1 fail\n");
  1353. } else {
  1354. I915_WRITE(fdi_rx_iir_reg,
  1355. temp | FDI_RX_BIT_LOCK);
  1356. DRM_DEBUG("train 1 ok 2!\n");
  1357. }
  1358. temp = I915_READ(fdi_tx_reg);
  1359. temp &= ~FDI_LINK_TRAIN_NONE;
  1360. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1361. I915_WRITE(fdi_tx_reg, temp);
  1362. temp = I915_READ(fdi_rx_reg);
  1363. temp &= ~FDI_LINK_TRAIN_NONE;
  1364. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1365. I915_WRITE(fdi_rx_reg, temp);
  1366. udelay(150);
  1367. temp = I915_READ(fdi_rx_iir_reg);
  1368. DRM_DEBUG("FDI_RX_IIR 0x%x\n", temp);
  1369. if ((temp & FDI_RX_SYMBOL_LOCK) == 0) {
  1370. for (j = 0; j < tries; j++) {
  1371. temp = I915_READ(fdi_rx_iir_reg);
  1372. DRM_DEBUG("FDI_RX_IIR 0x%x\n", temp);
  1373. if (temp & FDI_RX_SYMBOL_LOCK)
  1374. break;
  1375. udelay(200);
  1376. }
  1377. if (j != tries) {
  1378. I915_WRITE(fdi_rx_iir_reg,
  1379. temp | FDI_RX_SYMBOL_LOCK);
  1380. DRM_DEBUG("train 2 ok 1!\n");
  1381. } else
  1382. DRM_DEBUG("train 2 fail\n");
  1383. } else {
  1384. I915_WRITE(fdi_rx_iir_reg,
  1385. temp | FDI_RX_SYMBOL_LOCK);
  1386. DRM_DEBUG("train 2 ok 2!\n");
  1387. }
  1388. DRM_DEBUG("train done\n");
  1389. /* set transcoder timing */
  1390. I915_WRITE(trans_htot_reg, I915_READ(cpu_htot_reg));
  1391. I915_WRITE(trans_hblank_reg, I915_READ(cpu_hblank_reg));
  1392. I915_WRITE(trans_hsync_reg, I915_READ(cpu_hsync_reg));
  1393. I915_WRITE(trans_vtot_reg, I915_READ(cpu_vtot_reg));
  1394. I915_WRITE(trans_vblank_reg, I915_READ(cpu_vblank_reg));
  1395. I915_WRITE(trans_vsync_reg, I915_READ(cpu_vsync_reg));
  1396. /* enable PCH transcoder */
  1397. temp = I915_READ(transconf_reg);
  1398. I915_WRITE(transconf_reg, temp | TRANS_ENABLE);
  1399. I915_READ(transconf_reg);
  1400. while ((I915_READ(transconf_reg) & TRANS_STATE_ENABLE) == 0)
  1401. ;
  1402. /* enable normal */
  1403. temp = I915_READ(fdi_tx_reg);
  1404. temp &= ~FDI_LINK_TRAIN_NONE;
  1405. I915_WRITE(fdi_tx_reg, temp | FDI_LINK_TRAIN_NONE |
  1406. FDI_TX_ENHANCE_FRAME_ENABLE);
  1407. I915_READ(fdi_tx_reg);
  1408. temp = I915_READ(fdi_rx_reg);
  1409. temp &= ~FDI_LINK_TRAIN_NONE;
  1410. I915_WRITE(fdi_rx_reg, temp | FDI_LINK_TRAIN_NONE |
  1411. FDI_RX_ENHANCE_FRAME_ENABLE);
  1412. I915_READ(fdi_rx_reg);
  1413. /* wait one idle pattern time */
  1414. udelay(100);
  1415. }
  1416. intel_crtc_load_lut(crtc);
  1417. break;
  1418. case DRM_MODE_DPMS_OFF:
  1419. DRM_DEBUG("crtc %d dpms off\n", pipe);
  1420. i915_disable_vga(dev);
  1421. /* Disable display plane */
  1422. temp = I915_READ(dspcntr_reg);
  1423. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  1424. I915_WRITE(dspcntr_reg, temp & ~DISPLAY_PLANE_ENABLE);
  1425. /* Flush the plane changes */
  1426. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1427. I915_READ(dspbase_reg);
  1428. }
  1429. /* disable cpu pipe, disable after all planes disabled */
  1430. temp = I915_READ(pipeconf_reg);
  1431. if ((temp & PIPEACONF_ENABLE) != 0) {
  1432. I915_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE);
  1433. I915_READ(pipeconf_reg);
  1434. n = 0;
  1435. /* wait for cpu pipe off, pipe state */
  1436. while ((I915_READ(pipeconf_reg) & I965_PIPECONF_ACTIVE) != 0) {
  1437. n++;
  1438. if (n < 60) {
  1439. udelay(500);
  1440. continue;
  1441. } else {
  1442. DRM_DEBUG("pipe %d off delay\n", pipe);
  1443. break;
  1444. }
  1445. }
  1446. } else
  1447. DRM_DEBUG("crtc %d is disabled\n", pipe);
  1448. if (HAS_eDP) {
  1449. igdng_disable_pll_edp(crtc);
  1450. }
  1451. /* disable CPU FDI tx and PCH FDI rx */
  1452. temp = I915_READ(fdi_tx_reg);
  1453. I915_WRITE(fdi_tx_reg, temp & ~FDI_TX_ENABLE);
  1454. I915_READ(fdi_tx_reg);
  1455. temp = I915_READ(fdi_rx_reg);
  1456. I915_WRITE(fdi_rx_reg, temp & ~FDI_RX_ENABLE);
  1457. I915_READ(fdi_rx_reg);
  1458. udelay(100);
  1459. /* still set train pattern 1 */
  1460. temp = I915_READ(fdi_tx_reg);
  1461. temp &= ~FDI_LINK_TRAIN_NONE;
  1462. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1463. I915_WRITE(fdi_tx_reg, temp);
  1464. temp = I915_READ(fdi_rx_reg);
  1465. temp &= ~FDI_LINK_TRAIN_NONE;
  1466. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1467. I915_WRITE(fdi_rx_reg, temp);
  1468. udelay(100);
  1469. /* disable PCH transcoder */
  1470. temp = I915_READ(transconf_reg);
  1471. if ((temp & TRANS_ENABLE) != 0) {
  1472. I915_WRITE(transconf_reg, temp & ~TRANS_ENABLE);
  1473. I915_READ(transconf_reg);
  1474. n = 0;
  1475. /* wait for PCH transcoder off, transcoder state */
  1476. while ((I915_READ(transconf_reg) & TRANS_STATE_ENABLE) != 0) {
  1477. n++;
  1478. if (n < 60) {
  1479. udelay(500);
  1480. continue;
  1481. } else {
  1482. DRM_DEBUG("transcoder %d off delay\n", pipe);
  1483. break;
  1484. }
  1485. }
  1486. }
  1487. /* disable PCH DPLL */
  1488. temp = I915_READ(pch_dpll_reg);
  1489. if ((temp & DPLL_VCO_ENABLE) != 0) {
  1490. I915_WRITE(pch_dpll_reg, temp & ~DPLL_VCO_ENABLE);
  1491. I915_READ(pch_dpll_reg);
  1492. }
  1493. temp = I915_READ(fdi_rx_reg);
  1494. if ((temp & FDI_RX_PLL_ENABLE) != 0) {
  1495. temp &= ~FDI_SEL_PCDCLK;
  1496. temp &= ~FDI_RX_PLL_ENABLE;
  1497. I915_WRITE(fdi_rx_reg, temp);
  1498. I915_READ(fdi_rx_reg);
  1499. }
  1500. /* Disable CPU FDI TX PLL */
  1501. temp = I915_READ(fdi_tx_reg);
  1502. if ((temp & FDI_TX_PLL_ENABLE) != 0) {
  1503. I915_WRITE(fdi_tx_reg, temp & ~FDI_TX_PLL_ENABLE);
  1504. I915_READ(fdi_tx_reg);
  1505. udelay(100);
  1506. }
  1507. /* Disable PF */
  1508. temp = I915_READ(pf_ctl_reg);
  1509. if ((temp & PF_ENABLE) != 0) {
  1510. I915_WRITE(pf_ctl_reg, temp & ~PF_ENABLE);
  1511. I915_READ(pf_ctl_reg);
  1512. }
  1513. I915_WRITE(pf_win_size, 0);
  1514. /* Wait for the clocks to turn off. */
  1515. udelay(150);
  1516. break;
  1517. }
  1518. }
  1519. static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode)
  1520. {
  1521. struct drm_device *dev = crtc->dev;
  1522. struct drm_i915_private *dev_priv = dev->dev_private;
  1523. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1524. int pipe = intel_crtc->pipe;
  1525. int plane = intel_crtc->plane;
  1526. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  1527. int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR;
  1528. int dspbase_reg = (plane == 0) ? DSPAADDR : DSPBADDR;
  1529. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  1530. u32 temp;
  1531. /* XXX: When our outputs are all unaware of DPMS modes other than off
  1532. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  1533. */
  1534. switch (mode) {
  1535. case DRM_MODE_DPMS_ON:
  1536. case DRM_MODE_DPMS_STANDBY:
  1537. case DRM_MODE_DPMS_SUSPEND:
  1538. /* Enable the DPLL */
  1539. temp = I915_READ(dpll_reg);
  1540. if ((temp & DPLL_VCO_ENABLE) == 0) {
  1541. I915_WRITE(dpll_reg, temp);
  1542. I915_READ(dpll_reg);
  1543. /* Wait for the clocks to stabilize. */
  1544. udelay(150);
  1545. I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  1546. I915_READ(dpll_reg);
  1547. /* Wait for the clocks to stabilize. */
  1548. udelay(150);
  1549. I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  1550. I915_READ(dpll_reg);
  1551. /* Wait for the clocks to stabilize. */
  1552. udelay(150);
  1553. }
  1554. /* Enable the pipe */
  1555. temp = I915_READ(pipeconf_reg);
  1556. if ((temp & PIPEACONF_ENABLE) == 0)
  1557. I915_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE);
  1558. /* Enable the plane */
  1559. temp = I915_READ(dspcntr_reg);
  1560. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  1561. I915_WRITE(dspcntr_reg, temp | DISPLAY_PLANE_ENABLE);
  1562. /* Flush the plane changes */
  1563. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1564. }
  1565. intel_crtc_load_lut(crtc);
  1566. if (I915_HAS_FBC(dev) && (IS_I965G(dev) || plane == 0))
  1567. intel_update_fbc(crtc, &crtc->mode);
  1568. /* Give the overlay scaler a chance to enable if it's on this pipe */
  1569. //intel_crtc_dpms_video(crtc, true); TODO
  1570. intel_update_watermarks(dev);
  1571. break;
  1572. case DRM_MODE_DPMS_OFF:
  1573. intel_update_watermarks(dev);
  1574. /* Give the overlay scaler a chance to disable if it's on this pipe */
  1575. //intel_crtc_dpms_video(crtc, FALSE); TODO
  1576. if (dev_priv->cfb_plane == plane)
  1577. i8xx_disable_fbc(dev);
  1578. /* Disable the VGA plane that we never use */
  1579. i915_disable_vga(dev);
  1580. /* Disable display plane */
  1581. temp = I915_READ(dspcntr_reg);
  1582. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  1583. I915_WRITE(dspcntr_reg, temp & ~DISPLAY_PLANE_ENABLE);
  1584. /* Flush the plane changes */
  1585. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1586. I915_READ(dspbase_reg);
  1587. }
  1588. if (!IS_I9XX(dev)) {
  1589. /* Wait for vblank for the disable to take effect */
  1590. intel_wait_for_vblank(dev);
  1591. }
  1592. /* Next, disable display pipes */
  1593. temp = I915_READ(pipeconf_reg);
  1594. if ((temp & PIPEACONF_ENABLE) != 0) {
  1595. I915_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE);
  1596. I915_READ(pipeconf_reg);
  1597. }
  1598. /* Wait for vblank for the disable to take effect. */
  1599. intel_wait_for_vblank(dev);
  1600. temp = I915_READ(dpll_reg);
  1601. if ((temp & DPLL_VCO_ENABLE) != 0) {
  1602. I915_WRITE(dpll_reg, temp & ~DPLL_VCO_ENABLE);
  1603. I915_READ(dpll_reg);
  1604. }
  1605. /* Wait for the clocks to turn off. */
  1606. udelay(150);
  1607. break;
  1608. }
  1609. }
  1610. /**
  1611. * Sets the power management mode of the pipe and plane.
  1612. *
  1613. * This code should probably grow support for turning the cursor off and back
  1614. * on appropriately at the same time as we're turning the pipe off/on.
  1615. */
  1616. static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
  1617. {
  1618. struct drm_device *dev = crtc->dev;
  1619. struct drm_i915_master_private *master_priv;
  1620. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1621. int pipe = intel_crtc->pipe;
  1622. bool enabled;
  1623. if (IS_IGDNG(dev))
  1624. igdng_crtc_dpms(crtc, mode);
  1625. else
  1626. i9xx_crtc_dpms(crtc, mode);
  1627. intel_crtc->dpms_mode = mode;
  1628. if (!dev->primary->master)
  1629. return;
  1630. master_priv = dev->primary->master->driver_priv;
  1631. if (!master_priv->sarea_priv)
  1632. return;
  1633. enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
  1634. switch (pipe) {
  1635. case 0:
  1636. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  1637. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  1638. break;
  1639. case 1:
  1640. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  1641. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  1642. break;
  1643. default:
  1644. DRM_ERROR("Can't update pipe %d in SAREA\n", pipe);
  1645. break;
  1646. }
  1647. }
  1648. static void intel_crtc_prepare (struct drm_crtc *crtc)
  1649. {
  1650. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  1651. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  1652. }
  1653. static void intel_crtc_commit (struct drm_crtc *crtc)
  1654. {
  1655. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  1656. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  1657. }
  1658. void intel_encoder_prepare (struct drm_encoder *encoder)
  1659. {
  1660. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  1661. /* lvds has its own version of prepare see intel_lvds_prepare */
  1662. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
  1663. }
  1664. void intel_encoder_commit (struct drm_encoder *encoder)
  1665. {
  1666. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  1667. /* lvds has its own version of commit see intel_lvds_commit */
  1668. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  1669. }
  1670. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  1671. struct drm_display_mode *mode,
  1672. struct drm_display_mode *adjusted_mode)
  1673. {
  1674. struct drm_device *dev = crtc->dev;
  1675. if (IS_IGDNG(dev)) {
  1676. /* FDI link clock is fixed at 2.7G */
  1677. if (mode->clock * 3 > 27000 * 4)
  1678. return MODE_CLOCK_HIGH;
  1679. }
  1680. return true;
  1681. }
  1682. /** Returns the core display clock speed for i830 - i945 */
  1683. static int intel_get_core_clock_speed(struct drm_device *dev)
  1684. {
  1685. /* Core clock values taken from the published datasheets.
  1686. * The 830 may go up to 166 Mhz, which we should check.
  1687. */
  1688. if (IS_I945G(dev))
  1689. return 400000;
  1690. else if (IS_I915G(dev))
  1691. return 333000;
  1692. else if (IS_I945GM(dev) || IS_845G(dev) || IS_IGDGM(dev))
  1693. return 200000;
  1694. else if (IS_I915GM(dev)) {
  1695. u16 gcfgc = 0;
  1696. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  1697. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  1698. return 133000;
  1699. else {
  1700. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  1701. case GC_DISPLAY_CLOCK_333_MHZ:
  1702. return 333000;
  1703. default:
  1704. case GC_DISPLAY_CLOCK_190_200_MHZ:
  1705. return 190000;
  1706. }
  1707. }
  1708. } else if (IS_I865G(dev))
  1709. return 266000;
  1710. else if (IS_I855(dev)) {
  1711. u16 hpllcc = 0;
  1712. /* Assume that the hardware is in the high speed state. This
  1713. * should be the default.
  1714. */
  1715. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  1716. case GC_CLOCK_133_200:
  1717. case GC_CLOCK_100_200:
  1718. return 200000;
  1719. case GC_CLOCK_166_250:
  1720. return 250000;
  1721. case GC_CLOCK_100_133:
  1722. return 133000;
  1723. }
  1724. } else /* 852, 830 */
  1725. return 133000;
  1726. return 0; /* Silence gcc warning */
  1727. }
  1728. /**
  1729. * Return the pipe currently connected to the panel fitter,
  1730. * or -1 if the panel fitter is not present or not in use
  1731. */
  1732. static int intel_panel_fitter_pipe (struct drm_device *dev)
  1733. {
  1734. struct drm_i915_private *dev_priv = dev->dev_private;
  1735. u32 pfit_control;
  1736. /* i830 doesn't have a panel fitter */
  1737. if (IS_I830(dev))
  1738. return -1;
  1739. pfit_control = I915_READ(PFIT_CONTROL);
  1740. /* See if the panel fitter is in use */
  1741. if ((pfit_control & PFIT_ENABLE) == 0)
  1742. return -1;
  1743. /* 965 can place panel fitter on either pipe */
  1744. if (IS_I965G(dev))
  1745. return (pfit_control >> 29) & 0x3;
  1746. /* older chips can only use pipe 1 */
  1747. return 1;
  1748. }
  1749. struct fdi_m_n {
  1750. u32 tu;
  1751. u32 gmch_m;
  1752. u32 gmch_n;
  1753. u32 link_m;
  1754. u32 link_n;
  1755. };
  1756. static void
  1757. fdi_reduce_ratio(u32 *num, u32 *den)
  1758. {
  1759. while (*num > 0xffffff || *den > 0xffffff) {
  1760. *num >>= 1;
  1761. *den >>= 1;
  1762. }
  1763. }
  1764. #define DATA_N 0x800000
  1765. #define LINK_N 0x80000
  1766. static void
  1767. igdng_compute_m_n(int bytes_per_pixel, int nlanes,
  1768. int pixel_clock, int link_clock,
  1769. struct fdi_m_n *m_n)
  1770. {
  1771. u64 temp;
  1772. m_n->tu = 64; /* default size */
  1773. temp = (u64) DATA_N * pixel_clock;
  1774. temp = div_u64(temp, link_clock);
  1775. m_n->gmch_m = div_u64(temp * bytes_per_pixel, nlanes);
  1776. m_n->gmch_n = DATA_N;
  1777. fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  1778. temp = (u64) LINK_N * pixel_clock;
  1779. m_n->link_m = div_u64(temp, link_clock);
  1780. m_n->link_n = LINK_N;
  1781. fdi_reduce_ratio(&m_n->link_m, &m_n->link_n);
  1782. }
  1783. struct intel_watermark_params {
  1784. unsigned long fifo_size;
  1785. unsigned long max_wm;
  1786. unsigned long default_wm;
  1787. unsigned long guard_size;
  1788. unsigned long cacheline_size;
  1789. };
  1790. /* IGD has different values for various configs */
  1791. static struct intel_watermark_params igd_display_wm = {
  1792. IGD_DISPLAY_FIFO,
  1793. IGD_MAX_WM,
  1794. IGD_DFT_WM,
  1795. IGD_GUARD_WM,
  1796. IGD_FIFO_LINE_SIZE
  1797. };
  1798. static struct intel_watermark_params igd_display_hplloff_wm = {
  1799. IGD_DISPLAY_FIFO,
  1800. IGD_MAX_WM,
  1801. IGD_DFT_HPLLOFF_WM,
  1802. IGD_GUARD_WM,
  1803. IGD_FIFO_LINE_SIZE
  1804. };
  1805. static struct intel_watermark_params igd_cursor_wm = {
  1806. IGD_CURSOR_FIFO,
  1807. IGD_CURSOR_MAX_WM,
  1808. IGD_CURSOR_DFT_WM,
  1809. IGD_CURSOR_GUARD_WM,
  1810. IGD_FIFO_LINE_SIZE,
  1811. };
  1812. static struct intel_watermark_params igd_cursor_hplloff_wm = {
  1813. IGD_CURSOR_FIFO,
  1814. IGD_CURSOR_MAX_WM,
  1815. IGD_CURSOR_DFT_WM,
  1816. IGD_CURSOR_GUARD_WM,
  1817. IGD_FIFO_LINE_SIZE
  1818. };
  1819. static struct intel_watermark_params i945_wm_info = {
  1820. I945_FIFO_SIZE,
  1821. I915_MAX_WM,
  1822. 1,
  1823. 2,
  1824. I915_FIFO_LINE_SIZE
  1825. };
  1826. static struct intel_watermark_params i915_wm_info = {
  1827. I915_FIFO_SIZE,
  1828. I915_MAX_WM,
  1829. 1,
  1830. 2,
  1831. I915_FIFO_LINE_SIZE
  1832. };
  1833. static struct intel_watermark_params i855_wm_info = {
  1834. I855GM_FIFO_SIZE,
  1835. I915_MAX_WM,
  1836. 1,
  1837. 2,
  1838. I830_FIFO_LINE_SIZE
  1839. };
  1840. static struct intel_watermark_params i830_wm_info = {
  1841. I830_FIFO_SIZE,
  1842. I915_MAX_WM,
  1843. 1,
  1844. 2,
  1845. I830_FIFO_LINE_SIZE
  1846. };
  1847. /**
  1848. * intel_calculate_wm - calculate watermark level
  1849. * @clock_in_khz: pixel clock
  1850. * @wm: chip FIFO params
  1851. * @pixel_size: display pixel size
  1852. * @latency_ns: memory latency for the platform
  1853. *
  1854. * Calculate the watermark level (the level at which the display plane will
  1855. * start fetching from memory again). Each chip has a different display
  1856. * FIFO size and allocation, so the caller needs to figure that out and pass
  1857. * in the correct intel_watermark_params structure.
  1858. *
  1859. * As the pixel clock runs, the FIFO will be drained at a rate that depends
  1860. * on the pixel size. When it reaches the watermark level, it'll start
  1861. * fetching FIFO line sized based chunks from memory until the FIFO fills
  1862. * past the watermark point. If the FIFO drains completely, a FIFO underrun
  1863. * will occur, and a display engine hang could result.
  1864. */
  1865. static unsigned long intel_calculate_wm(unsigned long clock_in_khz,
  1866. struct intel_watermark_params *wm,
  1867. int pixel_size,
  1868. unsigned long latency_ns)
  1869. {
  1870. long entries_required, wm_size;
  1871. entries_required = (clock_in_khz * pixel_size * latency_ns) / 1000000;
  1872. entries_required /= wm->cacheline_size;
  1873. DRM_DEBUG("FIFO entries required for mode: %d\n", entries_required);
  1874. wm_size = wm->fifo_size - (entries_required + wm->guard_size);
  1875. DRM_DEBUG("FIFO watermark level: %d\n", wm_size);
  1876. /* Don't promote wm_size to unsigned... */
  1877. if (wm_size > (long)wm->max_wm)
  1878. wm_size = wm->max_wm;
  1879. if (wm_size <= 0)
  1880. wm_size = wm->default_wm;
  1881. return wm_size;
  1882. }
  1883. struct cxsr_latency {
  1884. int is_desktop;
  1885. unsigned long fsb_freq;
  1886. unsigned long mem_freq;
  1887. unsigned long display_sr;
  1888. unsigned long display_hpll_disable;
  1889. unsigned long cursor_sr;
  1890. unsigned long cursor_hpll_disable;
  1891. };
  1892. static struct cxsr_latency cxsr_latency_table[] = {
  1893. {1, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
  1894. {1, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
  1895. {1, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
  1896. {1, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
  1897. {1, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
  1898. {1, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
  1899. {1, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
  1900. {1, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
  1901. {1, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
  1902. {0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
  1903. {0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
  1904. {0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
  1905. {0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
  1906. {0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
  1907. {0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
  1908. {0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
  1909. {0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
  1910. {0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
  1911. };
  1912. static struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, int fsb,
  1913. int mem)
  1914. {
  1915. int i;
  1916. struct cxsr_latency *latency;
  1917. if (fsb == 0 || mem == 0)
  1918. return NULL;
  1919. for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
  1920. latency = &cxsr_latency_table[i];
  1921. if (is_desktop == latency->is_desktop &&
  1922. fsb == latency->fsb_freq && mem == latency->mem_freq)
  1923. break;
  1924. }
  1925. if (i >= ARRAY_SIZE(cxsr_latency_table)) {
  1926. DRM_DEBUG("Unknown FSB/MEM found, disable CxSR\n");
  1927. return NULL;
  1928. }
  1929. return latency;
  1930. }
  1931. static void igd_disable_cxsr(struct drm_device *dev)
  1932. {
  1933. struct drm_i915_private *dev_priv = dev->dev_private;
  1934. u32 reg;
  1935. /* deactivate cxsr */
  1936. reg = I915_READ(DSPFW3);
  1937. reg &= ~(IGD_SELF_REFRESH_EN);
  1938. I915_WRITE(DSPFW3, reg);
  1939. DRM_INFO("Big FIFO is disabled\n");
  1940. }
  1941. static void igd_enable_cxsr(struct drm_device *dev, unsigned long clock,
  1942. int pixel_size)
  1943. {
  1944. struct drm_i915_private *dev_priv = dev->dev_private;
  1945. u32 reg;
  1946. unsigned long wm;
  1947. struct cxsr_latency *latency;
  1948. latency = intel_get_cxsr_latency(IS_IGDG(dev), dev_priv->fsb_freq,
  1949. dev_priv->mem_freq);
  1950. if (!latency) {
  1951. DRM_DEBUG("Unknown FSB/MEM found, disable CxSR\n");
  1952. igd_disable_cxsr(dev);
  1953. return;
  1954. }
  1955. /* Display SR */
  1956. wm = intel_calculate_wm(clock, &igd_display_wm, pixel_size,
  1957. latency->display_sr);
  1958. reg = I915_READ(DSPFW1);
  1959. reg &= 0x7fffff;
  1960. reg |= wm << 23;
  1961. I915_WRITE(DSPFW1, reg);
  1962. DRM_DEBUG("DSPFW1 register is %x\n", reg);
  1963. /* cursor SR */
  1964. wm = intel_calculate_wm(clock, &igd_cursor_wm, pixel_size,
  1965. latency->cursor_sr);
  1966. reg = I915_READ(DSPFW3);
  1967. reg &= ~(0x3f << 24);
  1968. reg |= (wm & 0x3f) << 24;
  1969. I915_WRITE(DSPFW3, reg);
  1970. /* Display HPLL off SR */
  1971. wm = intel_calculate_wm(clock, &igd_display_hplloff_wm,
  1972. latency->display_hpll_disable, I915_FIFO_LINE_SIZE);
  1973. reg = I915_READ(DSPFW3);
  1974. reg &= 0xfffffe00;
  1975. reg |= wm & 0x1ff;
  1976. I915_WRITE(DSPFW3, reg);
  1977. /* cursor HPLL off SR */
  1978. wm = intel_calculate_wm(clock, &igd_cursor_hplloff_wm, pixel_size,
  1979. latency->cursor_hpll_disable);
  1980. reg = I915_READ(DSPFW3);
  1981. reg &= ~(0x3f << 16);
  1982. reg |= (wm & 0x3f) << 16;
  1983. I915_WRITE(DSPFW3, reg);
  1984. DRM_DEBUG("DSPFW3 register is %x\n", reg);
  1985. /* activate cxsr */
  1986. reg = I915_READ(DSPFW3);
  1987. reg |= IGD_SELF_REFRESH_EN;
  1988. I915_WRITE(DSPFW3, reg);
  1989. DRM_INFO("Big FIFO is enabled\n");
  1990. return;
  1991. }
  1992. /*
  1993. * Latency for FIFO fetches is dependent on several factors:
  1994. * - memory configuration (speed, channels)
  1995. * - chipset
  1996. * - current MCH state
  1997. * It can be fairly high in some situations, so here we assume a fairly
  1998. * pessimal value. It's a tradeoff between extra memory fetches (if we
  1999. * set this value too high, the FIFO will fetch frequently to stay full)
  2000. * and power consumption (set it too low to save power and we might see
  2001. * FIFO underruns and display "flicker").
  2002. *
  2003. * A value of 5us seems to be a good balance; safe for very low end
  2004. * platforms but not overly aggressive on lower latency configs.
  2005. */
  2006. const static int latency_ns = 5000;
  2007. static int intel_get_fifo_size(struct drm_device *dev, int plane)
  2008. {
  2009. struct drm_i915_private *dev_priv = dev->dev_private;
  2010. uint32_t dsparb = I915_READ(DSPARB);
  2011. int size;
  2012. if (IS_I9XX(dev)) {
  2013. if (plane == 0)
  2014. size = dsparb & 0x7f;
  2015. else
  2016. size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) -
  2017. (dsparb & 0x7f);
  2018. } else if (IS_I85X(dev)) {
  2019. if (plane == 0)
  2020. size = dsparb & 0x1ff;
  2021. else
  2022. size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) -
  2023. (dsparb & 0x1ff);
  2024. size >>= 1; /* Convert to cachelines */
  2025. } else if (IS_845G(dev)) {
  2026. size = dsparb & 0x7f;
  2027. size >>= 2; /* Convert to cachelines */
  2028. } else {
  2029. size = dsparb & 0x7f;
  2030. size >>= 1; /* Convert to cachelines */
  2031. }
  2032. DRM_DEBUG("FIFO size - (0x%08x) %s: %d\n", dsparb, plane ? "B" : "A",
  2033. size);
  2034. return size;
  2035. }
  2036. static void g4x_update_wm(struct drm_device *dev)
  2037. {
  2038. struct drm_i915_private *dev_priv = dev->dev_private;
  2039. u32 fw_blc_self = I915_READ(FW_BLC_SELF);
  2040. if (i915_powersave)
  2041. fw_blc_self |= FW_BLC_SELF_EN;
  2042. else
  2043. fw_blc_self &= ~FW_BLC_SELF_EN;
  2044. I915_WRITE(FW_BLC_SELF, fw_blc_self);
  2045. }
  2046. static void i965_update_wm(struct drm_device *dev)
  2047. {
  2048. struct drm_i915_private *dev_priv = dev->dev_private;
  2049. DRM_DEBUG("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR 8\n");
  2050. /* 965 has limitations... */
  2051. I915_WRITE(DSPFW1, (8 << 16) | (8 << 8) | (8 << 0));
  2052. I915_WRITE(DSPFW2, (8 << 8) | (8 << 0));
  2053. }
  2054. static void i9xx_update_wm(struct drm_device *dev, int planea_clock,
  2055. int planeb_clock, int sr_hdisplay, int pixel_size)
  2056. {
  2057. struct drm_i915_private *dev_priv = dev->dev_private;
  2058. uint32_t fwater_lo;
  2059. uint32_t fwater_hi;
  2060. int total_size, cacheline_size, cwm, srwm = 1;
  2061. int planea_wm, planeb_wm;
  2062. struct intel_watermark_params planea_params, planeb_params;
  2063. unsigned long line_time_us;
  2064. int sr_clock, sr_entries = 0;
  2065. /* Create copies of the base settings for each pipe */
  2066. if (IS_I965GM(dev) || IS_I945GM(dev))
  2067. planea_params = planeb_params = i945_wm_info;
  2068. else if (IS_I9XX(dev))
  2069. planea_params = planeb_params = i915_wm_info;
  2070. else
  2071. planea_params = planeb_params = i855_wm_info;
  2072. /* Grab a couple of global values before we overwrite them */
  2073. total_size = planea_params.fifo_size;
  2074. cacheline_size = planea_params.cacheline_size;
  2075. /* Update per-plane FIFO sizes */
  2076. planea_params.fifo_size = intel_get_fifo_size(dev, 0);
  2077. planeb_params.fifo_size = intel_get_fifo_size(dev, 1);
  2078. planea_wm = intel_calculate_wm(planea_clock, &planea_params,
  2079. pixel_size, latency_ns);
  2080. planeb_wm = intel_calculate_wm(planeb_clock, &planeb_params,
  2081. pixel_size, latency_ns);
  2082. DRM_DEBUG("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
  2083. /*
  2084. * Overlay gets an aggressive default since video jitter is bad.
  2085. */
  2086. cwm = 2;
  2087. /* Calc sr entries for one plane configs */
  2088. if (HAS_FW_BLC(dev) && sr_hdisplay &&
  2089. (!planea_clock || !planeb_clock)) {
  2090. /* self-refresh has much higher latency */
  2091. const static int sr_latency_ns = 6000;
  2092. sr_clock = planea_clock ? planea_clock : planeb_clock;
  2093. line_time_us = ((sr_hdisplay * 1000) / sr_clock);
  2094. /* Use ns/us then divide to preserve precision */
  2095. sr_entries = (((sr_latency_ns / line_time_us) + 1) *
  2096. pixel_size * sr_hdisplay) / 1000;
  2097. sr_entries = roundup(sr_entries / cacheline_size, 1);
  2098. DRM_DEBUG("self-refresh entries: %d\n", sr_entries);
  2099. srwm = total_size - sr_entries;
  2100. if (srwm < 0)
  2101. srwm = 1;
  2102. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN | (srwm & 0x3f));
  2103. }
  2104. DRM_DEBUG("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
  2105. planea_wm, planeb_wm, cwm, srwm);
  2106. fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
  2107. fwater_hi = (cwm & 0x1f);
  2108. /* Set request length to 8 cachelines per fetch */
  2109. fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
  2110. fwater_hi = fwater_hi | (1 << 8);
  2111. I915_WRITE(FW_BLC, fwater_lo);
  2112. I915_WRITE(FW_BLC2, fwater_hi);
  2113. }
  2114. static void i830_update_wm(struct drm_device *dev, int planea_clock,
  2115. int pixel_size)
  2116. {
  2117. struct drm_i915_private *dev_priv = dev->dev_private;
  2118. uint32_t fwater_lo = I915_READ(FW_BLC) & ~0xfff;
  2119. int planea_wm;
  2120. i830_wm_info.fifo_size = intel_get_fifo_size(dev, 0);
  2121. planea_wm = intel_calculate_wm(planea_clock, &i830_wm_info,
  2122. pixel_size, latency_ns);
  2123. fwater_lo |= (3<<8) | planea_wm;
  2124. DRM_DEBUG("Setting FIFO watermarks - A: %d\n", planea_wm);
  2125. I915_WRITE(FW_BLC, fwater_lo);
  2126. }
  2127. /**
  2128. * intel_update_watermarks - update FIFO watermark values based on current modes
  2129. *
  2130. * Calculate watermark values for the various WM regs based on current mode
  2131. * and plane configuration.
  2132. *
  2133. * There are several cases to deal with here:
  2134. * - normal (i.e. non-self-refresh)
  2135. * - self-refresh (SR) mode
  2136. * - lines are large relative to FIFO size (buffer can hold up to 2)
  2137. * - lines are small relative to FIFO size (buffer can hold more than 2
  2138. * lines), so need to account for TLB latency
  2139. *
  2140. * The normal calculation is:
  2141. * watermark = dotclock * bytes per pixel * latency
  2142. * where latency is platform & configuration dependent (we assume pessimal
  2143. * values here).
  2144. *
  2145. * The SR calculation is:
  2146. * watermark = (trunc(latency/line time)+1) * surface width *
  2147. * bytes per pixel
  2148. * where
  2149. * line time = htotal / dotclock
  2150. * and latency is assumed to be high, as above.
  2151. *
  2152. * The final value programmed to the register should always be rounded up,
  2153. * and include an extra 2 entries to account for clock crossings.
  2154. *
  2155. * We don't use the sprite, so we can ignore that. And on Crestline we have
  2156. * to set the non-SR watermarks to 8.
  2157. */
  2158. static void intel_update_watermarks(struct drm_device *dev)
  2159. {
  2160. struct drm_crtc *crtc;
  2161. struct intel_crtc *intel_crtc;
  2162. int sr_hdisplay = 0;
  2163. unsigned long planea_clock = 0, planeb_clock = 0, sr_clock = 0;
  2164. int enabled = 0, pixel_size = 0;
  2165. /* Get the clock config from both planes */
  2166. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  2167. intel_crtc = to_intel_crtc(crtc);
  2168. if (crtc->enabled) {
  2169. enabled++;
  2170. if (intel_crtc->plane == 0) {
  2171. DRM_DEBUG("plane A (pipe %d) clock: %d\n",
  2172. intel_crtc->pipe, crtc->mode.clock);
  2173. planea_clock = crtc->mode.clock;
  2174. } else {
  2175. DRM_DEBUG("plane B (pipe %d) clock: %d\n",
  2176. intel_crtc->pipe, crtc->mode.clock);
  2177. planeb_clock = crtc->mode.clock;
  2178. }
  2179. sr_hdisplay = crtc->mode.hdisplay;
  2180. sr_clock = crtc->mode.clock;
  2181. if (crtc->fb)
  2182. pixel_size = crtc->fb->bits_per_pixel / 8;
  2183. else
  2184. pixel_size = 4; /* by default */
  2185. }
  2186. }
  2187. if (enabled <= 0)
  2188. return;
  2189. /* Single plane configs can enable self refresh */
  2190. if (enabled == 1 && IS_IGD(dev))
  2191. igd_enable_cxsr(dev, sr_clock, pixel_size);
  2192. else if (IS_IGD(dev))
  2193. igd_disable_cxsr(dev);
  2194. if (IS_G4X(dev))
  2195. g4x_update_wm(dev);
  2196. else if (IS_I965G(dev))
  2197. i965_update_wm(dev);
  2198. else if (IS_I9XX(dev) || IS_MOBILE(dev))
  2199. i9xx_update_wm(dev, planea_clock, planeb_clock, sr_hdisplay,
  2200. pixel_size);
  2201. else
  2202. i830_update_wm(dev, planea_clock, pixel_size);
  2203. }
  2204. static int intel_crtc_mode_set(struct drm_crtc *crtc,
  2205. struct drm_display_mode *mode,
  2206. struct drm_display_mode *adjusted_mode,
  2207. int x, int y,
  2208. struct drm_framebuffer *old_fb)
  2209. {
  2210. struct drm_device *dev = crtc->dev;
  2211. struct drm_i915_private *dev_priv = dev->dev_private;
  2212. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2213. int pipe = intel_crtc->pipe;
  2214. int plane = intel_crtc->plane;
  2215. int fp_reg = (pipe == 0) ? FPA0 : FPB0;
  2216. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  2217. int dpll_md_reg = (intel_crtc->pipe == 0) ? DPLL_A_MD : DPLL_B_MD;
  2218. int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR;
  2219. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  2220. int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
  2221. int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
  2222. int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
  2223. int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
  2224. int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
  2225. int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
  2226. int dspsize_reg = (plane == 0) ? DSPASIZE : DSPBSIZE;
  2227. int dsppos_reg = (plane == 0) ? DSPAPOS : DSPBPOS;
  2228. int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC;
  2229. int refclk, num_outputs = 0;
  2230. intel_clock_t clock, reduced_clock;
  2231. u32 dpll = 0, fp = 0, fp2 = 0, dspcntr, pipeconf;
  2232. bool ok, has_reduced_clock = false, is_sdvo = false, is_dvo = false;
  2233. bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false;
  2234. bool is_edp = false;
  2235. struct drm_mode_config *mode_config = &dev->mode_config;
  2236. struct drm_connector *connector;
  2237. const intel_limit_t *limit;
  2238. int ret;
  2239. struct fdi_m_n m_n = {0};
  2240. int data_m1_reg = (pipe == 0) ? PIPEA_DATA_M1 : PIPEB_DATA_M1;
  2241. int data_n1_reg = (pipe == 0) ? PIPEA_DATA_N1 : PIPEB_DATA_N1;
  2242. int link_m1_reg = (pipe == 0) ? PIPEA_LINK_M1 : PIPEB_LINK_M1;
  2243. int link_n1_reg = (pipe == 0) ? PIPEA_LINK_N1 : PIPEB_LINK_N1;
  2244. int pch_fp_reg = (pipe == 0) ? PCH_FPA0 : PCH_FPB0;
  2245. int pch_dpll_reg = (pipe == 0) ? PCH_DPLL_A : PCH_DPLL_B;
  2246. int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL;
  2247. int lvds_reg = LVDS;
  2248. u32 temp;
  2249. int sdvo_pixel_multiply;
  2250. int target_clock;
  2251. drm_vblank_pre_modeset(dev, pipe);
  2252. list_for_each_entry(connector, &mode_config->connector_list, head) {
  2253. struct intel_output *intel_output = to_intel_output(connector);
  2254. if (!connector->encoder || connector->encoder->crtc != crtc)
  2255. continue;
  2256. switch (intel_output->type) {
  2257. case INTEL_OUTPUT_LVDS:
  2258. is_lvds = true;
  2259. break;
  2260. case INTEL_OUTPUT_SDVO:
  2261. case INTEL_OUTPUT_HDMI:
  2262. is_sdvo = true;
  2263. if (intel_output->needs_tv_clock)
  2264. is_tv = true;
  2265. break;
  2266. case INTEL_OUTPUT_DVO:
  2267. is_dvo = true;
  2268. break;
  2269. case INTEL_OUTPUT_TVOUT:
  2270. is_tv = true;
  2271. break;
  2272. case INTEL_OUTPUT_ANALOG:
  2273. is_crt = true;
  2274. break;
  2275. case INTEL_OUTPUT_DISPLAYPORT:
  2276. is_dp = true;
  2277. break;
  2278. case INTEL_OUTPUT_EDP:
  2279. is_edp = true;
  2280. break;
  2281. }
  2282. num_outputs++;
  2283. }
  2284. if (is_lvds && dev_priv->lvds_use_ssc && num_outputs < 2) {
  2285. refclk = dev_priv->lvds_ssc_freq * 1000;
  2286. DRM_DEBUG("using SSC reference clock of %d MHz\n", refclk / 1000);
  2287. } else if (IS_I9XX(dev)) {
  2288. refclk = 96000;
  2289. if (IS_IGDNG(dev))
  2290. refclk = 120000; /* 120Mhz refclk */
  2291. } else {
  2292. refclk = 48000;
  2293. }
  2294. /*
  2295. * Returns a set of divisors for the desired target clock with the given
  2296. * refclk, or FALSE. The returned values represent the clock equation:
  2297. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  2298. */
  2299. limit = intel_limit(crtc);
  2300. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, &clock);
  2301. if (!ok) {
  2302. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  2303. drm_vblank_post_modeset(dev, pipe);
  2304. return -EINVAL;
  2305. }
  2306. if (limit->find_reduced_pll && dev_priv->lvds_downclock_avail) {
  2307. memcpy(&reduced_clock, &clock, sizeof(intel_clock_t));
  2308. has_reduced_clock = limit->find_reduced_pll(limit, crtc,
  2309. (adjusted_mode->clock*3/4),
  2310. refclk,
  2311. &reduced_clock);
  2312. }
  2313. /* SDVO TV has fixed PLL values depend on its clock range,
  2314. this mirrors vbios setting. */
  2315. if (is_sdvo && is_tv) {
  2316. if (adjusted_mode->clock >= 100000
  2317. && adjusted_mode->clock < 140500) {
  2318. clock.p1 = 2;
  2319. clock.p2 = 10;
  2320. clock.n = 3;
  2321. clock.m1 = 16;
  2322. clock.m2 = 8;
  2323. } else if (adjusted_mode->clock >= 140500
  2324. && adjusted_mode->clock <= 200000) {
  2325. clock.p1 = 1;
  2326. clock.p2 = 10;
  2327. clock.n = 6;
  2328. clock.m1 = 12;
  2329. clock.m2 = 8;
  2330. }
  2331. }
  2332. /* FDI link */
  2333. if (IS_IGDNG(dev)) {
  2334. int lane, link_bw;
  2335. /* eDP doesn't require FDI link, so just set DP M/N
  2336. according to current link config */
  2337. if (is_edp) {
  2338. struct drm_connector *edp;
  2339. target_clock = mode->clock;
  2340. edp = intel_pipe_get_output(crtc);
  2341. intel_edp_link_config(to_intel_output(edp),
  2342. &lane, &link_bw);
  2343. } else {
  2344. /* DP over FDI requires target mode clock
  2345. instead of link clock */
  2346. if (is_dp)
  2347. target_clock = mode->clock;
  2348. else
  2349. target_clock = adjusted_mode->clock;
  2350. lane = 4;
  2351. link_bw = 270000;
  2352. }
  2353. igdng_compute_m_n(3, lane, target_clock,
  2354. link_bw, &m_n);
  2355. }
  2356. if (IS_IGD(dev)) {
  2357. fp = (1 << clock.n) << 16 | clock.m1 << 8 | clock.m2;
  2358. if (has_reduced_clock)
  2359. fp2 = (1 << reduced_clock.n) << 16 |
  2360. reduced_clock.m1 << 8 | reduced_clock.m2;
  2361. } else {
  2362. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  2363. if (has_reduced_clock)
  2364. fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
  2365. reduced_clock.m2;
  2366. }
  2367. if (!IS_IGDNG(dev))
  2368. dpll = DPLL_VGA_MODE_DIS;
  2369. if (IS_I9XX(dev)) {
  2370. if (is_lvds)
  2371. dpll |= DPLLB_MODE_LVDS;
  2372. else
  2373. dpll |= DPLLB_MODE_DAC_SERIAL;
  2374. if (is_sdvo) {
  2375. dpll |= DPLL_DVO_HIGH_SPEED;
  2376. sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  2377. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  2378. dpll |= (sdvo_pixel_multiply - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  2379. else if (IS_IGDNG(dev))
  2380. dpll |= (sdvo_pixel_multiply - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  2381. }
  2382. if (is_dp)
  2383. dpll |= DPLL_DVO_HIGH_SPEED;
  2384. /* compute bitmask from p1 value */
  2385. if (IS_IGD(dev))
  2386. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_IGD;
  2387. else {
  2388. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  2389. /* also FPA1 */
  2390. if (IS_IGDNG(dev))
  2391. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  2392. if (IS_G4X(dev) && has_reduced_clock)
  2393. dpll |= (1 << (reduced_clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  2394. }
  2395. switch (clock.p2) {
  2396. case 5:
  2397. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  2398. break;
  2399. case 7:
  2400. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  2401. break;
  2402. case 10:
  2403. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  2404. break;
  2405. case 14:
  2406. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  2407. break;
  2408. }
  2409. if (IS_I965G(dev) && !IS_IGDNG(dev))
  2410. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  2411. } else {
  2412. if (is_lvds) {
  2413. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  2414. } else {
  2415. if (clock.p1 == 2)
  2416. dpll |= PLL_P1_DIVIDE_BY_TWO;
  2417. else
  2418. dpll |= (clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  2419. if (clock.p2 == 4)
  2420. dpll |= PLL_P2_DIVIDE_BY_4;
  2421. }
  2422. }
  2423. if (is_sdvo && is_tv)
  2424. dpll |= PLL_REF_INPUT_TVCLKINBC;
  2425. else if (is_tv)
  2426. /* XXX: just matching BIOS for now */
  2427. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  2428. dpll |= 3;
  2429. else if (is_lvds && dev_priv->lvds_use_ssc && num_outputs < 2)
  2430. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  2431. else
  2432. dpll |= PLL_REF_INPUT_DREFCLK;
  2433. /* setup pipeconf */
  2434. pipeconf = I915_READ(pipeconf_reg);
  2435. /* Set up the display plane register */
  2436. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2437. /* IGDNG's plane is forced to pipe, bit 24 is to
  2438. enable color space conversion */
  2439. if (!IS_IGDNG(dev)) {
  2440. if (pipe == 0)
  2441. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  2442. else
  2443. dspcntr |= DISPPLANE_SEL_PIPE_B;
  2444. }
  2445. if (pipe == 0 && !IS_I965G(dev)) {
  2446. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  2447. * core speed.
  2448. *
  2449. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  2450. * pipe == 0 check?
  2451. */
  2452. if (mode->clock > intel_get_core_clock_speed(dev) * 9 / 10)
  2453. pipeconf |= PIPEACONF_DOUBLE_WIDE;
  2454. else
  2455. pipeconf &= ~PIPEACONF_DOUBLE_WIDE;
  2456. }
  2457. dspcntr |= DISPLAY_PLANE_ENABLE;
  2458. pipeconf |= PIPEACONF_ENABLE;
  2459. dpll |= DPLL_VCO_ENABLE;
  2460. /* Disable the panel fitter if it was on our pipe */
  2461. if (!IS_IGDNG(dev) && intel_panel_fitter_pipe(dev) == pipe)
  2462. I915_WRITE(PFIT_CONTROL, 0);
  2463. DRM_DEBUG("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  2464. drm_mode_debug_printmodeline(mode);
  2465. /* assign to IGDNG registers */
  2466. if (IS_IGDNG(dev)) {
  2467. fp_reg = pch_fp_reg;
  2468. dpll_reg = pch_dpll_reg;
  2469. }
  2470. if (is_edp) {
  2471. igdng_disable_pll_edp(crtc);
  2472. } else if ((dpll & DPLL_VCO_ENABLE)) {
  2473. I915_WRITE(fp_reg, fp);
  2474. I915_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE);
  2475. I915_READ(dpll_reg);
  2476. udelay(150);
  2477. }
  2478. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  2479. * This is an exception to the general rule that mode_set doesn't turn
  2480. * things on.
  2481. */
  2482. if (is_lvds) {
  2483. u32 lvds;
  2484. if (IS_IGDNG(dev))
  2485. lvds_reg = PCH_LVDS;
  2486. lvds = I915_READ(lvds_reg);
  2487. lvds |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP | LVDS_PIPEB_SELECT;
  2488. /* Set the B0-B3 data pairs corresponding to whether we're going to
  2489. * set the DPLLs for dual-channel mode or not.
  2490. */
  2491. if (clock.p2 == 7)
  2492. lvds |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  2493. else
  2494. lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  2495. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  2496. * appropriately here, but we need to look more thoroughly into how
  2497. * panels behave in the two modes.
  2498. */
  2499. I915_WRITE(lvds_reg, lvds);
  2500. I915_READ(lvds_reg);
  2501. }
  2502. if (is_dp)
  2503. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  2504. if (!is_edp) {
  2505. I915_WRITE(fp_reg, fp);
  2506. I915_WRITE(dpll_reg, dpll);
  2507. I915_READ(dpll_reg);
  2508. /* Wait for the clocks to stabilize. */
  2509. udelay(150);
  2510. if (IS_I965G(dev) && !IS_IGDNG(dev)) {
  2511. if (is_sdvo) {
  2512. sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  2513. I915_WRITE(dpll_md_reg, (0 << DPLL_MD_UDI_DIVIDER_SHIFT) |
  2514. ((sdvo_pixel_multiply - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT));
  2515. } else
  2516. I915_WRITE(dpll_md_reg, 0);
  2517. } else {
  2518. /* write it again -- the BIOS does, after all */
  2519. I915_WRITE(dpll_reg, dpll);
  2520. }
  2521. I915_READ(dpll_reg);
  2522. /* Wait for the clocks to stabilize. */
  2523. udelay(150);
  2524. }
  2525. if (is_lvds && has_reduced_clock && i915_powersave) {
  2526. I915_WRITE(fp_reg + 4, fp2);
  2527. intel_crtc->lowfreq_avail = true;
  2528. if (HAS_PIPE_CXSR(dev)) {
  2529. DRM_DEBUG("enabling CxSR downclocking\n");
  2530. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  2531. }
  2532. } else {
  2533. I915_WRITE(fp_reg + 4, fp);
  2534. intel_crtc->lowfreq_avail = false;
  2535. if (HAS_PIPE_CXSR(dev)) {
  2536. DRM_DEBUG("disabling CxSR downclocking\n");
  2537. pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
  2538. }
  2539. }
  2540. I915_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) |
  2541. ((adjusted_mode->crtc_htotal - 1) << 16));
  2542. I915_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) |
  2543. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  2544. I915_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) |
  2545. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  2546. I915_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) |
  2547. ((adjusted_mode->crtc_vtotal - 1) << 16));
  2548. I915_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) |
  2549. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  2550. I915_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) |
  2551. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  2552. /* pipesrc and dspsize control the size that is scaled from, which should
  2553. * always be the user's requested size.
  2554. */
  2555. if (!IS_IGDNG(dev)) {
  2556. I915_WRITE(dspsize_reg, ((mode->vdisplay - 1) << 16) |
  2557. (mode->hdisplay - 1));
  2558. I915_WRITE(dsppos_reg, 0);
  2559. }
  2560. I915_WRITE(pipesrc_reg, ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  2561. if (IS_IGDNG(dev)) {
  2562. I915_WRITE(data_m1_reg, TU_SIZE(m_n.tu) | m_n.gmch_m);
  2563. I915_WRITE(data_n1_reg, TU_SIZE(m_n.tu) | m_n.gmch_n);
  2564. I915_WRITE(link_m1_reg, m_n.link_m);
  2565. I915_WRITE(link_n1_reg, m_n.link_n);
  2566. if (is_edp) {
  2567. igdng_set_pll_edp(crtc, adjusted_mode->clock);
  2568. } else {
  2569. /* enable FDI RX PLL too */
  2570. temp = I915_READ(fdi_rx_reg);
  2571. I915_WRITE(fdi_rx_reg, temp | FDI_RX_PLL_ENABLE);
  2572. udelay(200);
  2573. }
  2574. }
  2575. I915_WRITE(pipeconf_reg, pipeconf);
  2576. I915_READ(pipeconf_reg);
  2577. intel_wait_for_vblank(dev);
  2578. if (IS_IGDNG(dev)) {
  2579. /* enable address swizzle for tiling buffer */
  2580. temp = I915_READ(DISP_ARB_CTL);
  2581. I915_WRITE(DISP_ARB_CTL, temp | DISP_TILE_SURFACE_SWIZZLING);
  2582. }
  2583. I915_WRITE(dspcntr_reg, dspcntr);
  2584. /* Flush the plane changes */
  2585. ret = intel_pipe_set_base(crtc, x, y, old_fb);
  2586. if (I915_HAS_FBC(dev) && (IS_I965G(dev) || plane == 0))
  2587. intel_update_fbc(crtc, &crtc->mode);
  2588. intel_update_watermarks(dev);
  2589. drm_vblank_post_modeset(dev, pipe);
  2590. return ret;
  2591. }
  2592. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  2593. void intel_crtc_load_lut(struct drm_crtc *crtc)
  2594. {
  2595. struct drm_device *dev = crtc->dev;
  2596. struct drm_i915_private *dev_priv = dev->dev_private;
  2597. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2598. int palreg = (intel_crtc->pipe == 0) ? PALETTE_A : PALETTE_B;
  2599. int i;
  2600. /* The clocks have to be on to load the palette. */
  2601. if (!crtc->enabled)
  2602. return;
  2603. /* use legacy palette for IGDNG */
  2604. if (IS_IGDNG(dev))
  2605. palreg = (intel_crtc->pipe == 0) ? LGC_PALETTE_A :
  2606. LGC_PALETTE_B;
  2607. for (i = 0; i < 256; i++) {
  2608. I915_WRITE(palreg + 4 * i,
  2609. (intel_crtc->lut_r[i] << 16) |
  2610. (intel_crtc->lut_g[i] << 8) |
  2611. intel_crtc->lut_b[i]);
  2612. }
  2613. }
  2614. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  2615. struct drm_file *file_priv,
  2616. uint32_t handle,
  2617. uint32_t width, uint32_t height)
  2618. {
  2619. struct drm_device *dev = crtc->dev;
  2620. struct drm_i915_private *dev_priv = dev->dev_private;
  2621. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2622. struct drm_gem_object *bo;
  2623. struct drm_i915_gem_object *obj_priv;
  2624. int pipe = intel_crtc->pipe;
  2625. int plane = intel_crtc->plane;
  2626. uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR;
  2627. uint32_t base = (pipe == 0) ? CURABASE : CURBBASE;
  2628. uint32_t temp = I915_READ(control);
  2629. size_t addr;
  2630. int ret;
  2631. DRM_DEBUG("\n");
  2632. /* if we want to turn off the cursor ignore width and height */
  2633. if (!handle) {
  2634. DRM_DEBUG("cursor off\n");
  2635. if (IS_MOBILE(dev) || IS_I9XX(dev)) {
  2636. temp &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  2637. temp |= CURSOR_MODE_DISABLE;
  2638. } else {
  2639. temp &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
  2640. }
  2641. addr = 0;
  2642. bo = NULL;
  2643. mutex_lock(&dev->struct_mutex);
  2644. goto finish;
  2645. }
  2646. /* Currently we only support 64x64 cursors */
  2647. if (width != 64 || height != 64) {
  2648. DRM_ERROR("we currently only support 64x64 cursors\n");
  2649. return -EINVAL;
  2650. }
  2651. bo = drm_gem_object_lookup(dev, file_priv, handle);
  2652. if (!bo)
  2653. return -ENOENT;
  2654. obj_priv = bo->driver_private;
  2655. if (bo->size < width * height * 4) {
  2656. DRM_ERROR("buffer is to small\n");
  2657. ret = -ENOMEM;
  2658. goto fail;
  2659. }
  2660. /* we only need to pin inside GTT if cursor is non-phy */
  2661. mutex_lock(&dev->struct_mutex);
  2662. if (!dev_priv->cursor_needs_physical) {
  2663. ret = i915_gem_object_pin(bo, PAGE_SIZE);
  2664. if (ret) {
  2665. DRM_ERROR("failed to pin cursor bo\n");
  2666. goto fail_locked;
  2667. }
  2668. addr = obj_priv->gtt_offset;
  2669. } else {
  2670. ret = i915_gem_attach_phys_object(dev, bo, (pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1);
  2671. if (ret) {
  2672. DRM_ERROR("failed to attach phys object\n");
  2673. goto fail_locked;
  2674. }
  2675. addr = obj_priv->phys_obj->handle->busaddr;
  2676. }
  2677. if (!IS_I9XX(dev))
  2678. I915_WRITE(CURSIZE, (height << 12) | width);
  2679. /* Hooray for CUR*CNTR differences */
  2680. if (IS_MOBILE(dev) || IS_I9XX(dev)) {
  2681. temp &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
  2682. temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  2683. temp |= (pipe << 28); /* Connect to correct pipe */
  2684. } else {
  2685. temp &= ~(CURSOR_FORMAT_MASK);
  2686. temp |= CURSOR_ENABLE;
  2687. temp |= CURSOR_FORMAT_ARGB | CURSOR_GAMMA_ENABLE;
  2688. }
  2689. finish:
  2690. I915_WRITE(control, temp);
  2691. I915_WRITE(base, addr);
  2692. if (intel_crtc->cursor_bo) {
  2693. if (dev_priv->cursor_needs_physical) {
  2694. if (intel_crtc->cursor_bo != bo)
  2695. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  2696. } else
  2697. i915_gem_object_unpin(intel_crtc->cursor_bo);
  2698. drm_gem_object_unreference(intel_crtc->cursor_bo);
  2699. }
  2700. if (I915_HAS_FBC(dev) && (IS_I965G(dev) || plane == 0))
  2701. intel_update_fbc(crtc, &crtc->mode);
  2702. mutex_unlock(&dev->struct_mutex);
  2703. intel_crtc->cursor_addr = addr;
  2704. intel_crtc->cursor_bo = bo;
  2705. return 0;
  2706. fail:
  2707. mutex_lock(&dev->struct_mutex);
  2708. fail_locked:
  2709. drm_gem_object_unreference(bo);
  2710. mutex_unlock(&dev->struct_mutex);
  2711. return ret;
  2712. }
  2713. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  2714. {
  2715. struct drm_device *dev = crtc->dev;
  2716. struct drm_i915_private *dev_priv = dev->dev_private;
  2717. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2718. struct intel_framebuffer *intel_fb;
  2719. int pipe = intel_crtc->pipe;
  2720. uint32_t temp = 0;
  2721. uint32_t adder;
  2722. if (crtc->fb) {
  2723. intel_fb = to_intel_framebuffer(crtc->fb);
  2724. intel_mark_busy(dev, intel_fb->obj);
  2725. }
  2726. if (x < 0) {
  2727. temp |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  2728. x = -x;
  2729. }
  2730. if (y < 0) {
  2731. temp |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  2732. y = -y;
  2733. }
  2734. temp |= x << CURSOR_X_SHIFT;
  2735. temp |= y << CURSOR_Y_SHIFT;
  2736. adder = intel_crtc->cursor_addr;
  2737. I915_WRITE((pipe == 0) ? CURAPOS : CURBPOS, temp);
  2738. I915_WRITE((pipe == 0) ? CURABASE : CURBBASE, adder);
  2739. return 0;
  2740. }
  2741. /** Sets the color ramps on behalf of RandR */
  2742. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  2743. u16 blue, int regno)
  2744. {
  2745. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2746. intel_crtc->lut_r[regno] = red >> 8;
  2747. intel_crtc->lut_g[regno] = green >> 8;
  2748. intel_crtc->lut_b[regno] = blue >> 8;
  2749. }
  2750. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  2751. u16 *blue, uint32_t size)
  2752. {
  2753. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2754. int i;
  2755. if (size != 256)
  2756. return;
  2757. for (i = 0; i < 256; i++) {
  2758. intel_crtc->lut_r[i] = red[i] >> 8;
  2759. intel_crtc->lut_g[i] = green[i] >> 8;
  2760. intel_crtc->lut_b[i] = blue[i] >> 8;
  2761. }
  2762. intel_crtc_load_lut(crtc);
  2763. }
  2764. /**
  2765. * Get a pipe with a simple mode set on it for doing load-based monitor
  2766. * detection.
  2767. *
  2768. * It will be up to the load-detect code to adjust the pipe as appropriate for
  2769. * its requirements. The pipe will be connected to no other outputs.
  2770. *
  2771. * Currently this code will only succeed if there is a pipe with no outputs
  2772. * configured for it. In the future, it could choose to temporarily disable
  2773. * some outputs to free up a pipe for its use.
  2774. *
  2775. * \return crtc, or NULL if no pipes are available.
  2776. */
  2777. /* VESA 640x480x72Hz mode to set on the pipe */
  2778. static struct drm_display_mode load_detect_mode = {
  2779. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  2780. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  2781. };
  2782. struct drm_crtc *intel_get_load_detect_pipe(struct intel_output *intel_output,
  2783. struct drm_display_mode *mode,
  2784. int *dpms_mode)
  2785. {
  2786. struct intel_crtc *intel_crtc;
  2787. struct drm_crtc *possible_crtc;
  2788. struct drm_crtc *supported_crtc =NULL;
  2789. struct drm_encoder *encoder = &intel_output->enc;
  2790. struct drm_crtc *crtc = NULL;
  2791. struct drm_device *dev = encoder->dev;
  2792. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  2793. struct drm_crtc_helper_funcs *crtc_funcs;
  2794. int i = -1;
  2795. /*
  2796. * Algorithm gets a little messy:
  2797. * - if the connector already has an assigned crtc, use it (but make
  2798. * sure it's on first)
  2799. * - try to find the first unused crtc that can drive this connector,
  2800. * and use that if we find one
  2801. * - if there are no unused crtcs available, try to use the first
  2802. * one we found that supports the connector
  2803. */
  2804. /* See if we already have a CRTC for this connector */
  2805. if (encoder->crtc) {
  2806. crtc = encoder->crtc;
  2807. /* Make sure the crtc and connector are running */
  2808. intel_crtc = to_intel_crtc(crtc);
  2809. *dpms_mode = intel_crtc->dpms_mode;
  2810. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  2811. crtc_funcs = crtc->helper_private;
  2812. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  2813. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  2814. }
  2815. return crtc;
  2816. }
  2817. /* Find an unused one (if possible) */
  2818. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  2819. i++;
  2820. if (!(encoder->possible_crtcs & (1 << i)))
  2821. continue;
  2822. if (!possible_crtc->enabled) {
  2823. crtc = possible_crtc;
  2824. break;
  2825. }
  2826. if (!supported_crtc)
  2827. supported_crtc = possible_crtc;
  2828. }
  2829. /*
  2830. * If we didn't find an unused CRTC, don't use any.
  2831. */
  2832. if (!crtc) {
  2833. return NULL;
  2834. }
  2835. encoder->crtc = crtc;
  2836. intel_output->base.encoder = encoder;
  2837. intel_output->load_detect_temp = true;
  2838. intel_crtc = to_intel_crtc(crtc);
  2839. *dpms_mode = intel_crtc->dpms_mode;
  2840. if (!crtc->enabled) {
  2841. if (!mode)
  2842. mode = &load_detect_mode;
  2843. drm_crtc_helper_set_mode(crtc, mode, 0, 0, crtc->fb);
  2844. } else {
  2845. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  2846. crtc_funcs = crtc->helper_private;
  2847. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  2848. }
  2849. /* Add this connector to the crtc */
  2850. encoder_funcs->mode_set(encoder, &crtc->mode, &crtc->mode);
  2851. encoder_funcs->commit(encoder);
  2852. }
  2853. /* let the connector get through one full cycle before testing */
  2854. intel_wait_for_vblank(dev);
  2855. return crtc;
  2856. }
  2857. void intel_release_load_detect_pipe(struct intel_output *intel_output, int dpms_mode)
  2858. {
  2859. struct drm_encoder *encoder = &intel_output->enc;
  2860. struct drm_device *dev = encoder->dev;
  2861. struct drm_crtc *crtc = encoder->crtc;
  2862. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  2863. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  2864. if (intel_output->load_detect_temp) {
  2865. encoder->crtc = NULL;
  2866. intel_output->base.encoder = NULL;
  2867. intel_output->load_detect_temp = false;
  2868. crtc->enabled = drm_helper_crtc_in_use(crtc);
  2869. drm_helper_disable_unused_functions(dev);
  2870. }
  2871. /* Switch crtc and output back off if necessary */
  2872. if (crtc->enabled && dpms_mode != DRM_MODE_DPMS_ON) {
  2873. if (encoder->crtc == crtc)
  2874. encoder_funcs->dpms(encoder, dpms_mode);
  2875. crtc_funcs->dpms(crtc, dpms_mode);
  2876. }
  2877. }
  2878. /* Returns the clock of the currently programmed mode of the given pipe. */
  2879. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  2880. {
  2881. struct drm_i915_private *dev_priv = dev->dev_private;
  2882. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2883. int pipe = intel_crtc->pipe;
  2884. u32 dpll = I915_READ((pipe == 0) ? DPLL_A : DPLL_B);
  2885. u32 fp;
  2886. intel_clock_t clock;
  2887. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  2888. fp = I915_READ((pipe == 0) ? FPA0 : FPB0);
  2889. else
  2890. fp = I915_READ((pipe == 0) ? FPA1 : FPB1);
  2891. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  2892. if (IS_IGD(dev)) {
  2893. clock.n = ffs((fp & FP_N_IGD_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  2894. clock.m2 = (fp & FP_M2_IGD_DIV_MASK) >> FP_M2_DIV_SHIFT;
  2895. } else {
  2896. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  2897. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  2898. }
  2899. if (IS_I9XX(dev)) {
  2900. if (IS_IGD(dev))
  2901. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_IGD) >>
  2902. DPLL_FPA01_P1_POST_DIV_SHIFT_IGD);
  2903. else
  2904. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  2905. DPLL_FPA01_P1_POST_DIV_SHIFT);
  2906. switch (dpll & DPLL_MODE_MASK) {
  2907. case DPLLB_MODE_DAC_SERIAL:
  2908. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  2909. 5 : 10;
  2910. break;
  2911. case DPLLB_MODE_LVDS:
  2912. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  2913. 7 : 14;
  2914. break;
  2915. default:
  2916. DRM_DEBUG("Unknown DPLL mode %08x in programmed "
  2917. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  2918. return 0;
  2919. }
  2920. /* XXX: Handle the 100Mhz refclk */
  2921. intel_clock(dev, 96000, &clock);
  2922. } else {
  2923. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  2924. if (is_lvds) {
  2925. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  2926. DPLL_FPA01_P1_POST_DIV_SHIFT);
  2927. clock.p2 = 14;
  2928. if ((dpll & PLL_REF_INPUT_MASK) ==
  2929. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  2930. /* XXX: might not be 66MHz */
  2931. intel_clock(dev, 66000, &clock);
  2932. } else
  2933. intel_clock(dev, 48000, &clock);
  2934. } else {
  2935. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  2936. clock.p1 = 2;
  2937. else {
  2938. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  2939. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  2940. }
  2941. if (dpll & PLL_P2_DIVIDE_BY_4)
  2942. clock.p2 = 4;
  2943. else
  2944. clock.p2 = 2;
  2945. intel_clock(dev, 48000, &clock);
  2946. }
  2947. }
  2948. /* XXX: It would be nice to validate the clocks, but we can't reuse
  2949. * i830PllIsValid() because it relies on the xf86_config connector
  2950. * configuration being accurate, which it isn't necessarily.
  2951. */
  2952. return clock.dot;
  2953. }
  2954. /** Returns the currently programmed mode of the given pipe. */
  2955. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  2956. struct drm_crtc *crtc)
  2957. {
  2958. struct drm_i915_private *dev_priv = dev->dev_private;
  2959. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2960. int pipe = intel_crtc->pipe;
  2961. struct drm_display_mode *mode;
  2962. int htot = I915_READ((pipe == 0) ? HTOTAL_A : HTOTAL_B);
  2963. int hsync = I915_READ((pipe == 0) ? HSYNC_A : HSYNC_B);
  2964. int vtot = I915_READ((pipe == 0) ? VTOTAL_A : VTOTAL_B);
  2965. int vsync = I915_READ((pipe == 0) ? VSYNC_A : VSYNC_B);
  2966. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  2967. if (!mode)
  2968. return NULL;
  2969. mode->clock = intel_crtc_clock_get(dev, crtc);
  2970. mode->hdisplay = (htot & 0xffff) + 1;
  2971. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  2972. mode->hsync_start = (hsync & 0xffff) + 1;
  2973. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  2974. mode->vdisplay = (vtot & 0xffff) + 1;
  2975. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  2976. mode->vsync_start = (vsync & 0xffff) + 1;
  2977. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  2978. drm_mode_set_name(mode);
  2979. drm_mode_set_crtcinfo(mode, 0);
  2980. return mode;
  2981. }
  2982. #define GPU_IDLE_TIMEOUT 500 /* ms */
  2983. /* When this timer fires, we've been idle for awhile */
  2984. static void intel_gpu_idle_timer(unsigned long arg)
  2985. {
  2986. struct drm_device *dev = (struct drm_device *)arg;
  2987. drm_i915_private_t *dev_priv = dev->dev_private;
  2988. DRM_DEBUG("idle timer fired, downclocking\n");
  2989. dev_priv->busy = false;
  2990. queue_work(dev_priv->wq, &dev_priv->idle_work);
  2991. }
  2992. void intel_increase_renderclock(struct drm_device *dev, bool schedule)
  2993. {
  2994. drm_i915_private_t *dev_priv = dev->dev_private;
  2995. if (IS_IGDNG(dev))
  2996. return;
  2997. if (!dev_priv->render_reclock_avail) {
  2998. DRM_DEBUG("not reclocking render clock\n");
  2999. return;
  3000. }
  3001. /* Restore render clock frequency to original value */
  3002. if (IS_G4X(dev) || IS_I9XX(dev))
  3003. pci_write_config_word(dev->pdev, GCFGC, dev_priv->orig_clock);
  3004. else if (IS_I85X(dev))
  3005. pci_write_config_word(dev->pdev, HPLLCC, dev_priv->orig_clock);
  3006. DRM_DEBUG("increasing render clock frequency\n");
  3007. /* Schedule downclock */
  3008. if (schedule)
  3009. mod_timer(&dev_priv->idle_timer, jiffies +
  3010. msecs_to_jiffies(GPU_IDLE_TIMEOUT));
  3011. }
  3012. void intel_decrease_renderclock(struct drm_device *dev)
  3013. {
  3014. drm_i915_private_t *dev_priv = dev->dev_private;
  3015. if (IS_IGDNG(dev))
  3016. return;
  3017. if (!dev_priv->render_reclock_avail) {
  3018. DRM_DEBUG("not reclocking render clock\n");
  3019. return;
  3020. }
  3021. if (IS_G4X(dev)) {
  3022. u16 gcfgc;
  3023. /* Adjust render clock... */
  3024. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3025. /* Down to minimum... */
  3026. gcfgc &= ~GM45_GC_RENDER_CLOCK_MASK;
  3027. gcfgc |= GM45_GC_RENDER_CLOCK_266_MHZ;
  3028. pci_write_config_word(dev->pdev, GCFGC, gcfgc);
  3029. } else if (IS_I965G(dev)) {
  3030. u16 gcfgc;
  3031. /* Adjust render clock... */
  3032. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3033. /* Down to minimum... */
  3034. gcfgc &= ~I965_GC_RENDER_CLOCK_MASK;
  3035. gcfgc |= I965_GC_RENDER_CLOCK_267_MHZ;
  3036. pci_write_config_word(dev->pdev, GCFGC, gcfgc);
  3037. } else if (IS_I945G(dev) || IS_I945GM(dev)) {
  3038. u16 gcfgc;
  3039. /* Adjust render clock... */
  3040. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3041. /* Down to minimum... */
  3042. gcfgc &= ~I945_GC_RENDER_CLOCK_MASK;
  3043. gcfgc |= I945_GC_RENDER_CLOCK_166_MHZ;
  3044. pci_write_config_word(dev->pdev, GCFGC, gcfgc);
  3045. } else if (IS_I915G(dev)) {
  3046. u16 gcfgc;
  3047. /* Adjust render clock... */
  3048. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3049. /* Down to minimum... */
  3050. gcfgc &= ~I915_GC_RENDER_CLOCK_MASK;
  3051. gcfgc |= I915_GC_RENDER_CLOCK_166_MHZ;
  3052. pci_write_config_word(dev->pdev, GCFGC, gcfgc);
  3053. } else if (IS_I85X(dev)) {
  3054. u16 hpllcc;
  3055. /* Adjust render clock... */
  3056. pci_read_config_word(dev->pdev, HPLLCC, &hpllcc);
  3057. /* Up to maximum... */
  3058. hpllcc &= ~GC_CLOCK_CONTROL_MASK;
  3059. hpllcc |= GC_CLOCK_133_200;
  3060. pci_write_config_word(dev->pdev, HPLLCC, hpllcc);
  3061. }
  3062. DRM_DEBUG("decreasing render clock frequency\n");
  3063. }
  3064. /* Note that no increase function is needed for this - increase_renderclock()
  3065. * will also rewrite these bits
  3066. */
  3067. void intel_decrease_displayclock(struct drm_device *dev)
  3068. {
  3069. if (IS_IGDNG(dev))
  3070. return;
  3071. if (IS_I945G(dev) || IS_I945GM(dev) || IS_I915G(dev) ||
  3072. IS_I915GM(dev)) {
  3073. u16 gcfgc;
  3074. /* Adjust render clock... */
  3075. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3076. /* Down to minimum... */
  3077. gcfgc &= ~0xf0;
  3078. gcfgc |= 0x80;
  3079. pci_write_config_word(dev->pdev, GCFGC, gcfgc);
  3080. }
  3081. }
  3082. #define CRTC_IDLE_TIMEOUT 1000 /* ms */
  3083. static void intel_crtc_idle_timer(unsigned long arg)
  3084. {
  3085. struct intel_crtc *intel_crtc = (struct intel_crtc *)arg;
  3086. struct drm_crtc *crtc = &intel_crtc->base;
  3087. drm_i915_private_t *dev_priv = crtc->dev->dev_private;
  3088. DRM_DEBUG("idle timer fired, downclocking\n");
  3089. intel_crtc->busy = false;
  3090. queue_work(dev_priv->wq, &dev_priv->idle_work);
  3091. }
  3092. static void intel_increase_pllclock(struct drm_crtc *crtc, bool schedule)
  3093. {
  3094. struct drm_device *dev = crtc->dev;
  3095. drm_i915_private_t *dev_priv = dev->dev_private;
  3096. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3097. int pipe = intel_crtc->pipe;
  3098. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  3099. int dpll = I915_READ(dpll_reg);
  3100. if (IS_IGDNG(dev))
  3101. return;
  3102. if (!dev_priv->lvds_downclock_avail)
  3103. return;
  3104. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  3105. DRM_DEBUG("upclocking LVDS\n");
  3106. /* Unlock panel regs */
  3107. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) | (0xabcd << 16));
  3108. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  3109. I915_WRITE(dpll_reg, dpll);
  3110. dpll = I915_READ(dpll_reg);
  3111. intel_wait_for_vblank(dev);
  3112. dpll = I915_READ(dpll_reg);
  3113. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  3114. DRM_DEBUG("failed to upclock LVDS!\n");
  3115. /* ...and lock them again */
  3116. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
  3117. }
  3118. /* Schedule downclock */
  3119. if (schedule)
  3120. mod_timer(&intel_crtc->idle_timer, jiffies +
  3121. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  3122. }
  3123. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  3124. {
  3125. struct drm_device *dev = crtc->dev;
  3126. drm_i915_private_t *dev_priv = dev->dev_private;
  3127. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3128. int pipe = intel_crtc->pipe;
  3129. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  3130. int dpll = I915_READ(dpll_reg);
  3131. if (IS_IGDNG(dev))
  3132. return;
  3133. if (!dev_priv->lvds_downclock_avail)
  3134. return;
  3135. /*
  3136. * Since this is called by a timer, we should never get here in
  3137. * the manual case.
  3138. */
  3139. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  3140. DRM_DEBUG("downclocking LVDS\n");
  3141. /* Unlock panel regs */
  3142. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) | (0xabcd << 16));
  3143. dpll |= DISPLAY_RATE_SELECT_FPA1;
  3144. I915_WRITE(dpll_reg, dpll);
  3145. dpll = I915_READ(dpll_reg);
  3146. intel_wait_for_vblank(dev);
  3147. dpll = I915_READ(dpll_reg);
  3148. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  3149. DRM_DEBUG("failed to downclock LVDS!\n");
  3150. /* ...and lock them again */
  3151. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
  3152. }
  3153. }
  3154. /**
  3155. * intel_idle_update - adjust clocks for idleness
  3156. * @work: work struct
  3157. *
  3158. * Either the GPU or display (or both) went idle. Check the busy status
  3159. * here and adjust the CRTC and GPU clocks as necessary.
  3160. */
  3161. static void intel_idle_update(struct work_struct *work)
  3162. {
  3163. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  3164. idle_work);
  3165. struct drm_device *dev = dev_priv->dev;
  3166. struct drm_crtc *crtc;
  3167. struct intel_crtc *intel_crtc;
  3168. if (!i915_powersave)
  3169. return;
  3170. mutex_lock(&dev->struct_mutex);
  3171. /* GPU isn't processing, downclock it. */
  3172. if (!dev_priv->busy) {
  3173. intel_decrease_renderclock(dev);
  3174. intel_decrease_displayclock(dev);
  3175. }
  3176. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3177. /* Skip inactive CRTCs */
  3178. if (!crtc->fb)
  3179. continue;
  3180. intel_crtc = to_intel_crtc(crtc);
  3181. if (!intel_crtc->busy)
  3182. intel_decrease_pllclock(crtc);
  3183. }
  3184. mutex_unlock(&dev->struct_mutex);
  3185. }
  3186. /**
  3187. * intel_mark_busy - mark the GPU and possibly the display busy
  3188. * @dev: drm device
  3189. * @obj: object we're operating on
  3190. *
  3191. * Callers can use this function to indicate that the GPU is busy processing
  3192. * commands. If @obj matches one of the CRTC objects (i.e. it's a scanout
  3193. * buffer), we'll also mark the display as busy, so we know to increase its
  3194. * clock frequency.
  3195. */
  3196. void intel_mark_busy(struct drm_device *dev, struct drm_gem_object *obj)
  3197. {
  3198. drm_i915_private_t *dev_priv = dev->dev_private;
  3199. struct drm_crtc *crtc = NULL;
  3200. struct intel_framebuffer *intel_fb;
  3201. struct intel_crtc *intel_crtc;
  3202. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  3203. return;
  3204. dev_priv->busy = true;
  3205. intel_increase_renderclock(dev, true);
  3206. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3207. if (!crtc->fb)
  3208. continue;
  3209. intel_crtc = to_intel_crtc(crtc);
  3210. intel_fb = to_intel_framebuffer(crtc->fb);
  3211. if (intel_fb->obj == obj) {
  3212. if (!intel_crtc->busy) {
  3213. /* Non-busy -> busy, upclock */
  3214. intel_increase_pllclock(crtc, true);
  3215. intel_crtc->busy = true;
  3216. } else {
  3217. /* Busy -> busy, put off timer */
  3218. mod_timer(&intel_crtc->idle_timer, jiffies +
  3219. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  3220. }
  3221. }
  3222. }
  3223. }
  3224. static void intel_crtc_destroy(struct drm_crtc *crtc)
  3225. {
  3226. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3227. drm_crtc_cleanup(crtc);
  3228. kfree(intel_crtc);
  3229. }
  3230. static const struct drm_crtc_helper_funcs intel_helper_funcs = {
  3231. .dpms = intel_crtc_dpms,
  3232. .mode_fixup = intel_crtc_mode_fixup,
  3233. .mode_set = intel_crtc_mode_set,
  3234. .mode_set_base = intel_pipe_set_base,
  3235. .prepare = intel_crtc_prepare,
  3236. .commit = intel_crtc_commit,
  3237. };
  3238. static const struct drm_crtc_funcs intel_crtc_funcs = {
  3239. .cursor_set = intel_crtc_cursor_set,
  3240. .cursor_move = intel_crtc_cursor_move,
  3241. .gamma_set = intel_crtc_gamma_set,
  3242. .set_config = drm_crtc_helper_set_config,
  3243. .destroy = intel_crtc_destroy,
  3244. };
  3245. static void intel_crtc_init(struct drm_device *dev, int pipe)
  3246. {
  3247. struct intel_crtc *intel_crtc;
  3248. int i;
  3249. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  3250. if (intel_crtc == NULL)
  3251. return;
  3252. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  3253. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  3254. intel_crtc->pipe = pipe;
  3255. intel_crtc->plane = pipe;
  3256. for (i = 0; i < 256; i++) {
  3257. intel_crtc->lut_r[i] = i;
  3258. intel_crtc->lut_g[i] = i;
  3259. intel_crtc->lut_b[i] = i;
  3260. }
  3261. /* Swap pipes & planes for FBC on pre-965 */
  3262. intel_crtc->pipe = pipe;
  3263. intel_crtc->plane = pipe;
  3264. if (IS_MOBILE(dev) && (IS_I9XX(dev) && !IS_I965G(dev))) {
  3265. DRM_DEBUG("swapping pipes & planes for FBC\n");
  3266. intel_crtc->plane = ((pipe == 0) ? 1 : 0);
  3267. }
  3268. intel_crtc->cursor_addr = 0;
  3269. intel_crtc->dpms_mode = DRM_MODE_DPMS_OFF;
  3270. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  3271. intel_crtc->busy = false;
  3272. setup_timer(&intel_crtc->idle_timer, intel_crtc_idle_timer,
  3273. (unsigned long)intel_crtc);
  3274. }
  3275. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  3276. struct drm_file *file_priv)
  3277. {
  3278. drm_i915_private_t *dev_priv = dev->dev_private;
  3279. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  3280. struct drm_mode_object *drmmode_obj;
  3281. struct intel_crtc *crtc;
  3282. if (!dev_priv) {
  3283. DRM_ERROR("called with no initialization\n");
  3284. return -EINVAL;
  3285. }
  3286. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  3287. DRM_MODE_OBJECT_CRTC);
  3288. if (!drmmode_obj) {
  3289. DRM_ERROR("no such CRTC id\n");
  3290. return -EINVAL;
  3291. }
  3292. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  3293. pipe_from_crtc_id->pipe = crtc->pipe;
  3294. return 0;
  3295. }
  3296. struct drm_crtc *intel_get_crtc_from_pipe(struct drm_device *dev, int pipe)
  3297. {
  3298. struct drm_crtc *crtc = NULL;
  3299. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3300. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3301. if (intel_crtc->pipe == pipe)
  3302. break;
  3303. }
  3304. return crtc;
  3305. }
  3306. static int intel_connector_clones(struct drm_device *dev, int type_mask)
  3307. {
  3308. int index_mask = 0;
  3309. struct drm_connector *connector;
  3310. int entry = 0;
  3311. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  3312. struct intel_output *intel_output = to_intel_output(connector);
  3313. if (type_mask & intel_output->clone_mask)
  3314. index_mask |= (1 << entry);
  3315. entry++;
  3316. }
  3317. return index_mask;
  3318. }
  3319. static void intel_setup_outputs(struct drm_device *dev)
  3320. {
  3321. struct drm_i915_private *dev_priv = dev->dev_private;
  3322. struct drm_connector *connector;
  3323. intel_crt_init(dev);
  3324. /* Set up integrated LVDS */
  3325. if (IS_MOBILE(dev) && !IS_I830(dev))
  3326. intel_lvds_init(dev);
  3327. if (IS_IGDNG(dev)) {
  3328. int found;
  3329. if (IS_MOBILE(dev) && (I915_READ(DP_A) & DP_DETECTED))
  3330. intel_dp_init(dev, DP_A);
  3331. if (I915_READ(HDMIB) & PORT_DETECTED) {
  3332. /* check SDVOB */
  3333. /* found = intel_sdvo_init(dev, HDMIB); */
  3334. found = 0;
  3335. if (!found)
  3336. intel_hdmi_init(dev, HDMIB);
  3337. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  3338. intel_dp_init(dev, PCH_DP_B);
  3339. }
  3340. if (I915_READ(HDMIC) & PORT_DETECTED)
  3341. intel_hdmi_init(dev, HDMIC);
  3342. if (I915_READ(HDMID) & PORT_DETECTED)
  3343. intel_hdmi_init(dev, HDMID);
  3344. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  3345. intel_dp_init(dev, PCH_DP_C);
  3346. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  3347. intel_dp_init(dev, PCH_DP_D);
  3348. } else if (IS_I9XX(dev)) {
  3349. bool found = false;
  3350. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  3351. found = intel_sdvo_init(dev, SDVOB);
  3352. if (!found && SUPPORTS_INTEGRATED_HDMI(dev))
  3353. intel_hdmi_init(dev, SDVOB);
  3354. if (!found && SUPPORTS_INTEGRATED_DP(dev))
  3355. intel_dp_init(dev, DP_B);
  3356. }
  3357. /* Before G4X SDVOC doesn't have its own detect register */
  3358. if (I915_READ(SDVOB) & SDVO_DETECTED)
  3359. found = intel_sdvo_init(dev, SDVOC);
  3360. if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
  3361. if (SUPPORTS_INTEGRATED_HDMI(dev))
  3362. intel_hdmi_init(dev, SDVOC);
  3363. if (SUPPORTS_INTEGRATED_DP(dev))
  3364. intel_dp_init(dev, DP_C);
  3365. }
  3366. if (SUPPORTS_INTEGRATED_DP(dev) && (I915_READ(DP_D) & DP_DETECTED))
  3367. intel_dp_init(dev, DP_D);
  3368. } else
  3369. intel_dvo_init(dev);
  3370. if (IS_I9XX(dev) && IS_MOBILE(dev) && !IS_IGDNG(dev))
  3371. intel_tv_init(dev);
  3372. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  3373. struct intel_output *intel_output = to_intel_output(connector);
  3374. struct drm_encoder *encoder = &intel_output->enc;
  3375. encoder->possible_crtcs = intel_output->crtc_mask;
  3376. encoder->possible_clones = intel_connector_clones(dev,
  3377. intel_output->clone_mask);
  3378. }
  3379. }
  3380. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  3381. {
  3382. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  3383. struct drm_device *dev = fb->dev;
  3384. if (fb->fbdev)
  3385. intelfb_remove(dev, fb);
  3386. drm_framebuffer_cleanup(fb);
  3387. mutex_lock(&dev->struct_mutex);
  3388. drm_gem_object_unreference(intel_fb->obj);
  3389. mutex_unlock(&dev->struct_mutex);
  3390. kfree(intel_fb);
  3391. }
  3392. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  3393. struct drm_file *file_priv,
  3394. unsigned int *handle)
  3395. {
  3396. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  3397. struct drm_gem_object *object = intel_fb->obj;
  3398. return drm_gem_handle_create(file_priv, object, handle);
  3399. }
  3400. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  3401. .destroy = intel_user_framebuffer_destroy,
  3402. .create_handle = intel_user_framebuffer_create_handle,
  3403. };
  3404. int intel_framebuffer_create(struct drm_device *dev,
  3405. struct drm_mode_fb_cmd *mode_cmd,
  3406. struct drm_framebuffer **fb,
  3407. struct drm_gem_object *obj)
  3408. {
  3409. struct intel_framebuffer *intel_fb;
  3410. int ret;
  3411. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  3412. if (!intel_fb)
  3413. return -ENOMEM;
  3414. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  3415. if (ret) {
  3416. DRM_ERROR("framebuffer init failed %d\n", ret);
  3417. return ret;
  3418. }
  3419. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  3420. intel_fb->obj = obj;
  3421. *fb = &intel_fb->base;
  3422. return 0;
  3423. }
  3424. static struct drm_framebuffer *
  3425. intel_user_framebuffer_create(struct drm_device *dev,
  3426. struct drm_file *filp,
  3427. struct drm_mode_fb_cmd *mode_cmd)
  3428. {
  3429. struct drm_gem_object *obj;
  3430. struct drm_framebuffer *fb;
  3431. int ret;
  3432. obj = drm_gem_object_lookup(dev, filp, mode_cmd->handle);
  3433. if (!obj)
  3434. return NULL;
  3435. ret = intel_framebuffer_create(dev, mode_cmd, &fb, obj);
  3436. if (ret) {
  3437. mutex_lock(&dev->struct_mutex);
  3438. drm_gem_object_unreference(obj);
  3439. mutex_unlock(&dev->struct_mutex);
  3440. return NULL;
  3441. }
  3442. return fb;
  3443. }
  3444. static const struct drm_mode_config_funcs intel_mode_funcs = {
  3445. .fb_create = intel_user_framebuffer_create,
  3446. .fb_changed = intelfb_probe,
  3447. };
  3448. void intel_init_clock_gating(struct drm_device *dev)
  3449. {
  3450. struct drm_i915_private *dev_priv = dev->dev_private;
  3451. /*
  3452. * Disable clock gating reported to work incorrectly according to the
  3453. * specs, but enable as much else as we can.
  3454. */
  3455. if (IS_G4X(dev)) {
  3456. uint32_t dspclk_gate;
  3457. I915_WRITE(RENCLK_GATE_D1, 0);
  3458. I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
  3459. GS_UNIT_CLOCK_GATE_DISABLE |
  3460. CL_UNIT_CLOCK_GATE_DISABLE);
  3461. I915_WRITE(RAMCLK_GATE_D, 0);
  3462. dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
  3463. OVRUNIT_CLOCK_GATE_DISABLE |
  3464. OVCUNIT_CLOCK_GATE_DISABLE;
  3465. if (IS_GM45(dev))
  3466. dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
  3467. I915_WRITE(DSPCLK_GATE_D, dspclk_gate);
  3468. } else if (IS_I965GM(dev)) {
  3469. I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
  3470. I915_WRITE(RENCLK_GATE_D2, 0);
  3471. I915_WRITE(DSPCLK_GATE_D, 0);
  3472. I915_WRITE(RAMCLK_GATE_D, 0);
  3473. I915_WRITE16(DEUC, 0);
  3474. } else if (IS_I965G(dev)) {
  3475. I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
  3476. I965_RCC_CLOCK_GATE_DISABLE |
  3477. I965_RCPB_CLOCK_GATE_DISABLE |
  3478. I965_ISC_CLOCK_GATE_DISABLE |
  3479. I965_FBC_CLOCK_GATE_DISABLE);
  3480. I915_WRITE(RENCLK_GATE_D2, 0);
  3481. } else if (IS_I9XX(dev)) {
  3482. u32 dstate = I915_READ(D_STATE);
  3483. dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
  3484. DSTATE_DOT_CLOCK_GATING;
  3485. I915_WRITE(D_STATE, dstate);
  3486. } else if (IS_I855(dev) || IS_I865G(dev)) {
  3487. I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
  3488. } else if (IS_I830(dev)) {
  3489. I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE);
  3490. }
  3491. }
  3492. void intel_modeset_init(struct drm_device *dev)
  3493. {
  3494. struct drm_i915_private *dev_priv = dev->dev_private;
  3495. int num_pipe;
  3496. int i;
  3497. drm_mode_config_init(dev);
  3498. dev->mode_config.min_width = 0;
  3499. dev->mode_config.min_height = 0;
  3500. dev->mode_config.funcs = (void *)&intel_mode_funcs;
  3501. if (IS_I965G(dev)) {
  3502. dev->mode_config.max_width = 8192;
  3503. dev->mode_config.max_height = 8192;
  3504. } else if (IS_I9XX(dev)) {
  3505. dev->mode_config.max_width = 4096;
  3506. dev->mode_config.max_height = 4096;
  3507. } else {
  3508. dev->mode_config.max_width = 2048;
  3509. dev->mode_config.max_height = 2048;
  3510. }
  3511. /* set memory base */
  3512. if (IS_I9XX(dev))
  3513. dev->mode_config.fb_base = pci_resource_start(dev->pdev, 2);
  3514. else
  3515. dev->mode_config.fb_base = pci_resource_start(dev->pdev, 0);
  3516. if (IS_MOBILE(dev) || IS_I9XX(dev))
  3517. num_pipe = 2;
  3518. else
  3519. num_pipe = 1;
  3520. DRM_DEBUG("%d display pipe%s available.\n",
  3521. num_pipe, num_pipe > 1 ? "s" : "");
  3522. if (IS_I85X(dev))
  3523. pci_read_config_word(dev->pdev, HPLLCC, &dev_priv->orig_clock);
  3524. else if (IS_I9XX(dev) || IS_G4X(dev))
  3525. pci_read_config_word(dev->pdev, GCFGC, &dev_priv->orig_clock);
  3526. for (i = 0; i < num_pipe; i++) {
  3527. intel_crtc_init(dev, i);
  3528. }
  3529. intel_setup_outputs(dev);
  3530. intel_init_clock_gating(dev);
  3531. INIT_WORK(&dev_priv->idle_work, intel_idle_update);
  3532. setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer,
  3533. (unsigned long)dev);
  3534. }
  3535. void intel_modeset_cleanup(struct drm_device *dev)
  3536. {
  3537. struct drm_i915_private *dev_priv = dev->dev_private;
  3538. struct drm_crtc *crtc;
  3539. struct intel_crtc *intel_crtc;
  3540. mutex_lock(&dev->struct_mutex);
  3541. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3542. /* Skip inactive CRTCs */
  3543. if (!crtc->fb)
  3544. continue;
  3545. intel_crtc = to_intel_crtc(crtc);
  3546. intel_increase_pllclock(crtc, false);
  3547. del_timer_sync(&intel_crtc->idle_timer);
  3548. }
  3549. intel_increase_renderclock(dev, false);
  3550. del_timer_sync(&dev_priv->idle_timer);
  3551. mutex_unlock(&dev->struct_mutex);
  3552. i8xx_disable_fbc(dev);
  3553. drm_mode_config_cleanup(dev);
  3554. }
  3555. /* current intel driver doesn't take advantage of encoders
  3556. always give back the encoder for the connector
  3557. */
  3558. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  3559. {
  3560. struct intel_output *intel_output = to_intel_output(connector);
  3561. return &intel_output->enc;
  3562. }