intel_display.c 144 KB

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