intel_display.c 145 KB

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