intel_display.c 156 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417
  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_encoder *l_entry;
  691. list_for_each_entry(l_entry, &mode_config->encoder_list, head) {
  692. if (l_entry && l_entry->crtc == crtc) {
  693. struct intel_encoder *intel_encoder = enc_to_intel_encoder(l_entry);
  694. if (intel_encoder->type == type)
  695. return true;
  696. }
  697. }
  698. return false;
  699. }
  700. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  701. /**
  702. * Returns whether the given set of divisors are valid for a given refclk with
  703. * the given connectors.
  704. */
  705. static bool intel_PLL_is_valid(struct drm_crtc *crtc, intel_clock_t *clock)
  706. {
  707. const intel_limit_t *limit = intel_limit (crtc);
  708. struct drm_device *dev = crtc->dev;
  709. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  710. INTELPllInvalid ("p1 out of range\n");
  711. if (clock->p < limit->p.min || limit->p.max < clock->p)
  712. INTELPllInvalid ("p out of range\n");
  713. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  714. INTELPllInvalid ("m2 out of range\n");
  715. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  716. INTELPllInvalid ("m1 out of range\n");
  717. if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev))
  718. INTELPllInvalid ("m1 <= m2\n");
  719. if (clock->m < limit->m.min || limit->m.max < clock->m)
  720. INTELPllInvalid ("m out of range\n");
  721. if (clock->n < limit->n.min || limit->n.max < clock->n)
  722. INTELPllInvalid ("n out of range\n");
  723. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  724. INTELPllInvalid ("vco out of range\n");
  725. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  726. * connector, etc., rather than just a single range.
  727. */
  728. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  729. INTELPllInvalid ("dot out of range\n");
  730. return true;
  731. }
  732. static bool
  733. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  734. int target, int refclk, intel_clock_t *best_clock)
  735. {
  736. struct drm_device *dev = crtc->dev;
  737. struct drm_i915_private *dev_priv = dev->dev_private;
  738. intel_clock_t clock;
  739. int err = target;
  740. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  741. (I915_READ(LVDS)) != 0) {
  742. /*
  743. * For LVDS, if the panel is on, just rely on its current
  744. * settings for dual-channel. We haven't figured out how to
  745. * reliably set up different single/dual channel state, if we
  746. * even can.
  747. */
  748. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  749. LVDS_CLKB_POWER_UP)
  750. clock.p2 = limit->p2.p2_fast;
  751. else
  752. clock.p2 = limit->p2.p2_slow;
  753. } else {
  754. if (target < limit->p2.dot_limit)
  755. clock.p2 = limit->p2.p2_slow;
  756. else
  757. clock.p2 = limit->p2.p2_fast;
  758. }
  759. memset (best_clock, 0, sizeof (*best_clock));
  760. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  761. clock.m1++) {
  762. for (clock.m2 = limit->m2.min;
  763. clock.m2 <= limit->m2.max; clock.m2++) {
  764. /* m1 is always 0 in Pineview */
  765. if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev))
  766. break;
  767. for (clock.n = limit->n.min;
  768. clock.n <= limit->n.max; clock.n++) {
  769. for (clock.p1 = limit->p1.min;
  770. clock.p1 <= limit->p1.max; clock.p1++) {
  771. int this_err;
  772. intel_clock(dev, refclk, &clock);
  773. if (!intel_PLL_is_valid(crtc, &clock))
  774. continue;
  775. this_err = abs(clock.dot - target);
  776. if (this_err < err) {
  777. *best_clock = clock;
  778. err = this_err;
  779. }
  780. }
  781. }
  782. }
  783. }
  784. return (err != target);
  785. }
  786. static bool
  787. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  788. int target, int refclk, intel_clock_t *best_clock)
  789. {
  790. struct drm_device *dev = crtc->dev;
  791. struct drm_i915_private *dev_priv = dev->dev_private;
  792. intel_clock_t clock;
  793. int max_n;
  794. bool found;
  795. /* approximately equals target * 0.00488 */
  796. int err_most = (target >> 8) + (target >> 10);
  797. found = false;
  798. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  799. int lvds_reg;
  800. if (HAS_PCH_SPLIT(dev))
  801. lvds_reg = PCH_LVDS;
  802. else
  803. lvds_reg = LVDS;
  804. if ((I915_READ(lvds_reg) & LVDS_CLKB_POWER_MASK) ==
  805. LVDS_CLKB_POWER_UP)
  806. clock.p2 = limit->p2.p2_fast;
  807. else
  808. clock.p2 = limit->p2.p2_slow;
  809. } else {
  810. if (target < limit->p2.dot_limit)
  811. clock.p2 = limit->p2.p2_slow;
  812. else
  813. clock.p2 = limit->p2.p2_fast;
  814. }
  815. memset(best_clock, 0, sizeof(*best_clock));
  816. max_n = limit->n.max;
  817. /* based on hardware requriment prefer smaller n to precision */
  818. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  819. /* based on hardware requirment prefere larger m1,m2 */
  820. for (clock.m1 = limit->m1.max;
  821. clock.m1 >= limit->m1.min; clock.m1--) {
  822. for (clock.m2 = limit->m2.max;
  823. clock.m2 >= limit->m2.min; clock.m2--) {
  824. for (clock.p1 = limit->p1.max;
  825. clock.p1 >= limit->p1.min; clock.p1--) {
  826. int this_err;
  827. intel_clock(dev, refclk, &clock);
  828. if (!intel_PLL_is_valid(crtc, &clock))
  829. continue;
  830. this_err = abs(clock.dot - target) ;
  831. if (this_err < err_most) {
  832. *best_clock = clock;
  833. err_most = this_err;
  834. max_n = clock.n;
  835. found = true;
  836. }
  837. }
  838. }
  839. }
  840. }
  841. return found;
  842. }
  843. static bool
  844. intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  845. int target, int refclk, intel_clock_t *best_clock)
  846. {
  847. struct drm_device *dev = crtc->dev;
  848. intel_clock_t clock;
  849. /* return directly when it is eDP */
  850. if (HAS_eDP)
  851. return true;
  852. if (target < 200000) {
  853. clock.n = 1;
  854. clock.p1 = 2;
  855. clock.p2 = 10;
  856. clock.m1 = 12;
  857. clock.m2 = 9;
  858. } else {
  859. clock.n = 2;
  860. clock.p1 = 1;
  861. clock.p2 = 10;
  862. clock.m1 = 14;
  863. clock.m2 = 8;
  864. }
  865. intel_clock(dev, refclk, &clock);
  866. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  867. return true;
  868. }
  869. /* DisplayPort has only two frequencies, 162MHz and 270MHz */
  870. static bool
  871. intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  872. int target, int refclk, intel_clock_t *best_clock)
  873. {
  874. intel_clock_t clock;
  875. if (target < 200000) {
  876. clock.p1 = 2;
  877. clock.p2 = 10;
  878. clock.n = 2;
  879. clock.m1 = 23;
  880. clock.m2 = 8;
  881. } else {
  882. clock.p1 = 1;
  883. clock.p2 = 10;
  884. clock.n = 1;
  885. clock.m1 = 14;
  886. clock.m2 = 2;
  887. }
  888. clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
  889. clock.p = (clock.p1 * clock.p2);
  890. clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
  891. clock.vco = 0;
  892. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  893. return true;
  894. }
  895. void
  896. intel_wait_for_vblank(struct drm_device *dev)
  897. {
  898. /* Wait for 20ms, i.e. one cycle at 50hz. */
  899. msleep(20);
  900. }
  901. /* Parameters have changed, update FBC info */
  902. static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  903. {
  904. struct drm_device *dev = crtc->dev;
  905. struct drm_i915_private *dev_priv = dev->dev_private;
  906. struct drm_framebuffer *fb = crtc->fb;
  907. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  908. struct drm_i915_gem_object *obj_priv = to_intel_bo(intel_fb->obj);
  909. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  910. int plane, i;
  911. u32 fbc_ctl, fbc_ctl2;
  912. dev_priv->cfb_pitch = dev_priv->cfb_size / FBC_LL_SIZE;
  913. if (fb->pitch < dev_priv->cfb_pitch)
  914. dev_priv->cfb_pitch = fb->pitch;
  915. /* FBC_CTL wants 64B units */
  916. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  917. dev_priv->cfb_fence = obj_priv->fence_reg;
  918. dev_priv->cfb_plane = intel_crtc->plane;
  919. plane = dev_priv->cfb_plane == 0 ? FBC_CTL_PLANEA : FBC_CTL_PLANEB;
  920. /* Clear old tags */
  921. for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++)
  922. I915_WRITE(FBC_TAG + (i * 4), 0);
  923. /* Set it up... */
  924. fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | plane;
  925. if (obj_priv->tiling_mode != I915_TILING_NONE)
  926. fbc_ctl2 |= FBC_CTL_CPU_FENCE;
  927. I915_WRITE(FBC_CONTROL2, fbc_ctl2);
  928. I915_WRITE(FBC_FENCE_OFF, crtc->y);
  929. /* enable it... */
  930. fbc_ctl = FBC_CTL_EN | FBC_CTL_PERIODIC;
  931. if (IS_I945GM(dev))
  932. fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */
  933. fbc_ctl |= (dev_priv->cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT;
  934. fbc_ctl |= (interval & 0x2fff) << FBC_CTL_INTERVAL_SHIFT;
  935. if (obj_priv->tiling_mode != I915_TILING_NONE)
  936. fbc_ctl |= dev_priv->cfb_fence;
  937. I915_WRITE(FBC_CONTROL, fbc_ctl);
  938. DRM_DEBUG_KMS("enabled FBC, pitch %ld, yoff %d, plane %d, ",
  939. dev_priv->cfb_pitch, crtc->y, dev_priv->cfb_plane);
  940. }
  941. void i8xx_disable_fbc(struct drm_device *dev)
  942. {
  943. struct drm_i915_private *dev_priv = dev->dev_private;
  944. u32 fbc_ctl;
  945. if (!I915_HAS_FBC(dev))
  946. return;
  947. /* Disable compression */
  948. fbc_ctl = I915_READ(FBC_CONTROL);
  949. fbc_ctl &= ~FBC_CTL_EN;
  950. I915_WRITE(FBC_CONTROL, fbc_ctl);
  951. /* Wait for compressing bit to clear */
  952. while (I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING)
  953. ; /* nothing */
  954. intel_wait_for_vblank(dev);
  955. DRM_DEBUG_KMS("disabled FBC\n");
  956. }
  957. static bool i8xx_fbc_enabled(struct drm_crtc *crtc)
  958. {
  959. struct drm_device *dev = crtc->dev;
  960. struct drm_i915_private *dev_priv = dev->dev_private;
  961. return I915_READ(FBC_CONTROL) & FBC_CTL_EN;
  962. }
  963. static void g4x_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  964. {
  965. struct drm_device *dev = crtc->dev;
  966. struct drm_i915_private *dev_priv = dev->dev_private;
  967. struct drm_framebuffer *fb = crtc->fb;
  968. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  969. struct drm_i915_gem_object *obj_priv = to_intel_bo(intel_fb->obj);
  970. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  971. int plane = (intel_crtc->plane == 0 ? DPFC_CTL_PLANEA :
  972. DPFC_CTL_PLANEB);
  973. unsigned long stall_watermark = 200;
  974. u32 dpfc_ctl;
  975. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  976. dev_priv->cfb_fence = obj_priv->fence_reg;
  977. dev_priv->cfb_plane = intel_crtc->plane;
  978. dpfc_ctl = plane | DPFC_SR_EN | DPFC_CTL_LIMIT_1X;
  979. if (obj_priv->tiling_mode != I915_TILING_NONE) {
  980. dpfc_ctl |= DPFC_CTL_FENCE_EN | dev_priv->cfb_fence;
  981. I915_WRITE(DPFC_CHICKEN, DPFC_HT_MODIFY);
  982. } else {
  983. I915_WRITE(DPFC_CHICKEN, ~DPFC_HT_MODIFY);
  984. }
  985. I915_WRITE(DPFC_CONTROL, dpfc_ctl);
  986. I915_WRITE(DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN |
  987. (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) |
  988. (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT));
  989. I915_WRITE(DPFC_FENCE_YOFF, crtc->y);
  990. /* enable it... */
  991. I915_WRITE(DPFC_CONTROL, I915_READ(DPFC_CONTROL) | DPFC_CTL_EN);
  992. DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane);
  993. }
  994. void g4x_disable_fbc(struct drm_device *dev)
  995. {
  996. struct drm_i915_private *dev_priv = dev->dev_private;
  997. u32 dpfc_ctl;
  998. /* Disable compression */
  999. dpfc_ctl = I915_READ(DPFC_CONTROL);
  1000. dpfc_ctl &= ~DPFC_CTL_EN;
  1001. I915_WRITE(DPFC_CONTROL, dpfc_ctl);
  1002. intel_wait_for_vblank(dev);
  1003. DRM_DEBUG_KMS("disabled FBC\n");
  1004. }
  1005. static bool g4x_fbc_enabled(struct drm_crtc *crtc)
  1006. {
  1007. struct drm_device *dev = crtc->dev;
  1008. struct drm_i915_private *dev_priv = dev->dev_private;
  1009. return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN;
  1010. }
  1011. /**
  1012. * intel_update_fbc - enable/disable FBC as needed
  1013. * @crtc: CRTC to point the compressor at
  1014. * @mode: mode in use
  1015. *
  1016. * Set up the framebuffer compression hardware at mode set time. We
  1017. * enable it if possible:
  1018. * - plane A only (on pre-965)
  1019. * - no pixel mulitply/line duplication
  1020. * - no alpha buffer discard
  1021. * - no dual wide
  1022. * - framebuffer <= 2048 in width, 1536 in height
  1023. *
  1024. * We can't assume that any compression will take place (worst case),
  1025. * so the compressed buffer has to be the same size as the uncompressed
  1026. * one. It also must reside (along with the line length buffer) in
  1027. * stolen memory.
  1028. *
  1029. * We need to enable/disable FBC on a global basis.
  1030. */
  1031. static void intel_update_fbc(struct drm_crtc *crtc,
  1032. struct drm_display_mode *mode)
  1033. {
  1034. struct drm_device *dev = crtc->dev;
  1035. struct drm_i915_private *dev_priv = dev->dev_private;
  1036. struct drm_framebuffer *fb = crtc->fb;
  1037. struct intel_framebuffer *intel_fb;
  1038. struct drm_i915_gem_object *obj_priv;
  1039. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1040. int plane = intel_crtc->plane;
  1041. if (!i915_powersave)
  1042. return;
  1043. if (!dev_priv->display.fbc_enabled ||
  1044. !dev_priv->display.enable_fbc ||
  1045. !dev_priv->display.disable_fbc)
  1046. return;
  1047. if (!crtc->fb)
  1048. return;
  1049. intel_fb = to_intel_framebuffer(fb);
  1050. obj_priv = to_intel_bo(intel_fb->obj);
  1051. /*
  1052. * If FBC is already on, we just have to verify that we can
  1053. * keep it that way...
  1054. * Need to disable if:
  1055. * - changing FBC params (stride, fence, mode)
  1056. * - new fb is too large to fit in compressed buffer
  1057. * - going to an unsupported config (interlace, pixel multiply, etc.)
  1058. */
  1059. if (intel_fb->obj->size > dev_priv->cfb_size) {
  1060. DRM_DEBUG_KMS("framebuffer too large, disabling "
  1061. "compression\n");
  1062. dev_priv->no_fbc_reason = FBC_STOLEN_TOO_SMALL;
  1063. goto out_disable;
  1064. }
  1065. if ((mode->flags & DRM_MODE_FLAG_INTERLACE) ||
  1066. (mode->flags & DRM_MODE_FLAG_DBLSCAN)) {
  1067. DRM_DEBUG_KMS("mode incompatible with compression, "
  1068. "disabling\n");
  1069. dev_priv->no_fbc_reason = FBC_UNSUPPORTED_MODE;
  1070. goto out_disable;
  1071. }
  1072. if ((mode->hdisplay > 2048) ||
  1073. (mode->vdisplay > 1536)) {
  1074. DRM_DEBUG_KMS("mode too large for compression, disabling\n");
  1075. dev_priv->no_fbc_reason = FBC_MODE_TOO_LARGE;
  1076. goto out_disable;
  1077. }
  1078. if ((IS_I915GM(dev) || IS_I945GM(dev)) && plane != 0) {
  1079. DRM_DEBUG_KMS("plane not 0, disabling compression\n");
  1080. dev_priv->no_fbc_reason = FBC_BAD_PLANE;
  1081. goto out_disable;
  1082. }
  1083. if (obj_priv->tiling_mode != I915_TILING_X) {
  1084. DRM_DEBUG_KMS("framebuffer not tiled, disabling compression\n");
  1085. dev_priv->no_fbc_reason = FBC_NOT_TILED;
  1086. goto out_disable;
  1087. }
  1088. if (dev_priv->display.fbc_enabled(crtc)) {
  1089. /* We can re-enable it in this case, but need to update pitch */
  1090. if (fb->pitch > dev_priv->cfb_pitch)
  1091. dev_priv->display.disable_fbc(dev);
  1092. if (obj_priv->fence_reg != dev_priv->cfb_fence)
  1093. dev_priv->display.disable_fbc(dev);
  1094. if (plane != dev_priv->cfb_plane)
  1095. dev_priv->display.disable_fbc(dev);
  1096. }
  1097. if (!dev_priv->display.fbc_enabled(crtc)) {
  1098. /* Now try to turn it back on if possible */
  1099. dev_priv->display.enable_fbc(crtc, 500);
  1100. }
  1101. return;
  1102. out_disable:
  1103. DRM_DEBUG_KMS("unsupported config, disabling FBC\n");
  1104. /* Multiple disables should be harmless */
  1105. if (dev_priv->display.fbc_enabled(crtc))
  1106. dev_priv->display.disable_fbc(dev);
  1107. }
  1108. static int
  1109. intel_pin_and_fence_fb_obj(struct drm_device *dev, struct drm_gem_object *obj)
  1110. {
  1111. struct drm_i915_gem_object *obj_priv = to_intel_bo(obj);
  1112. u32 alignment;
  1113. int ret;
  1114. switch (obj_priv->tiling_mode) {
  1115. case I915_TILING_NONE:
  1116. alignment = 64 * 1024;
  1117. break;
  1118. case I915_TILING_X:
  1119. /* pin() will align the object as required by fence */
  1120. alignment = 0;
  1121. break;
  1122. case I915_TILING_Y:
  1123. /* FIXME: Is this true? */
  1124. DRM_ERROR("Y tiled not allowed for scan out buffers\n");
  1125. return -EINVAL;
  1126. default:
  1127. BUG();
  1128. }
  1129. ret = i915_gem_object_pin(obj, alignment);
  1130. if (ret != 0)
  1131. return ret;
  1132. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1133. * fence, whereas 965+ only requires a fence if using
  1134. * framebuffer compression. For simplicity, we always install
  1135. * a fence as the cost is not that onerous.
  1136. */
  1137. if (obj_priv->fence_reg == I915_FENCE_REG_NONE &&
  1138. obj_priv->tiling_mode != I915_TILING_NONE) {
  1139. ret = i915_gem_object_get_fence_reg(obj);
  1140. if (ret != 0) {
  1141. i915_gem_object_unpin(obj);
  1142. return ret;
  1143. }
  1144. }
  1145. return 0;
  1146. }
  1147. static int
  1148. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  1149. struct drm_framebuffer *old_fb)
  1150. {
  1151. struct drm_device *dev = crtc->dev;
  1152. struct drm_i915_private *dev_priv = dev->dev_private;
  1153. struct drm_i915_master_private *master_priv;
  1154. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1155. struct intel_framebuffer *intel_fb;
  1156. struct drm_i915_gem_object *obj_priv;
  1157. struct drm_gem_object *obj;
  1158. int pipe = intel_crtc->pipe;
  1159. int plane = intel_crtc->plane;
  1160. unsigned long Start, Offset;
  1161. int dspbase = (plane == 0 ? DSPAADDR : DSPBADDR);
  1162. int dspsurf = (plane == 0 ? DSPASURF : DSPBSURF);
  1163. int dspstride = (plane == 0) ? DSPASTRIDE : DSPBSTRIDE;
  1164. int dsptileoff = (plane == 0 ? DSPATILEOFF : DSPBTILEOFF);
  1165. int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR;
  1166. u32 dspcntr;
  1167. int ret;
  1168. /* no fb bound */
  1169. if (!crtc->fb) {
  1170. DRM_DEBUG_KMS("No FB bound\n");
  1171. return 0;
  1172. }
  1173. switch (plane) {
  1174. case 0:
  1175. case 1:
  1176. break;
  1177. default:
  1178. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1179. return -EINVAL;
  1180. }
  1181. intel_fb = to_intel_framebuffer(crtc->fb);
  1182. obj = intel_fb->obj;
  1183. obj_priv = to_intel_bo(obj);
  1184. mutex_lock(&dev->struct_mutex);
  1185. ret = intel_pin_and_fence_fb_obj(dev, obj);
  1186. if (ret != 0) {
  1187. mutex_unlock(&dev->struct_mutex);
  1188. return ret;
  1189. }
  1190. ret = i915_gem_object_set_to_display_plane(obj);
  1191. if (ret != 0) {
  1192. i915_gem_object_unpin(obj);
  1193. mutex_unlock(&dev->struct_mutex);
  1194. return ret;
  1195. }
  1196. dspcntr = I915_READ(dspcntr_reg);
  1197. /* Mask out pixel format bits in case we change it */
  1198. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1199. switch (crtc->fb->bits_per_pixel) {
  1200. case 8:
  1201. dspcntr |= DISPPLANE_8BPP;
  1202. break;
  1203. case 16:
  1204. if (crtc->fb->depth == 15)
  1205. dspcntr |= DISPPLANE_15_16BPP;
  1206. else
  1207. dspcntr |= DISPPLANE_16BPP;
  1208. break;
  1209. case 24:
  1210. case 32:
  1211. if (crtc->fb->depth == 30)
  1212. dspcntr |= DISPPLANE_32BPP_30BIT_NO_ALPHA;
  1213. else
  1214. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  1215. break;
  1216. default:
  1217. DRM_ERROR("Unknown color depth\n");
  1218. i915_gem_object_unpin(obj);
  1219. mutex_unlock(&dev->struct_mutex);
  1220. return -EINVAL;
  1221. }
  1222. if (IS_I965G(dev)) {
  1223. if (obj_priv->tiling_mode != I915_TILING_NONE)
  1224. dspcntr |= DISPPLANE_TILED;
  1225. else
  1226. dspcntr &= ~DISPPLANE_TILED;
  1227. }
  1228. if (HAS_PCH_SPLIT(dev))
  1229. /* must disable */
  1230. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  1231. I915_WRITE(dspcntr_reg, dspcntr);
  1232. Start = obj_priv->gtt_offset;
  1233. Offset = y * crtc->fb->pitch + x * (crtc->fb->bits_per_pixel / 8);
  1234. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d\n", Start, Offset, x, y);
  1235. I915_WRITE(dspstride, crtc->fb->pitch);
  1236. if (IS_I965G(dev)) {
  1237. I915_WRITE(dspbase, Offset);
  1238. I915_READ(dspbase);
  1239. I915_WRITE(dspsurf, Start);
  1240. I915_READ(dspsurf);
  1241. I915_WRITE(dsptileoff, (y << 16) | x);
  1242. } else {
  1243. I915_WRITE(dspbase, Start + Offset);
  1244. I915_READ(dspbase);
  1245. }
  1246. if ((IS_I965G(dev) || plane == 0))
  1247. intel_update_fbc(crtc, &crtc->mode);
  1248. intel_wait_for_vblank(dev);
  1249. if (old_fb) {
  1250. intel_fb = to_intel_framebuffer(old_fb);
  1251. obj_priv = to_intel_bo(intel_fb->obj);
  1252. i915_gem_object_unpin(intel_fb->obj);
  1253. }
  1254. intel_increase_pllclock(crtc, true);
  1255. mutex_unlock(&dev->struct_mutex);
  1256. if (!dev->primary->master)
  1257. return 0;
  1258. master_priv = dev->primary->master->driver_priv;
  1259. if (!master_priv->sarea_priv)
  1260. return 0;
  1261. if (pipe) {
  1262. master_priv->sarea_priv->pipeB_x = x;
  1263. master_priv->sarea_priv->pipeB_y = y;
  1264. } else {
  1265. master_priv->sarea_priv->pipeA_x = x;
  1266. master_priv->sarea_priv->pipeA_y = y;
  1267. }
  1268. return 0;
  1269. }
  1270. /* Disable the VGA plane that we never use */
  1271. static void i915_disable_vga (struct drm_device *dev)
  1272. {
  1273. struct drm_i915_private *dev_priv = dev->dev_private;
  1274. u8 sr1;
  1275. u32 vga_reg;
  1276. if (HAS_PCH_SPLIT(dev))
  1277. vga_reg = CPU_VGACNTRL;
  1278. else
  1279. vga_reg = VGACNTRL;
  1280. if (I915_READ(vga_reg) & VGA_DISP_DISABLE)
  1281. return;
  1282. I915_WRITE8(VGA_SR_INDEX, 1);
  1283. sr1 = I915_READ8(VGA_SR_DATA);
  1284. I915_WRITE8(VGA_SR_DATA, sr1 | (1 << 5));
  1285. udelay(100);
  1286. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  1287. }
  1288. static void ironlake_disable_pll_edp (struct drm_crtc *crtc)
  1289. {
  1290. struct drm_device *dev = crtc->dev;
  1291. struct drm_i915_private *dev_priv = dev->dev_private;
  1292. u32 dpa_ctl;
  1293. DRM_DEBUG_KMS("\n");
  1294. dpa_ctl = I915_READ(DP_A);
  1295. dpa_ctl &= ~DP_PLL_ENABLE;
  1296. I915_WRITE(DP_A, dpa_ctl);
  1297. }
  1298. static void ironlake_enable_pll_edp (struct drm_crtc *crtc)
  1299. {
  1300. struct drm_device *dev = crtc->dev;
  1301. struct drm_i915_private *dev_priv = dev->dev_private;
  1302. u32 dpa_ctl;
  1303. dpa_ctl = I915_READ(DP_A);
  1304. dpa_ctl |= DP_PLL_ENABLE;
  1305. I915_WRITE(DP_A, dpa_ctl);
  1306. udelay(200);
  1307. }
  1308. static void ironlake_set_pll_edp (struct drm_crtc *crtc, int clock)
  1309. {
  1310. struct drm_device *dev = crtc->dev;
  1311. struct drm_i915_private *dev_priv = dev->dev_private;
  1312. u32 dpa_ctl;
  1313. DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", clock);
  1314. dpa_ctl = I915_READ(DP_A);
  1315. dpa_ctl &= ~DP_PLL_FREQ_MASK;
  1316. if (clock < 200000) {
  1317. u32 temp;
  1318. dpa_ctl |= DP_PLL_FREQ_160MHZ;
  1319. /* workaround for 160Mhz:
  1320. 1) program 0x4600c bits 15:0 = 0x8124
  1321. 2) program 0x46010 bit 0 = 1
  1322. 3) program 0x46034 bit 24 = 1
  1323. 4) program 0x64000 bit 14 = 1
  1324. */
  1325. temp = I915_READ(0x4600c);
  1326. temp &= 0xffff0000;
  1327. I915_WRITE(0x4600c, temp | 0x8124);
  1328. temp = I915_READ(0x46010);
  1329. I915_WRITE(0x46010, temp | 1);
  1330. temp = I915_READ(0x46034);
  1331. I915_WRITE(0x46034, temp | (1 << 24));
  1332. } else {
  1333. dpa_ctl |= DP_PLL_FREQ_270MHZ;
  1334. }
  1335. I915_WRITE(DP_A, dpa_ctl);
  1336. udelay(500);
  1337. }
  1338. /* The FDI link training functions for ILK/Ibexpeak. */
  1339. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  1340. {
  1341. struct drm_device *dev = crtc->dev;
  1342. struct drm_i915_private *dev_priv = dev->dev_private;
  1343. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1344. int pipe = intel_crtc->pipe;
  1345. int fdi_tx_reg = (pipe == 0) ? FDI_TXA_CTL : FDI_TXB_CTL;
  1346. int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL;
  1347. int fdi_rx_iir_reg = (pipe == 0) ? FDI_RXA_IIR : FDI_RXB_IIR;
  1348. int fdi_rx_imr_reg = (pipe == 0) ? FDI_RXA_IMR : FDI_RXB_IMR;
  1349. u32 temp, tries = 0;
  1350. /* enable CPU FDI TX and PCH FDI RX */
  1351. temp = I915_READ(fdi_tx_reg);
  1352. temp |= FDI_TX_ENABLE;
  1353. temp |= FDI_DP_PORT_WIDTH_X4; /* default */
  1354. temp &= ~FDI_LINK_TRAIN_NONE;
  1355. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1356. I915_WRITE(fdi_tx_reg, temp);
  1357. I915_READ(fdi_tx_reg);
  1358. temp = I915_READ(fdi_rx_reg);
  1359. temp &= ~FDI_LINK_TRAIN_NONE;
  1360. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1361. I915_WRITE(fdi_rx_reg, temp | FDI_RX_ENABLE);
  1362. I915_READ(fdi_rx_reg);
  1363. udelay(150);
  1364. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  1365. for train result */
  1366. temp = I915_READ(fdi_rx_imr_reg);
  1367. temp &= ~FDI_RX_SYMBOL_LOCK;
  1368. temp &= ~FDI_RX_BIT_LOCK;
  1369. I915_WRITE(fdi_rx_imr_reg, temp);
  1370. I915_READ(fdi_rx_imr_reg);
  1371. udelay(150);
  1372. for (;;) {
  1373. temp = I915_READ(fdi_rx_iir_reg);
  1374. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  1375. if ((temp & FDI_RX_BIT_LOCK)) {
  1376. DRM_DEBUG_KMS("FDI train 1 done.\n");
  1377. I915_WRITE(fdi_rx_iir_reg,
  1378. temp | FDI_RX_BIT_LOCK);
  1379. break;
  1380. }
  1381. tries++;
  1382. if (tries > 5) {
  1383. DRM_DEBUG_KMS("FDI train 1 fail!\n");
  1384. break;
  1385. }
  1386. }
  1387. /* Train 2 */
  1388. temp = I915_READ(fdi_tx_reg);
  1389. temp &= ~FDI_LINK_TRAIN_NONE;
  1390. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1391. I915_WRITE(fdi_tx_reg, temp);
  1392. temp = I915_READ(fdi_rx_reg);
  1393. temp &= ~FDI_LINK_TRAIN_NONE;
  1394. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1395. I915_WRITE(fdi_rx_reg, temp);
  1396. udelay(150);
  1397. tries = 0;
  1398. for (;;) {
  1399. temp = I915_READ(fdi_rx_iir_reg);
  1400. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  1401. if (temp & FDI_RX_SYMBOL_LOCK) {
  1402. I915_WRITE(fdi_rx_iir_reg,
  1403. temp | FDI_RX_SYMBOL_LOCK);
  1404. DRM_DEBUG_KMS("FDI train 2 done.\n");
  1405. break;
  1406. }
  1407. tries++;
  1408. if (tries > 5) {
  1409. DRM_DEBUG_KMS("FDI train 2 fail!\n");
  1410. break;
  1411. }
  1412. }
  1413. DRM_DEBUG_KMS("FDI train done\n");
  1414. }
  1415. static int snb_b_fdi_train_param [] = {
  1416. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  1417. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  1418. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  1419. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  1420. };
  1421. /* The FDI link training functions for SNB/Cougarpoint. */
  1422. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  1423. {
  1424. struct drm_device *dev = crtc->dev;
  1425. struct drm_i915_private *dev_priv = dev->dev_private;
  1426. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1427. int pipe = intel_crtc->pipe;
  1428. int fdi_tx_reg = (pipe == 0) ? FDI_TXA_CTL : FDI_TXB_CTL;
  1429. int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL;
  1430. int fdi_rx_iir_reg = (pipe == 0) ? FDI_RXA_IIR : FDI_RXB_IIR;
  1431. int fdi_rx_imr_reg = (pipe == 0) ? FDI_RXA_IMR : FDI_RXB_IMR;
  1432. u32 temp, i;
  1433. /* enable CPU FDI TX and PCH FDI RX */
  1434. temp = I915_READ(fdi_tx_reg);
  1435. temp |= FDI_TX_ENABLE;
  1436. temp |= FDI_DP_PORT_WIDTH_X4; /* default */
  1437. temp &= ~FDI_LINK_TRAIN_NONE;
  1438. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1439. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  1440. /* SNB-B */
  1441. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  1442. I915_WRITE(fdi_tx_reg, temp);
  1443. I915_READ(fdi_tx_reg);
  1444. temp = I915_READ(fdi_rx_reg);
  1445. if (HAS_PCH_CPT(dev)) {
  1446. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  1447. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  1448. } else {
  1449. temp &= ~FDI_LINK_TRAIN_NONE;
  1450. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1451. }
  1452. I915_WRITE(fdi_rx_reg, temp | FDI_RX_ENABLE);
  1453. I915_READ(fdi_rx_reg);
  1454. udelay(150);
  1455. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  1456. for train result */
  1457. temp = I915_READ(fdi_rx_imr_reg);
  1458. temp &= ~FDI_RX_SYMBOL_LOCK;
  1459. temp &= ~FDI_RX_BIT_LOCK;
  1460. I915_WRITE(fdi_rx_imr_reg, temp);
  1461. I915_READ(fdi_rx_imr_reg);
  1462. udelay(150);
  1463. for (i = 0; i < 4; i++ ) {
  1464. temp = I915_READ(fdi_tx_reg);
  1465. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  1466. temp |= snb_b_fdi_train_param[i];
  1467. I915_WRITE(fdi_tx_reg, temp);
  1468. udelay(500);
  1469. temp = I915_READ(fdi_rx_iir_reg);
  1470. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  1471. if (temp & FDI_RX_BIT_LOCK) {
  1472. I915_WRITE(fdi_rx_iir_reg,
  1473. temp | FDI_RX_BIT_LOCK);
  1474. DRM_DEBUG_KMS("FDI train 1 done.\n");
  1475. break;
  1476. }
  1477. }
  1478. if (i == 4)
  1479. DRM_DEBUG_KMS("FDI train 1 fail!\n");
  1480. /* Train 2 */
  1481. temp = I915_READ(fdi_tx_reg);
  1482. temp &= ~FDI_LINK_TRAIN_NONE;
  1483. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1484. if (IS_GEN6(dev)) {
  1485. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  1486. /* SNB-B */
  1487. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  1488. }
  1489. I915_WRITE(fdi_tx_reg, temp);
  1490. temp = I915_READ(fdi_rx_reg);
  1491. if (HAS_PCH_CPT(dev)) {
  1492. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  1493. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  1494. } else {
  1495. temp &= ~FDI_LINK_TRAIN_NONE;
  1496. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1497. }
  1498. I915_WRITE(fdi_rx_reg, temp);
  1499. udelay(150);
  1500. for (i = 0; i < 4; i++ ) {
  1501. temp = I915_READ(fdi_tx_reg);
  1502. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  1503. temp |= snb_b_fdi_train_param[i];
  1504. I915_WRITE(fdi_tx_reg, temp);
  1505. udelay(500);
  1506. temp = I915_READ(fdi_rx_iir_reg);
  1507. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  1508. if (temp & FDI_RX_SYMBOL_LOCK) {
  1509. I915_WRITE(fdi_rx_iir_reg,
  1510. temp | FDI_RX_SYMBOL_LOCK);
  1511. DRM_DEBUG_KMS("FDI train 2 done.\n");
  1512. break;
  1513. }
  1514. }
  1515. if (i == 4)
  1516. DRM_DEBUG_KMS("FDI train 2 fail!\n");
  1517. DRM_DEBUG_KMS("FDI train done.\n");
  1518. }
  1519. static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode)
  1520. {
  1521. struct drm_device *dev = crtc->dev;
  1522. struct drm_i915_private *dev_priv = dev->dev_private;
  1523. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1524. int pipe = intel_crtc->pipe;
  1525. int plane = intel_crtc->plane;
  1526. int pch_dpll_reg = (pipe == 0) ? PCH_DPLL_A : PCH_DPLL_B;
  1527. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  1528. int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR;
  1529. int dspbase_reg = (plane == 0) ? DSPAADDR : DSPBADDR;
  1530. int fdi_tx_reg = (pipe == 0) ? FDI_TXA_CTL : FDI_TXB_CTL;
  1531. int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL;
  1532. int transconf_reg = (pipe == 0) ? TRANSACONF : TRANSBCONF;
  1533. int pf_ctl_reg = (pipe == 0) ? PFA_CTL_1 : PFB_CTL_1;
  1534. int pf_win_size = (pipe == 0) ? PFA_WIN_SZ : PFB_WIN_SZ;
  1535. int pf_win_pos = (pipe == 0) ? PFA_WIN_POS : PFB_WIN_POS;
  1536. int cpu_htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
  1537. int cpu_hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
  1538. int cpu_hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
  1539. int cpu_vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
  1540. int cpu_vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
  1541. int cpu_vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
  1542. int trans_htot_reg = (pipe == 0) ? TRANS_HTOTAL_A : TRANS_HTOTAL_B;
  1543. int trans_hblank_reg = (pipe == 0) ? TRANS_HBLANK_A : TRANS_HBLANK_B;
  1544. int trans_hsync_reg = (pipe == 0) ? TRANS_HSYNC_A : TRANS_HSYNC_B;
  1545. int trans_vtot_reg = (pipe == 0) ? TRANS_VTOTAL_A : TRANS_VTOTAL_B;
  1546. int trans_vblank_reg = (pipe == 0) ? TRANS_VBLANK_A : TRANS_VBLANK_B;
  1547. int trans_vsync_reg = (pipe == 0) ? TRANS_VSYNC_A : TRANS_VSYNC_B;
  1548. int trans_dpll_sel = (pipe == 0) ? 0 : 1;
  1549. u32 temp;
  1550. int n;
  1551. u32 pipe_bpc;
  1552. temp = I915_READ(pipeconf_reg);
  1553. pipe_bpc = temp & PIPE_BPC_MASK;
  1554. /* XXX: When our outputs are all unaware of DPMS modes other than off
  1555. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  1556. */
  1557. switch (mode) {
  1558. case DRM_MODE_DPMS_ON:
  1559. case DRM_MODE_DPMS_STANDBY:
  1560. case DRM_MODE_DPMS_SUSPEND:
  1561. DRM_DEBUG_KMS("crtc %d dpms on\n", pipe);
  1562. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  1563. temp = I915_READ(PCH_LVDS);
  1564. if ((temp & LVDS_PORT_EN) == 0) {
  1565. I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
  1566. POSTING_READ(PCH_LVDS);
  1567. }
  1568. }
  1569. if (HAS_eDP) {
  1570. /* enable eDP PLL */
  1571. ironlake_enable_pll_edp(crtc);
  1572. } else {
  1573. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  1574. temp = I915_READ(fdi_rx_reg);
  1575. /*
  1576. * make the BPC in FDI Rx be consistent with that in
  1577. * pipeconf reg.
  1578. */
  1579. temp &= ~(0x7 << 16);
  1580. temp |= (pipe_bpc << 11);
  1581. I915_WRITE(fdi_rx_reg, temp | FDI_RX_PLL_ENABLE |
  1582. FDI_DP_PORT_WIDTH_X4); /* default 4 lanes */
  1583. I915_READ(fdi_rx_reg);
  1584. udelay(200);
  1585. /* Switch from Rawclk to PCDclk */
  1586. temp = I915_READ(fdi_rx_reg);
  1587. I915_WRITE(fdi_rx_reg, temp | FDI_SEL_PCDCLK);
  1588. I915_READ(fdi_rx_reg);
  1589. udelay(200);
  1590. /* Enable CPU FDI TX PLL, always on for Ironlake */
  1591. temp = I915_READ(fdi_tx_reg);
  1592. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  1593. I915_WRITE(fdi_tx_reg, temp | FDI_TX_PLL_ENABLE);
  1594. I915_READ(fdi_tx_reg);
  1595. udelay(100);
  1596. }
  1597. }
  1598. /* Enable panel fitting for LVDS */
  1599. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  1600. temp = I915_READ(pf_ctl_reg);
  1601. I915_WRITE(pf_ctl_reg, temp | PF_ENABLE | PF_FILTER_MED_3x3);
  1602. /* currently full aspect */
  1603. I915_WRITE(pf_win_pos, 0);
  1604. I915_WRITE(pf_win_size,
  1605. (dev_priv->panel_fixed_mode->hdisplay << 16) |
  1606. (dev_priv->panel_fixed_mode->vdisplay));
  1607. }
  1608. /* Enable CPU pipe */
  1609. temp = I915_READ(pipeconf_reg);
  1610. if ((temp & PIPEACONF_ENABLE) == 0) {
  1611. I915_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE);
  1612. I915_READ(pipeconf_reg);
  1613. udelay(100);
  1614. }
  1615. /* configure and enable CPU plane */
  1616. temp = I915_READ(dspcntr_reg);
  1617. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  1618. I915_WRITE(dspcntr_reg, temp | DISPLAY_PLANE_ENABLE);
  1619. /* Flush the plane changes */
  1620. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1621. }
  1622. if (!HAS_eDP) {
  1623. /* For PCH output, training FDI link */
  1624. if (IS_GEN6(dev))
  1625. gen6_fdi_link_train(crtc);
  1626. else
  1627. ironlake_fdi_link_train(crtc);
  1628. /* enable PCH DPLL */
  1629. temp = I915_READ(pch_dpll_reg);
  1630. if ((temp & DPLL_VCO_ENABLE) == 0) {
  1631. I915_WRITE(pch_dpll_reg, temp | DPLL_VCO_ENABLE);
  1632. I915_READ(pch_dpll_reg);
  1633. }
  1634. udelay(200);
  1635. if (HAS_PCH_CPT(dev)) {
  1636. /* Be sure PCH DPLL SEL is set */
  1637. temp = I915_READ(PCH_DPLL_SEL);
  1638. if (trans_dpll_sel == 0 &&
  1639. (temp & TRANSA_DPLL_ENABLE) == 0)
  1640. temp |= (TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL);
  1641. else if (trans_dpll_sel == 1 &&
  1642. (temp & TRANSB_DPLL_ENABLE) == 0)
  1643. temp |= (TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  1644. I915_WRITE(PCH_DPLL_SEL, temp);
  1645. I915_READ(PCH_DPLL_SEL);
  1646. }
  1647. /* set transcoder timing */
  1648. I915_WRITE(trans_htot_reg, I915_READ(cpu_htot_reg));
  1649. I915_WRITE(trans_hblank_reg, I915_READ(cpu_hblank_reg));
  1650. I915_WRITE(trans_hsync_reg, I915_READ(cpu_hsync_reg));
  1651. I915_WRITE(trans_vtot_reg, I915_READ(cpu_vtot_reg));
  1652. I915_WRITE(trans_vblank_reg, I915_READ(cpu_vblank_reg));
  1653. I915_WRITE(trans_vsync_reg, I915_READ(cpu_vsync_reg));
  1654. /* enable normal train */
  1655. temp = I915_READ(fdi_tx_reg);
  1656. temp &= ~FDI_LINK_TRAIN_NONE;
  1657. I915_WRITE(fdi_tx_reg, temp | FDI_LINK_TRAIN_NONE |
  1658. FDI_TX_ENHANCE_FRAME_ENABLE);
  1659. I915_READ(fdi_tx_reg);
  1660. temp = I915_READ(fdi_rx_reg);
  1661. if (HAS_PCH_CPT(dev)) {
  1662. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  1663. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  1664. } else {
  1665. temp &= ~FDI_LINK_TRAIN_NONE;
  1666. temp |= FDI_LINK_TRAIN_NONE;
  1667. }
  1668. I915_WRITE(fdi_rx_reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  1669. I915_READ(fdi_rx_reg);
  1670. /* wait one idle pattern time */
  1671. udelay(100);
  1672. /* For PCH DP, enable TRANS_DP_CTL */
  1673. if (HAS_PCH_CPT(dev) &&
  1674. intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  1675. int trans_dp_ctl = (pipe == 0) ? TRANS_DP_CTL_A : TRANS_DP_CTL_B;
  1676. int reg;
  1677. reg = I915_READ(trans_dp_ctl);
  1678. reg &= ~TRANS_DP_PORT_SEL_MASK;
  1679. reg = TRANS_DP_OUTPUT_ENABLE |
  1680. TRANS_DP_ENH_FRAMING |
  1681. TRANS_DP_VSYNC_ACTIVE_HIGH |
  1682. TRANS_DP_HSYNC_ACTIVE_HIGH;
  1683. switch (intel_trans_dp_port_sel(crtc)) {
  1684. case PCH_DP_B:
  1685. reg |= TRANS_DP_PORT_SEL_B;
  1686. break;
  1687. case PCH_DP_C:
  1688. reg |= TRANS_DP_PORT_SEL_C;
  1689. break;
  1690. case PCH_DP_D:
  1691. reg |= TRANS_DP_PORT_SEL_D;
  1692. break;
  1693. default:
  1694. DRM_DEBUG_KMS("Wrong PCH DP port return. Guess port B\n");
  1695. reg |= TRANS_DP_PORT_SEL_B;
  1696. break;
  1697. }
  1698. I915_WRITE(trans_dp_ctl, reg);
  1699. POSTING_READ(trans_dp_ctl);
  1700. }
  1701. /* enable PCH transcoder */
  1702. temp = I915_READ(transconf_reg);
  1703. /*
  1704. * make the BPC in transcoder be consistent with
  1705. * that in pipeconf reg.
  1706. */
  1707. temp &= ~PIPE_BPC_MASK;
  1708. temp |= pipe_bpc;
  1709. I915_WRITE(transconf_reg, temp | TRANS_ENABLE);
  1710. I915_READ(transconf_reg);
  1711. while ((I915_READ(transconf_reg) & TRANS_STATE_ENABLE) == 0)
  1712. ;
  1713. }
  1714. intel_crtc_load_lut(crtc);
  1715. break;
  1716. case DRM_MODE_DPMS_OFF:
  1717. DRM_DEBUG_KMS("crtc %d dpms off\n", pipe);
  1718. drm_vblank_off(dev, pipe);
  1719. /* Disable display plane */
  1720. temp = I915_READ(dspcntr_reg);
  1721. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  1722. I915_WRITE(dspcntr_reg, temp & ~DISPLAY_PLANE_ENABLE);
  1723. /* Flush the plane changes */
  1724. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1725. I915_READ(dspbase_reg);
  1726. }
  1727. i915_disable_vga(dev);
  1728. /* disable cpu pipe, disable after all planes disabled */
  1729. temp = I915_READ(pipeconf_reg);
  1730. if ((temp & PIPEACONF_ENABLE) != 0) {
  1731. I915_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE);
  1732. I915_READ(pipeconf_reg);
  1733. n = 0;
  1734. /* wait for cpu pipe off, pipe state */
  1735. while ((I915_READ(pipeconf_reg) & I965_PIPECONF_ACTIVE) != 0) {
  1736. n++;
  1737. if (n < 60) {
  1738. udelay(500);
  1739. continue;
  1740. } else {
  1741. DRM_DEBUG_KMS("pipe %d off delay\n",
  1742. pipe);
  1743. break;
  1744. }
  1745. }
  1746. } else
  1747. DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
  1748. udelay(100);
  1749. /* Disable PF */
  1750. temp = I915_READ(pf_ctl_reg);
  1751. if ((temp & PF_ENABLE) != 0) {
  1752. I915_WRITE(pf_ctl_reg, temp & ~PF_ENABLE);
  1753. I915_READ(pf_ctl_reg);
  1754. }
  1755. I915_WRITE(pf_win_size, 0);
  1756. POSTING_READ(pf_win_size);
  1757. /* disable CPU FDI tx and PCH FDI rx */
  1758. temp = I915_READ(fdi_tx_reg);
  1759. I915_WRITE(fdi_tx_reg, temp & ~FDI_TX_ENABLE);
  1760. I915_READ(fdi_tx_reg);
  1761. temp = I915_READ(fdi_rx_reg);
  1762. /* BPC in FDI rx is consistent with that in pipeconf */
  1763. temp &= ~(0x07 << 16);
  1764. temp |= (pipe_bpc << 11);
  1765. I915_WRITE(fdi_rx_reg, temp & ~FDI_RX_ENABLE);
  1766. I915_READ(fdi_rx_reg);
  1767. udelay(100);
  1768. /* still set train pattern 1 */
  1769. temp = I915_READ(fdi_tx_reg);
  1770. temp &= ~FDI_LINK_TRAIN_NONE;
  1771. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1772. I915_WRITE(fdi_tx_reg, temp);
  1773. POSTING_READ(fdi_tx_reg);
  1774. temp = I915_READ(fdi_rx_reg);
  1775. if (HAS_PCH_CPT(dev)) {
  1776. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  1777. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  1778. } else {
  1779. temp &= ~FDI_LINK_TRAIN_NONE;
  1780. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1781. }
  1782. I915_WRITE(fdi_rx_reg, temp);
  1783. POSTING_READ(fdi_rx_reg);
  1784. udelay(100);
  1785. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  1786. temp = I915_READ(PCH_LVDS);
  1787. I915_WRITE(PCH_LVDS, temp & ~LVDS_PORT_EN);
  1788. I915_READ(PCH_LVDS);
  1789. udelay(100);
  1790. }
  1791. /* disable PCH transcoder */
  1792. temp = I915_READ(transconf_reg);
  1793. if ((temp & TRANS_ENABLE) != 0) {
  1794. I915_WRITE(transconf_reg, temp & ~TRANS_ENABLE);
  1795. I915_READ(transconf_reg);
  1796. n = 0;
  1797. /* wait for PCH transcoder off, transcoder state */
  1798. while ((I915_READ(transconf_reg) & TRANS_STATE_ENABLE) != 0) {
  1799. n++;
  1800. if (n < 60) {
  1801. udelay(500);
  1802. continue;
  1803. } else {
  1804. DRM_DEBUG_KMS("transcoder %d off "
  1805. "delay\n", pipe);
  1806. break;
  1807. }
  1808. }
  1809. }
  1810. temp = I915_READ(transconf_reg);
  1811. /* BPC in transcoder is consistent with that in pipeconf */
  1812. temp &= ~PIPE_BPC_MASK;
  1813. temp |= pipe_bpc;
  1814. I915_WRITE(transconf_reg, temp);
  1815. I915_READ(transconf_reg);
  1816. udelay(100);
  1817. if (HAS_PCH_CPT(dev)) {
  1818. /* disable TRANS_DP_CTL */
  1819. int trans_dp_ctl = (pipe == 0) ? TRANS_DP_CTL_A : TRANS_DP_CTL_B;
  1820. int reg;
  1821. reg = I915_READ(trans_dp_ctl);
  1822. reg &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK);
  1823. I915_WRITE(trans_dp_ctl, reg);
  1824. POSTING_READ(trans_dp_ctl);
  1825. /* disable DPLL_SEL */
  1826. temp = I915_READ(PCH_DPLL_SEL);
  1827. if (trans_dpll_sel == 0)
  1828. temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLB_SEL);
  1829. else
  1830. temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  1831. I915_WRITE(PCH_DPLL_SEL, temp);
  1832. I915_READ(PCH_DPLL_SEL);
  1833. }
  1834. /* disable PCH DPLL */
  1835. temp = I915_READ(pch_dpll_reg);
  1836. I915_WRITE(pch_dpll_reg, temp & ~DPLL_VCO_ENABLE);
  1837. I915_READ(pch_dpll_reg);
  1838. if (HAS_eDP) {
  1839. ironlake_disable_pll_edp(crtc);
  1840. }
  1841. /* Switch from PCDclk to Rawclk */
  1842. temp = I915_READ(fdi_rx_reg);
  1843. temp &= ~FDI_SEL_PCDCLK;
  1844. I915_WRITE(fdi_rx_reg, temp);
  1845. I915_READ(fdi_rx_reg);
  1846. /* Disable CPU FDI TX PLL */
  1847. temp = I915_READ(fdi_tx_reg);
  1848. I915_WRITE(fdi_tx_reg, temp & ~FDI_TX_PLL_ENABLE);
  1849. I915_READ(fdi_tx_reg);
  1850. udelay(100);
  1851. temp = I915_READ(fdi_rx_reg);
  1852. temp &= ~FDI_RX_PLL_ENABLE;
  1853. I915_WRITE(fdi_rx_reg, temp);
  1854. I915_READ(fdi_rx_reg);
  1855. /* Wait for the clocks to turn off. */
  1856. udelay(100);
  1857. break;
  1858. }
  1859. }
  1860. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  1861. {
  1862. struct intel_overlay *overlay;
  1863. int ret;
  1864. if (!enable && intel_crtc->overlay) {
  1865. overlay = intel_crtc->overlay;
  1866. mutex_lock(&overlay->dev->struct_mutex);
  1867. for (;;) {
  1868. ret = intel_overlay_switch_off(overlay);
  1869. if (ret == 0)
  1870. break;
  1871. ret = intel_overlay_recover_from_interrupt(overlay, 0);
  1872. if (ret != 0) {
  1873. /* overlay doesn't react anymore. Usually
  1874. * results in a black screen and an unkillable
  1875. * X server. */
  1876. BUG();
  1877. overlay->hw_wedged = HW_WEDGED;
  1878. break;
  1879. }
  1880. }
  1881. mutex_unlock(&overlay->dev->struct_mutex);
  1882. }
  1883. /* Let userspace switch the overlay on again. In most cases userspace
  1884. * has to recompute where to put it anyway. */
  1885. return;
  1886. }
  1887. static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode)
  1888. {
  1889. struct drm_device *dev = crtc->dev;
  1890. struct drm_i915_private *dev_priv = dev->dev_private;
  1891. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1892. int pipe = intel_crtc->pipe;
  1893. int plane = intel_crtc->plane;
  1894. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  1895. int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR;
  1896. int dspbase_reg = (plane == 0) ? DSPAADDR : DSPBADDR;
  1897. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  1898. u32 temp;
  1899. /* XXX: When our outputs are all unaware of DPMS modes other than off
  1900. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  1901. */
  1902. switch (mode) {
  1903. case DRM_MODE_DPMS_ON:
  1904. case DRM_MODE_DPMS_STANDBY:
  1905. case DRM_MODE_DPMS_SUSPEND:
  1906. intel_update_watermarks(dev);
  1907. /* Enable the DPLL */
  1908. temp = I915_READ(dpll_reg);
  1909. if ((temp & DPLL_VCO_ENABLE) == 0) {
  1910. I915_WRITE(dpll_reg, temp);
  1911. I915_READ(dpll_reg);
  1912. /* Wait for the clocks to stabilize. */
  1913. udelay(150);
  1914. I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  1915. I915_READ(dpll_reg);
  1916. /* Wait for the clocks to stabilize. */
  1917. udelay(150);
  1918. I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  1919. I915_READ(dpll_reg);
  1920. /* Wait for the clocks to stabilize. */
  1921. udelay(150);
  1922. }
  1923. /* Enable the pipe */
  1924. temp = I915_READ(pipeconf_reg);
  1925. if ((temp & PIPEACONF_ENABLE) == 0)
  1926. I915_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE);
  1927. /* Enable the plane */
  1928. temp = I915_READ(dspcntr_reg);
  1929. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  1930. I915_WRITE(dspcntr_reg, temp | DISPLAY_PLANE_ENABLE);
  1931. /* Flush the plane changes */
  1932. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1933. }
  1934. intel_crtc_load_lut(crtc);
  1935. if ((IS_I965G(dev) || plane == 0))
  1936. intel_update_fbc(crtc, &crtc->mode);
  1937. /* Give the overlay scaler a chance to enable if it's on this pipe */
  1938. intel_crtc_dpms_overlay(intel_crtc, true);
  1939. break;
  1940. case DRM_MODE_DPMS_OFF:
  1941. intel_update_watermarks(dev);
  1942. /* Give the overlay scaler a chance to disable if it's on this pipe */
  1943. intel_crtc_dpms_overlay(intel_crtc, false);
  1944. drm_vblank_off(dev, pipe);
  1945. if (dev_priv->cfb_plane == plane &&
  1946. dev_priv->display.disable_fbc)
  1947. dev_priv->display.disable_fbc(dev);
  1948. /* Disable the VGA plane that we never use */
  1949. i915_disable_vga(dev);
  1950. /* Disable display plane */
  1951. temp = I915_READ(dspcntr_reg);
  1952. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  1953. I915_WRITE(dspcntr_reg, temp & ~DISPLAY_PLANE_ENABLE);
  1954. /* Flush the plane changes */
  1955. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1956. I915_READ(dspbase_reg);
  1957. }
  1958. if (!IS_I9XX(dev)) {
  1959. /* Wait for vblank for the disable to take effect */
  1960. intel_wait_for_vblank(dev);
  1961. }
  1962. /* Next, disable display pipes */
  1963. temp = I915_READ(pipeconf_reg);
  1964. if ((temp & PIPEACONF_ENABLE) != 0) {
  1965. I915_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE);
  1966. I915_READ(pipeconf_reg);
  1967. }
  1968. /* Wait for vblank for the disable to take effect. */
  1969. intel_wait_for_vblank(dev);
  1970. temp = I915_READ(dpll_reg);
  1971. if ((temp & DPLL_VCO_ENABLE) != 0) {
  1972. I915_WRITE(dpll_reg, temp & ~DPLL_VCO_ENABLE);
  1973. I915_READ(dpll_reg);
  1974. }
  1975. /* Wait for the clocks to turn off. */
  1976. udelay(150);
  1977. break;
  1978. }
  1979. }
  1980. /**
  1981. * Sets the power management mode of the pipe and plane.
  1982. *
  1983. * This code should probably grow support for turning the cursor off and back
  1984. * on appropriately at the same time as we're turning the pipe off/on.
  1985. */
  1986. static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
  1987. {
  1988. struct drm_device *dev = crtc->dev;
  1989. struct drm_i915_private *dev_priv = dev->dev_private;
  1990. struct drm_i915_master_private *master_priv;
  1991. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1992. int pipe = intel_crtc->pipe;
  1993. bool enabled;
  1994. dev_priv->display.dpms(crtc, mode);
  1995. intel_crtc->dpms_mode = mode;
  1996. if (!dev->primary->master)
  1997. return;
  1998. master_priv = dev->primary->master->driver_priv;
  1999. if (!master_priv->sarea_priv)
  2000. return;
  2001. enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
  2002. switch (pipe) {
  2003. case 0:
  2004. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  2005. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  2006. break;
  2007. case 1:
  2008. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  2009. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  2010. break;
  2011. default:
  2012. DRM_ERROR("Can't update pipe %d in SAREA\n", pipe);
  2013. break;
  2014. }
  2015. }
  2016. static void intel_crtc_prepare (struct drm_crtc *crtc)
  2017. {
  2018. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  2019. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  2020. }
  2021. static void intel_crtc_commit (struct drm_crtc *crtc)
  2022. {
  2023. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  2024. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  2025. }
  2026. void intel_encoder_prepare (struct drm_encoder *encoder)
  2027. {
  2028. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  2029. /* lvds has its own version of prepare see intel_lvds_prepare */
  2030. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
  2031. }
  2032. void intel_encoder_commit (struct drm_encoder *encoder)
  2033. {
  2034. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  2035. /* lvds has its own version of commit see intel_lvds_commit */
  2036. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  2037. }
  2038. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  2039. struct drm_display_mode *mode,
  2040. struct drm_display_mode *adjusted_mode)
  2041. {
  2042. struct drm_device *dev = crtc->dev;
  2043. if (HAS_PCH_SPLIT(dev)) {
  2044. /* FDI link clock is fixed at 2.7G */
  2045. if (mode->clock * 3 > 27000 * 4)
  2046. return MODE_CLOCK_HIGH;
  2047. }
  2048. return true;
  2049. }
  2050. static int i945_get_display_clock_speed(struct drm_device *dev)
  2051. {
  2052. return 400000;
  2053. }
  2054. static int i915_get_display_clock_speed(struct drm_device *dev)
  2055. {
  2056. return 333000;
  2057. }
  2058. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  2059. {
  2060. return 200000;
  2061. }
  2062. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  2063. {
  2064. u16 gcfgc = 0;
  2065. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  2066. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  2067. return 133000;
  2068. else {
  2069. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  2070. case GC_DISPLAY_CLOCK_333_MHZ:
  2071. return 333000;
  2072. default:
  2073. case GC_DISPLAY_CLOCK_190_200_MHZ:
  2074. return 190000;
  2075. }
  2076. }
  2077. }
  2078. static int i865_get_display_clock_speed(struct drm_device *dev)
  2079. {
  2080. return 266000;
  2081. }
  2082. static int i855_get_display_clock_speed(struct drm_device *dev)
  2083. {
  2084. u16 hpllcc = 0;
  2085. /* Assume that the hardware is in the high speed state. This
  2086. * should be the default.
  2087. */
  2088. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  2089. case GC_CLOCK_133_200:
  2090. case GC_CLOCK_100_200:
  2091. return 200000;
  2092. case GC_CLOCK_166_250:
  2093. return 250000;
  2094. case GC_CLOCK_100_133:
  2095. return 133000;
  2096. }
  2097. /* Shouldn't happen */
  2098. return 0;
  2099. }
  2100. static int i830_get_display_clock_speed(struct drm_device *dev)
  2101. {
  2102. return 133000;
  2103. }
  2104. /**
  2105. * Return the pipe currently connected to the panel fitter,
  2106. * or -1 if the panel fitter is not present or not in use
  2107. */
  2108. int intel_panel_fitter_pipe (struct drm_device *dev)
  2109. {
  2110. struct drm_i915_private *dev_priv = dev->dev_private;
  2111. u32 pfit_control;
  2112. /* i830 doesn't have a panel fitter */
  2113. if (IS_I830(dev))
  2114. return -1;
  2115. pfit_control = I915_READ(PFIT_CONTROL);
  2116. /* See if the panel fitter is in use */
  2117. if ((pfit_control & PFIT_ENABLE) == 0)
  2118. return -1;
  2119. /* 965 can place panel fitter on either pipe */
  2120. if (IS_I965G(dev))
  2121. return (pfit_control >> 29) & 0x3;
  2122. /* older chips can only use pipe 1 */
  2123. return 1;
  2124. }
  2125. struct fdi_m_n {
  2126. u32 tu;
  2127. u32 gmch_m;
  2128. u32 gmch_n;
  2129. u32 link_m;
  2130. u32 link_n;
  2131. };
  2132. static void
  2133. fdi_reduce_ratio(u32 *num, u32 *den)
  2134. {
  2135. while (*num > 0xffffff || *den > 0xffffff) {
  2136. *num >>= 1;
  2137. *den >>= 1;
  2138. }
  2139. }
  2140. #define DATA_N 0x800000
  2141. #define LINK_N 0x80000
  2142. static void
  2143. ironlake_compute_m_n(int bits_per_pixel, int nlanes, int pixel_clock,
  2144. int link_clock, struct fdi_m_n *m_n)
  2145. {
  2146. u64 temp;
  2147. m_n->tu = 64; /* default size */
  2148. temp = (u64) DATA_N * pixel_clock;
  2149. temp = div_u64(temp, link_clock);
  2150. m_n->gmch_m = div_u64(temp * bits_per_pixel, nlanes);
  2151. m_n->gmch_m >>= 3; /* convert to bytes_per_pixel */
  2152. m_n->gmch_n = DATA_N;
  2153. fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  2154. temp = (u64) LINK_N * pixel_clock;
  2155. m_n->link_m = div_u64(temp, link_clock);
  2156. m_n->link_n = LINK_N;
  2157. fdi_reduce_ratio(&m_n->link_m, &m_n->link_n);
  2158. }
  2159. struct intel_watermark_params {
  2160. unsigned long fifo_size;
  2161. unsigned long max_wm;
  2162. unsigned long default_wm;
  2163. unsigned long guard_size;
  2164. unsigned long cacheline_size;
  2165. };
  2166. /* Pineview has different values for various configs */
  2167. static struct intel_watermark_params pineview_display_wm = {
  2168. PINEVIEW_DISPLAY_FIFO,
  2169. PINEVIEW_MAX_WM,
  2170. PINEVIEW_DFT_WM,
  2171. PINEVIEW_GUARD_WM,
  2172. PINEVIEW_FIFO_LINE_SIZE
  2173. };
  2174. static struct intel_watermark_params pineview_display_hplloff_wm = {
  2175. PINEVIEW_DISPLAY_FIFO,
  2176. PINEVIEW_MAX_WM,
  2177. PINEVIEW_DFT_HPLLOFF_WM,
  2178. PINEVIEW_GUARD_WM,
  2179. PINEVIEW_FIFO_LINE_SIZE
  2180. };
  2181. static struct intel_watermark_params pineview_cursor_wm = {
  2182. PINEVIEW_CURSOR_FIFO,
  2183. PINEVIEW_CURSOR_MAX_WM,
  2184. PINEVIEW_CURSOR_DFT_WM,
  2185. PINEVIEW_CURSOR_GUARD_WM,
  2186. PINEVIEW_FIFO_LINE_SIZE,
  2187. };
  2188. static struct intel_watermark_params pineview_cursor_hplloff_wm = {
  2189. PINEVIEW_CURSOR_FIFO,
  2190. PINEVIEW_CURSOR_MAX_WM,
  2191. PINEVIEW_CURSOR_DFT_WM,
  2192. PINEVIEW_CURSOR_GUARD_WM,
  2193. PINEVIEW_FIFO_LINE_SIZE
  2194. };
  2195. static struct intel_watermark_params g4x_wm_info = {
  2196. G4X_FIFO_SIZE,
  2197. G4X_MAX_WM,
  2198. G4X_MAX_WM,
  2199. 2,
  2200. G4X_FIFO_LINE_SIZE,
  2201. };
  2202. static struct intel_watermark_params i945_wm_info = {
  2203. I945_FIFO_SIZE,
  2204. I915_MAX_WM,
  2205. 1,
  2206. 2,
  2207. I915_FIFO_LINE_SIZE
  2208. };
  2209. static struct intel_watermark_params i915_wm_info = {
  2210. I915_FIFO_SIZE,
  2211. I915_MAX_WM,
  2212. 1,
  2213. 2,
  2214. I915_FIFO_LINE_SIZE
  2215. };
  2216. static struct intel_watermark_params i855_wm_info = {
  2217. I855GM_FIFO_SIZE,
  2218. I915_MAX_WM,
  2219. 1,
  2220. 2,
  2221. I830_FIFO_LINE_SIZE
  2222. };
  2223. static struct intel_watermark_params i830_wm_info = {
  2224. I830_FIFO_SIZE,
  2225. I915_MAX_WM,
  2226. 1,
  2227. 2,
  2228. I830_FIFO_LINE_SIZE
  2229. };
  2230. static struct intel_watermark_params ironlake_display_wm_info = {
  2231. ILK_DISPLAY_FIFO,
  2232. ILK_DISPLAY_MAXWM,
  2233. ILK_DISPLAY_DFTWM,
  2234. 2,
  2235. ILK_FIFO_LINE_SIZE
  2236. };
  2237. static struct intel_watermark_params ironlake_display_srwm_info = {
  2238. ILK_DISPLAY_SR_FIFO,
  2239. ILK_DISPLAY_MAX_SRWM,
  2240. ILK_DISPLAY_DFT_SRWM,
  2241. 2,
  2242. ILK_FIFO_LINE_SIZE
  2243. };
  2244. static struct intel_watermark_params ironlake_cursor_srwm_info = {
  2245. ILK_CURSOR_SR_FIFO,
  2246. ILK_CURSOR_MAX_SRWM,
  2247. ILK_CURSOR_DFT_SRWM,
  2248. 2,
  2249. ILK_FIFO_LINE_SIZE
  2250. };
  2251. /**
  2252. * intel_calculate_wm - calculate watermark level
  2253. * @clock_in_khz: pixel clock
  2254. * @wm: chip FIFO params
  2255. * @pixel_size: display pixel size
  2256. * @latency_ns: memory latency for the platform
  2257. *
  2258. * Calculate the watermark level (the level at which the display plane will
  2259. * start fetching from memory again). Each chip has a different display
  2260. * FIFO size and allocation, so the caller needs to figure that out and pass
  2261. * in the correct intel_watermark_params structure.
  2262. *
  2263. * As the pixel clock runs, the FIFO will be drained at a rate that depends
  2264. * on the pixel size. When it reaches the watermark level, it'll start
  2265. * fetching FIFO line sized based chunks from memory until the FIFO fills
  2266. * past the watermark point. If the FIFO drains completely, a FIFO underrun
  2267. * will occur, and a display engine hang could result.
  2268. */
  2269. static unsigned long intel_calculate_wm(unsigned long clock_in_khz,
  2270. struct intel_watermark_params *wm,
  2271. int pixel_size,
  2272. unsigned long latency_ns)
  2273. {
  2274. long entries_required, wm_size;
  2275. /*
  2276. * Note: we need to make sure we don't overflow for various clock &
  2277. * latency values.
  2278. * clocks go from a few thousand to several hundred thousand.
  2279. * latency is usually a few thousand
  2280. */
  2281. entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) /
  2282. 1000;
  2283. entries_required /= wm->cacheline_size;
  2284. DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries_required);
  2285. wm_size = wm->fifo_size - (entries_required + wm->guard_size);
  2286. DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size);
  2287. /* Don't promote wm_size to unsigned... */
  2288. if (wm_size > (long)wm->max_wm)
  2289. wm_size = wm->max_wm;
  2290. if (wm_size <= 0)
  2291. wm_size = wm->default_wm;
  2292. return wm_size;
  2293. }
  2294. struct cxsr_latency {
  2295. int is_desktop;
  2296. unsigned long fsb_freq;
  2297. unsigned long mem_freq;
  2298. unsigned long display_sr;
  2299. unsigned long display_hpll_disable;
  2300. unsigned long cursor_sr;
  2301. unsigned long cursor_hpll_disable;
  2302. };
  2303. static struct cxsr_latency cxsr_latency_table[] = {
  2304. {1, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
  2305. {1, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
  2306. {1, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
  2307. {1, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
  2308. {1, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
  2309. {1, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
  2310. {1, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
  2311. {1, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
  2312. {1, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
  2313. {0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
  2314. {0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
  2315. {0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
  2316. {0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
  2317. {0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
  2318. {0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
  2319. {0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
  2320. {0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
  2321. {0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
  2322. };
  2323. static struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, int fsb,
  2324. int mem)
  2325. {
  2326. int i;
  2327. struct cxsr_latency *latency;
  2328. if (fsb == 0 || mem == 0)
  2329. return NULL;
  2330. for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
  2331. latency = &cxsr_latency_table[i];
  2332. if (is_desktop == latency->is_desktop &&
  2333. fsb == latency->fsb_freq && mem == latency->mem_freq)
  2334. return latency;
  2335. }
  2336. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  2337. return NULL;
  2338. }
  2339. static void pineview_disable_cxsr(struct drm_device *dev)
  2340. {
  2341. struct drm_i915_private *dev_priv = dev->dev_private;
  2342. u32 reg;
  2343. /* deactivate cxsr */
  2344. reg = I915_READ(DSPFW3);
  2345. reg &= ~(PINEVIEW_SELF_REFRESH_EN);
  2346. I915_WRITE(DSPFW3, reg);
  2347. DRM_INFO("Big FIFO is disabled\n");
  2348. }
  2349. /*
  2350. * Latency for FIFO fetches is dependent on several factors:
  2351. * - memory configuration (speed, channels)
  2352. * - chipset
  2353. * - current MCH state
  2354. * It can be fairly high in some situations, so here we assume a fairly
  2355. * pessimal value. It's a tradeoff between extra memory fetches (if we
  2356. * set this value too high, the FIFO will fetch frequently to stay full)
  2357. * and power consumption (set it too low to save power and we might see
  2358. * FIFO underruns and display "flicker").
  2359. *
  2360. * A value of 5us seems to be a good balance; safe for very low end
  2361. * platforms but not overly aggressive on lower latency configs.
  2362. */
  2363. static const int latency_ns = 5000;
  2364. static int i9xx_get_fifo_size(struct drm_device *dev, int plane)
  2365. {
  2366. struct drm_i915_private *dev_priv = dev->dev_private;
  2367. uint32_t dsparb = I915_READ(DSPARB);
  2368. int size;
  2369. if (plane == 0)
  2370. size = dsparb & 0x7f;
  2371. else
  2372. size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) -
  2373. (dsparb & 0x7f);
  2374. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  2375. plane ? "B" : "A", size);
  2376. return size;
  2377. }
  2378. static int i85x_get_fifo_size(struct drm_device *dev, int plane)
  2379. {
  2380. struct drm_i915_private *dev_priv = dev->dev_private;
  2381. uint32_t dsparb = I915_READ(DSPARB);
  2382. int size;
  2383. if (plane == 0)
  2384. size = dsparb & 0x1ff;
  2385. else
  2386. size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) -
  2387. (dsparb & 0x1ff);
  2388. size >>= 1; /* Convert to cachelines */
  2389. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  2390. plane ? "B" : "A", size);
  2391. return size;
  2392. }
  2393. static int i845_get_fifo_size(struct drm_device *dev, int plane)
  2394. {
  2395. struct drm_i915_private *dev_priv = dev->dev_private;
  2396. uint32_t dsparb = I915_READ(DSPARB);
  2397. int size;
  2398. size = dsparb & 0x7f;
  2399. size >>= 2; /* Convert to cachelines */
  2400. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  2401. plane ? "B" : "A",
  2402. size);
  2403. return size;
  2404. }
  2405. static int i830_get_fifo_size(struct drm_device *dev, int plane)
  2406. {
  2407. struct drm_i915_private *dev_priv = dev->dev_private;
  2408. uint32_t dsparb = I915_READ(DSPARB);
  2409. int size;
  2410. size = dsparb & 0x7f;
  2411. size >>= 1; /* Convert to cachelines */
  2412. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  2413. plane ? "B" : "A", size);
  2414. return size;
  2415. }
  2416. static void pineview_update_wm(struct drm_device *dev, int planea_clock,
  2417. int planeb_clock, int sr_hdisplay, int pixel_size)
  2418. {
  2419. struct drm_i915_private *dev_priv = dev->dev_private;
  2420. u32 reg;
  2421. unsigned long wm;
  2422. struct cxsr_latency *latency;
  2423. int sr_clock;
  2424. latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->fsb_freq,
  2425. dev_priv->mem_freq);
  2426. if (!latency) {
  2427. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  2428. pineview_disable_cxsr(dev);
  2429. return;
  2430. }
  2431. if (!planea_clock || !planeb_clock) {
  2432. sr_clock = planea_clock ? planea_clock : planeb_clock;
  2433. /* Display SR */
  2434. wm = intel_calculate_wm(sr_clock, &pineview_display_wm,
  2435. pixel_size, latency->display_sr);
  2436. reg = I915_READ(DSPFW1);
  2437. reg &= ~DSPFW_SR_MASK;
  2438. reg |= wm << DSPFW_SR_SHIFT;
  2439. I915_WRITE(DSPFW1, reg);
  2440. DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg);
  2441. /* cursor SR */
  2442. wm = intel_calculate_wm(sr_clock, &pineview_cursor_wm,
  2443. pixel_size, latency->cursor_sr);
  2444. reg = I915_READ(DSPFW3);
  2445. reg &= ~DSPFW_CURSOR_SR_MASK;
  2446. reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT;
  2447. I915_WRITE(DSPFW3, reg);
  2448. /* Display HPLL off SR */
  2449. wm = intel_calculate_wm(sr_clock, &pineview_display_hplloff_wm,
  2450. pixel_size, latency->display_hpll_disable);
  2451. reg = I915_READ(DSPFW3);
  2452. reg &= ~DSPFW_HPLL_SR_MASK;
  2453. reg |= wm & DSPFW_HPLL_SR_MASK;
  2454. I915_WRITE(DSPFW3, reg);
  2455. /* cursor HPLL off SR */
  2456. wm = intel_calculate_wm(sr_clock, &pineview_cursor_hplloff_wm,
  2457. pixel_size, latency->cursor_hpll_disable);
  2458. reg = I915_READ(DSPFW3);
  2459. reg &= ~DSPFW_HPLL_CURSOR_MASK;
  2460. reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT;
  2461. I915_WRITE(DSPFW3, reg);
  2462. DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg);
  2463. /* activate cxsr */
  2464. reg = I915_READ(DSPFW3);
  2465. reg |= PINEVIEW_SELF_REFRESH_EN;
  2466. I915_WRITE(DSPFW3, reg);
  2467. DRM_DEBUG_KMS("Self-refresh is enabled\n");
  2468. } else {
  2469. pineview_disable_cxsr(dev);
  2470. DRM_DEBUG_KMS("Self-refresh is disabled\n");
  2471. }
  2472. }
  2473. static void g4x_update_wm(struct drm_device *dev, int planea_clock,
  2474. int planeb_clock, int sr_hdisplay, int pixel_size)
  2475. {
  2476. struct drm_i915_private *dev_priv = dev->dev_private;
  2477. int total_size, cacheline_size;
  2478. int planea_wm, planeb_wm, cursora_wm, cursorb_wm, cursor_sr;
  2479. struct intel_watermark_params planea_params, planeb_params;
  2480. unsigned long line_time_us;
  2481. int sr_clock, sr_entries = 0, entries_required;
  2482. /* Create copies of the base settings for each pipe */
  2483. planea_params = planeb_params = g4x_wm_info;
  2484. /* Grab a couple of global values before we overwrite them */
  2485. total_size = planea_params.fifo_size;
  2486. cacheline_size = planea_params.cacheline_size;
  2487. /*
  2488. * Note: we need to make sure we don't overflow for various clock &
  2489. * latency values.
  2490. * clocks go from a few thousand to several hundred thousand.
  2491. * latency is usually a few thousand
  2492. */
  2493. entries_required = ((planea_clock / 1000) * pixel_size * latency_ns) /
  2494. 1000;
  2495. entries_required /= G4X_FIFO_LINE_SIZE;
  2496. planea_wm = entries_required + planea_params.guard_size;
  2497. entries_required = ((planeb_clock / 1000) * pixel_size * latency_ns) /
  2498. 1000;
  2499. entries_required /= G4X_FIFO_LINE_SIZE;
  2500. planeb_wm = entries_required + planeb_params.guard_size;
  2501. cursora_wm = cursorb_wm = 16;
  2502. cursor_sr = 32;
  2503. DRM_DEBUG("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
  2504. /* Calc sr entries for one plane configs */
  2505. if (sr_hdisplay && (!planea_clock || !planeb_clock)) {
  2506. /* self-refresh has much higher latency */
  2507. static const int sr_latency_ns = 12000;
  2508. sr_clock = planea_clock ? planea_clock : planeb_clock;
  2509. line_time_us = ((sr_hdisplay * 1000) / sr_clock);
  2510. /* Use ns/us then divide to preserve precision */
  2511. sr_entries = (((sr_latency_ns / line_time_us) + 1) *
  2512. pixel_size * sr_hdisplay) / 1000;
  2513. sr_entries = roundup(sr_entries / cacheline_size, 1);
  2514. DRM_DEBUG("self-refresh entries: %d\n", sr_entries);
  2515. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
  2516. } else {
  2517. /* Turn off self refresh if both pipes are enabled */
  2518. I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF)
  2519. & ~FW_BLC_SELF_EN);
  2520. }
  2521. DRM_DEBUG("Setting FIFO watermarks - A: %d, B: %d, SR %d\n",
  2522. planea_wm, planeb_wm, sr_entries);
  2523. planea_wm &= 0x3f;
  2524. planeb_wm &= 0x3f;
  2525. I915_WRITE(DSPFW1, (sr_entries << DSPFW_SR_SHIFT) |
  2526. (cursorb_wm << DSPFW_CURSORB_SHIFT) |
  2527. (planeb_wm << DSPFW_PLANEB_SHIFT) | planea_wm);
  2528. I915_WRITE(DSPFW2, (I915_READ(DSPFW2) & DSPFW_CURSORA_MASK) |
  2529. (cursora_wm << DSPFW_CURSORA_SHIFT));
  2530. /* HPLL off in SR has some issues on G4x... disable it */
  2531. I915_WRITE(DSPFW3, (I915_READ(DSPFW3) & ~DSPFW_HPLL_SR_EN) |
  2532. (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  2533. }
  2534. static void i965_update_wm(struct drm_device *dev, int planea_clock,
  2535. int planeb_clock, int sr_hdisplay, int pixel_size)
  2536. {
  2537. struct drm_i915_private *dev_priv = dev->dev_private;
  2538. unsigned long line_time_us;
  2539. int sr_clock, sr_entries, srwm = 1;
  2540. /* Calc sr entries for one plane configs */
  2541. if (sr_hdisplay && (!planea_clock || !planeb_clock)) {
  2542. /* self-refresh has much higher latency */
  2543. static const int sr_latency_ns = 12000;
  2544. sr_clock = planea_clock ? planea_clock : planeb_clock;
  2545. line_time_us = ((sr_hdisplay * 1000) / sr_clock);
  2546. /* Use ns/us then divide to preserve precision */
  2547. sr_entries = (((sr_latency_ns / line_time_us) + 1) *
  2548. pixel_size * sr_hdisplay) / 1000;
  2549. sr_entries = roundup(sr_entries / I915_FIFO_LINE_SIZE, 1);
  2550. DRM_DEBUG("self-refresh entries: %d\n", sr_entries);
  2551. srwm = I945_FIFO_SIZE - sr_entries;
  2552. if (srwm < 0)
  2553. srwm = 1;
  2554. srwm &= 0x3f;
  2555. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
  2556. } else {
  2557. /* Turn off self refresh if both pipes are enabled */
  2558. I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF)
  2559. & ~FW_BLC_SELF_EN);
  2560. }
  2561. DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
  2562. srwm);
  2563. /* 965 has limitations... */
  2564. I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) | (8 << 16) | (8 << 8) |
  2565. (8 << 0));
  2566. I915_WRITE(DSPFW2, (8 << 8) | (8 << 0));
  2567. }
  2568. static void i9xx_update_wm(struct drm_device *dev, int planea_clock,
  2569. int planeb_clock, int sr_hdisplay, int pixel_size)
  2570. {
  2571. struct drm_i915_private *dev_priv = dev->dev_private;
  2572. uint32_t fwater_lo;
  2573. uint32_t fwater_hi;
  2574. int total_size, cacheline_size, cwm, srwm = 1;
  2575. int planea_wm, planeb_wm;
  2576. struct intel_watermark_params planea_params, planeb_params;
  2577. unsigned long line_time_us;
  2578. int sr_clock, sr_entries = 0;
  2579. /* Create copies of the base settings for each pipe */
  2580. if (IS_I965GM(dev) || IS_I945GM(dev))
  2581. planea_params = planeb_params = i945_wm_info;
  2582. else if (IS_I9XX(dev))
  2583. planea_params = planeb_params = i915_wm_info;
  2584. else
  2585. planea_params = planeb_params = i855_wm_info;
  2586. /* Grab a couple of global values before we overwrite them */
  2587. total_size = planea_params.fifo_size;
  2588. cacheline_size = planea_params.cacheline_size;
  2589. /* Update per-plane FIFO sizes */
  2590. planea_params.fifo_size = dev_priv->display.get_fifo_size(dev, 0);
  2591. planeb_params.fifo_size = dev_priv->display.get_fifo_size(dev, 1);
  2592. planea_wm = intel_calculate_wm(planea_clock, &planea_params,
  2593. pixel_size, latency_ns);
  2594. planeb_wm = intel_calculate_wm(planeb_clock, &planeb_params,
  2595. pixel_size, latency_ns);
  2596. DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
  2597. /*
  2598. * Overlay gets an aggressive default since video jitter is bad.
  2599. */
  2600. cwm = 2;
  2601. /* Calc sr entries for one plane configs */
  2602. if (HAS_FW_BLC(dev) && sr_hdisplay &&
  2603. (!planea_clock || !planeb_clock)) {
  2604. /* self-refresh has much higher latency */
  2605. static const int sr_latency_ns = 6000;
  2606. sr_clock = planea_clock ? planea_clock : planeb_clock;
  2607. line_time_us = ((sr_hdisplay * 1000) / sr_clock);
  2608. /* Use ns/us then divide to preserve precision */
  2609. sr_entries = (((sr_latency_ns / line_time_us) + 1) *
  2610. pixel_size * sr_hdisplay) / 1000;
  2611. sr_entries = roundup(sr_entries / cacheline_size, 1);
  2612. DRM_DEBUG_KMS("self-refresh entries: %d\n", sr_entries);
  2613. srwm = total_size - sr_entries;
  2614. if (srwm < 0)
  2615. srwm = 1;
  2616. if (IS_I945G(dev) || IS_I945GM(dev))
  2617. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_FIFO_MASK | (srwm & 0xff));
  2618. else if (IS_I915GM(dev)) {
  2619. /* 915M has a smaller SRWM field */
  2620. I915_WRITE(FW_BLC_SELF, srwm & 0x3f);
  2621. I915_WRITE(INSTPM, I915_READ(INSTPM) | INSTPM_SELF_EN);
  2622. }
  2623. } else {
  2624. /* Turn off self refresh if both pipes are enabled */
  2625. if (IS_I945G(dev) || IS_I945GM(dev)) {
  2626. I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF)
  2627. & ~FW_BLC_SELF_EN);
  2628. } else if (IS_I915GM(dev)) {
  2629. I915_WRITE(INSTPM, I915_READ(INSTPM) & ~INSTPM_SELF_EN);
  2630. }
  2631. }
  2632. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
  2633. planea_wm, planeb_wm, cwm, srwm);
  2634. fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
  2635. fwater_hi = (cwm & 0x1f);
  2636. /* Set request length to 8 cachelines per fetch */
  2637. fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
  2638. fwater_hi = fwater_hi | (1 << 8);
  2639. I915_WRITE(FW_BLC, fwater_lo);
  2640. I915_WRITE(FW_BLC2, fwater_hi);
  2641. }
  2642. static void i830_update_wm(struct drm_device *dev, int planea_clock, int unused,
  2643. int unused2, int pixel_size)
  2644. {
  2645. struct drm_i915_private *dev_priv = dev->dev_private;
  2646. uint32_t fwater_lo = I915_READ(FW_BLC) & ~0xfff;
  2647. int planea_wm;
  2648. i830_wm_info.fifo_size = dev_priv->display.get_fifo_size(dev, 0);
  2649. planea_wm = intel_calculate_wm(planea_clock, &i830_wm_info,
  2650. pixel_size, latency_ns);
  2651. fwater_lo |= (3<<8) | planea_wm;
  2652. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm);
  2653. I915_WRITE(FW_BLC, fwater_lo);
  2654. }
  2655. #define ILK_LP0_PLANE_LATENCY 700
  2656. static void ironlake_update_wm(struct drm_device *dev, int planea_clock,
  2657. int planeb_clock, int sr_hdisplay, int pixel_size)
  2658. {
  2659. struct drm_i915_private *dev_priv = dev->dev_private;
  2660. int planea_wm, planeb_wm, cursora_wm, cursorb_wm;
  2661. int sr_wm, cursor_wm;
  2662. unsigned long line_time_us;
  2663. int sr_clock, entries_required;
  2664. u32 reg_value;
  2665. /* Calculate and update the watermark for plane A */
  2666. if (planea_clock) {
  2667. entries_required = ((planea_clock / 1000) * pixel_size *
  2668. ILK_LP0_PLANE_LATENCY) / 1000;
  2669. entries_required = DIV_ROUND_UP(entries_required,
  2670. ironlake_display_wm_info.cacheline_size);
  2671. planea_wm = entries_required +
  2672. ironlake_display_wm_info.guard_size;
  2673. if (planea_wm > (int)ironlake_display_wm_info.max_wm)
  2674. planea_wm = ironlake_display_wm_info.max_wm;
  2675. cursora_wm = 16;
  2676. reg_value = I915_READ(WM0_PIPEA_ILK);
  2677. reg_value &= ~(WM0_PIPE_PLANE_MASK | WM0_PIPE_CURSOR_MASK);
  2678. reg_value |= (planea_wm << WM0_PIPE_PLANE_SHIFT) |
  2679. (cursora_wm & WM0_PIPE_CURSOR_MASK);
  2680. I915_WRITE(WM0_PIPEA_ILK, reg_value);
  2681. DRM_DEBUG_KMS("FIFO watermarks For pipe A - plane %d, "
  2682. "cursor: %d\n", planea_wm, cursora_wm);
  2683. }
  2684. /* Calculate and update the watermark for plane B */
  2685. if (planeb_clock) {
  2686. entries_required = ((planeb_clock / 1000) * pixel_size *
  2687. ILK_LP0_PLANE_LATENCY) / 1000;
  2688. entries_required = DIV_ROUND_UP(entries_required,
  2689. ironlake_display_wm_info.cacheline_size);
  2690. planeb_wm = entries_required +
  2691. ironlake_display_wm_info.guard_size;
  2692. if (planeb_wm > (int)ironlake_display_wm_info.max_wm)
  2693. planeb_wm = ironlake_display_wm_info.max_wm;
  2694. cursorb_wm = 16;
  2695. reg_value = I915_READ(WM0_PIPEB_ILK);
  2696. reg_value &= ~(WM0_PIPE_PLANE_MASK | WM0_PIPE_CURSOR_MASK);
  2697. reg_value |= (planeb_wm << WM0_PIPE_PLANE_SHIFT) |
  2698. (cursorb_wm & WM0_PIPE_CURSOR_MASK);
  2699. I915_WRITE(WM0_PIPEB_ILK, reg_value);
  2700. DRM_DEBUG_KMS("FIFO watermarks For pipe B - plane %d, "
  2701. "cursor: %d\n", planeb_wm, cursorb_wm);
  2702. }
  2703. /*
  2704. * Calculate and update the self-refresh watermark only when one
  2705. * display plane is used.
  2706. */
  2707. if (!planea_clock || !planeb_clock) {
  2708. int line_count;
  2709. /* Read the self-refresh latency. The unit is 0.5us */
  2710. int ilk_sr_latency = I915_READ(MLTR_ILK) & ILK_SRLT_MASK;
  2711. sr_clock = planea_clock ? planea_clock : planeb_clock;
  2712. line_time_us = ((sr_hdisplay * 1000) / sr_clock);
  2713. /* Use ns/us then divide to preserve precision */
  2714. line_count = ((ilk_sr_latency * 500) / line_time_us + 1000)
  2715. / 1000;
  2716. /* calculate the self-refresh watermark for display plane */
  2717. entries_required = line_count * sr_hdisplay * pixel_size;
  2718. entries_required = DIV_ROUND_UP(entries_required,
  2719. ironlake_display_srwm_info.cacheline_size);
  2720. sr_wm = entries_required +
  2721. ironlake_display_srwm_info.guard_size;
  2722. /* calculate the self-refresh watermark for display cursor */
  2723. entries_required = line_count * pixel_size * 64;
  2724. entries_required = DIV_ROUND_UP(entries_required,
  2725. ironlake_cursor_srwm_info.cacheline_size);
  2726. cursor_wm = entries_required +
  2727. ironlake_cursor_srwm_info.guard_size;
  2728. /* configure watermark and enable self-refresh */
  2729. reg_value = I915_READ(WM1_LP_ILK);
  2730. reg_value &= ~(WM1_LP_LATENCY_MASK | WM1_LP_SR_MASK |
  2731. WM1_LP_CURSOR_MASK);
  2732. reg_value |= WM1_LP_SR_EN |
  2733. (ilk_sr_latency << WM1_LP_LATENCY_SHIFT) |
  2734. (sr_wm << WM1_LP_SR_SHIFT) | cursor_wm;
  2735. I915_WRITE(WM1_LP_ILK, reg_value);
  2736. DRM_DEBUG_KMS("self-refresh watermark: display plane %d "
  2737. "cursor %d\n", sr_wm, cursor_wm);
  2738. } else {
  2739. /* Turn off self refresh if both pipes are enabled */
  2740. I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN);
  2741. }
  2742. }
  2743. /**
  2744. * intel_update_watermarks - update FIFO watermark values based on current modes
  2745. *
  2746. * Calculate watermark values for the various WM regs based on current mode
  2747. * and plane configuration.
  2748. *
  2749. * There are several cases to deal with here:
  2750. * - normal (i.e. non-self-refresh)
  2751. * - self-refresh (SR) mode
  2752. * - lines are large relative to FIFO size (buffer can hold up to 2)
  2753. * - lines are small relative to FIFO size (buffer can hold more than 2
  2754. * lines), so need to account for TLB latency
  2755. *
  2756. * The normal calculation is:
  2757. * watermark = dotclock * bytes per pixel * latency
  2758. * where latency is platform & configuration dependent (we assume pessimal
  2759. * values here).
  2760. *
  2761. * The SR calculation is:
  2762. * watermark = (trunc(latency/line time)+1) * surface width *
  2763. * bytes per pixel
  2764. * where
  2765. * line time = htotal / dotclock
  2766. * and latency is assumed to be high, as above.
  2767. *
  2768. * The final value programmed to the register should always be rounded up,
  2769. * and include an extra 2 entries to account for clock crossings.
  2770. *
  2771. * We don't use the sprite, so we can ignore that. And on Crestline we have
  2772. * to set the non-SR watermarks to 8.
  2773. */
  2774. static void intel_update_watermarks(struct drm_device *dev)
  2775. {
  2776. struct drm_i915_private *dev_priv = dev->dev_private;
  2777. struct drm_crtc *crtc;
  2778. struct intel_crtc *intel_crtc;
  2779. int sr_hdisplay = 0;
  2780. unsigned long planea_clock = 0, planeb_clock = 0, sr_clock = 0;
  2781. int enabled = 0, pixel_size = 0;
  2782. if (!dev_priv->display.update_wm)
  2783. return;
  2784. /* Get the clock config from both planes */
  2785. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  2786. intel_crtc = to_intel_crtc(crtc);
  2787. if (crtc->enabled) {
  2788. enabled++;
  2789. if (intel_crtc->plane == 0) {
  2790. DRM_DEBUG_KMS("plane A (pipe %d) clock: %d\n",
  2791. intel_crtc->pipe, crtc->mode.clock);
  2792. planea_clock = crtc->mode.clock;
  2793. } else {
  2794. DRM_DEBUG_KMS("plane B (pipe %d) clock: %d\n",
  2795. intel_crtc->pipe, crtc->mode.clock);
  2796. planeb_clock = crtc->mode.clock;
  2797. }
  2798. sr_hdisplay = crtc->mode.hdisplay;
  2799. sr_clock = crtc->mode.clock;
  2800. if (crtc->fb)
  2801. pixel_size = crtc->fb->bits_per_pixel / 8;
  2802. else
  2803. pixel_size = 4; /* by default */
  2804. }
  2805. }
  2806. if (enabled <= 0)
  2807. return;
  2808. dev_priv->display.update_wm(dev, planea_clock, planeb_clock,
  2809. sr_hdisplay, pixel_size);
  2810. }
  2811. static int intel_crtc_mode_set(struct drm_crtc *crtc,
  2812. struct drm_display_mode *mode,
  2813. struct drm_display_mode *adjusted_mode,
  2814. int x, int y,
  2815. struct drm_framebuffer *old_fb)
  2816. {
  2817. struct drm_device *dev = crtc->dev;
  2818. struct drm_i915_private *dev_priv = dev->dev_private;
  2819. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2820. int pipe = intel_crtc->pipe;
  2821. int plane = intel_crtc->plane;
  2822. int fp_reg = (pipe == 0) ? FPA0 : FPB0;
  2823. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  2824. int dpll_md_reg = (intel_crtc->pipe == 0) ? DPLL_A_MD : DPLL_B_MD;
  2825. int dspcntr_reg = (plane == 0) ? DSPACNTR : DSPBCNTR;
  2826. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  2827. int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
  2828. int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
  2829. int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
  2830. int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
  2831. int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
  2832. int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
  2833. int dspsize_reg = (plane == 0) ? DSPASIZE : DSPBSIZE;
  2834. int dsppos_reg = (plane == 0) ? DSPAPOS : DSPBPOS;
  2835. int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC;
  2836. int refclk, num_connectors = 0;
  2837. intel_clock_t clock, reduced_clock;
  2838. u32 dpll = 0, fp = 0, fp2 = 0, dspcntr, pipeconf;
  2839. bool ok, has_reduced_clock = false, is_sdvo = false, is_dvo = false;
  2840. bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false;
  2841. bool is_edp = false;
  2842. struct drm_mode_config *mode_config = &dev->mode_config;
  2843. struct drm_encoder *encoder;
  2844. struct intel_encoder *intel_encoder = NULL;
  2845. const intel_limit_t *limit;
  2846. int ret;
  2847. struct fdi_m_n m_n = {0};
  2848. int data_m1_reg = (pipe == 0) ? PIPEA_DATA_M1 : PIPEB_DATA_M1;
  2849. int data_n1_reg = (pipe == 0) ? PIPEA_DATA_N1 : PIPEB_DATA_N1;
  2850. int link_m1_reg = (pipe == 0) ? PIPEA_LINK_M1 : PIPEB_LINK_M1;
  2851. int link_n1_reg = (pipe == 0) ? PIPEA_LINK_N1 : PIPEB_LINK_N1;
  2852. int pch_fp_reg = (pipe == 0) ? PCH_FPA0 : PCH_FPB0;
  2853. int pch_dpll_reg = (pipe == 0) ? PCH_DPLL_A : PCH_DPLL_B;
  2854. int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL;
  2855. int fdi_tx_reg = (pipe == 0) ? FDI_TXA_CTL : FDI_TXB_CTL;
  2856. int trans_dpll_sel = (pipe == 0) ? 0 : 1;
  2857. int lvds_reg = LVDS;
  2858. u32 temp;
  2859. int sdvo_pixel_multiply;
  2860. int target_clock;
  2861. drm_vblank_pre_modeset(dev, pipe);
  2862. list_for_each_entry(encoder, &mode_config->encoder_list, head) {
  2863. if (!encoder || encoder->crtc != crtc)
  2864. continue;
  2865. intel_encoder = enc_to_intel_encoder(encoder);
  2866. switch (intel_encoder->type) {
  2867. case INTEL_OUTPUT_LVDS:
  2868. is_lvds = true;
  2869. break;
  2870. case INTEL_OUTPUT_SDVO:
  2871. case INTEL_OUTPUT_HDMI:
  2872. is_sdvo = true;
  2873. if (intel_encoder->needs_tv_clock)
  2874. is_tv = true;
  2875. break;
  2876. case INTEL_OUTPUT_DVO:
  2877. is_dvo = true;
  2878. break;
  2879. case INTEL_OUTPUT_TVOUT:
  2880. is_tv = true;
  2881. break;
  2882. case INTEL_OUTPUT_ANALOG:
  2883. is_crt = true;
  2884. break;
  2885. case INTEL_OUTPUT_DISPLAYPORT:
  2886. is_dp = true;
  2887. break;
  2888. case INTEL_OUTPUT_EDP:
  2889. is_edp = true;
  2890. break;
  2891. }
  2892. num_connectors++;
  2893. }
  2894. if (is_lvds && dev_priv->lvds_use_ssc && num_connectors < 2) {
  2895. refclk = dev_priv->lvds_ssc_freq * 1000;
  2896. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  2897. refclk / 1000);
  2898. } else if (IS_I9XX(dev)) {
  2899. refclk = 96000;
  2900. if (HAS_PCH_SPLIT(dev))
  2901. refclk = 120000; /* 120Mhz refclk */
  2902. } else {
  2903. refclk = 48000;
  2904. }
  2905. /*
  2906. * Returns a set of divisors for the desired target clock with the given
  2907. * refclk, or FALSE. The returned values represent the clock equation:
  2908. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  2909. */
  2910. limit = intel_limit(crtc);
  2911. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, &clock);
  2912. if (!ok) {
  2913. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  2914. drm_vblank_post_modeset(dev, pipe);
  2915. return -EINVAL;
  2916. }
  2917. if (is_lvds && dev_priv->lvds_downclock_avail) {
  2918. has_reduced_clock = limit->find_pll(limit, crtc,
  2919. dev_priv->lvds_downclock,
  2920. refclk,
  2921. &reduced_clock);
  2922. if (has_reduced_clock && (clock.p != reduced_clock.p)) {
  2923. /*
  2924. * If the different P is found, it means that we can't
  2925. * switch the display clock by using the FP0/FP1.
  2926. * In such case we will disable the LVDS downclock
  2927. * feature.
  2928. */
  2929. DRM_DEBUG_KMS("Different P is found for "
  2930. "LVDS clock/downclock\n");
  2931. has_reduced_clock = 0;
  2932. }
  2933. }
  2934. /* SDVO TV has fixed PLL values depend on its clock range,
  2935. this mirrors vbios setting. */
  2936. if (is_sdvo && is_tv) {
  2937. if (adjusted_mode->clock >= 100000
  2938. && adjusted_mode->clock < 140500) {
  2939. clock.p1 = 2;
  2940. clock.p2 = 10;
  2941. clock.n = 3;
  2942. clock.m1 = 16;
  2943. clock.m2 = 8;
  2944. } else if (adjusted_mode->clock >= 140500
  2945. && adjusted_mode->clock <= 200000) {
  2946. clock.p1 = 1;
  2947. clock.p2 = 10;
  2948. clock.n = 6;
  2949. clock.m1 = 12;
  2950. clock.m2 = 8;
  2951. }
  2952. }
  2953. /* FDI link */
  2954. if (HAS_PCH_SPLIT(dev)) {
  2955. int lane, link_bw, bpp;
  2956. /* eDP doesn't require FDI link, so just set DP M/N
  2957. according to current link config */
  2958. if (is_edp) {
  2959. target_clock = mode->clock;
  2960. intel_edp_link_config(intel_encoder,
  2961. &lane, &link_bw);
  2962. } else {
  2963. /* DP over FDI requires target mode clock
  2964. instead of link clock */
  2965. if (is_dp)
  2966. target_clock = mode->clock;
  2967. else
  2968. target_clock = adjusted_mode->clock;
  2969. lane = 4;
  2970. link_bw = 270000;
  2971. }
  2972. /* determine panel color depth */
  2973. temp = I915_READ(pipeconf_reg);
  2974. temp &= ~PIPE_BPC_MASK;
  2975. if (is_lvds) {
  2976. int lvds_reg = I915_READ(PCH_LVDS);
  2977. /* the BPC will be 6 if it is 18-bit LVDS panel */
  2978. if ((lvds_reg & LVDS_A3_POWER_MASK) == LVDS_A3_POWER_UP)
  2979. temp |= PIPE_8BPC;
  2980. else
  2981. temp |= PIPE_6BPC;
  2982. } else if (is_edp) {
  2983. switch (dev_priv->edp_bpp/3) {
  2984. case 8:
  2985. temp |= PIPE_8BPC;
  2986. break;
  2987. case 10:
  2988. temp |= PIPE_10BPC;
  2989. break;
  2990. case 6:
  2991. temp |= PIPE_6BPC;
  2992. break;
  2993. case 12:
  2994. temp |= PIPE_12BPC;
  2995. break;
  2996. }
  2997. } else
  2998. temp |= PIPE_8BPC;
  2999. I915_WRITE(pipeconf_reg, temp);
  3000. I915_READ(pipeconf_reg);
  3001. switch (temp & PIPE_BPC_MASK) {
  3002. case PIPE_8BPC:
  3003. bpp = 24;
  3004. break;
  3005. case PIPE_10BPC:
  3006. bpp = 30;
  3007. break;
  3008. case PIPE_6BPC:
  3009. bpp = 18;
  3010. break;
  3011. case PIPE_12BPC:
  3012. bpp = 36;
  3013. break;
  3014. default:
  3015. DRM_ERROR("unknown pipe bpc value\n");
  3016. bpp = 24;
  3017. }
  3018. ironlake_compute_m_n(bpp, lane, target_clock, link_bw, &m_n);
  3019. }
  3020. /* Ironlake: try to setup display ref clock before DPLL
  3021. * enabling. This is only under driver's control after
  3022. * PCH B stepping, previous chipset stepping should be
  3023. * ignoring this setting.
  3024. */
  3025. if (HAS_PCH_SPLIT(dev)) {
  3026. temp = I915_READ(PCH_DREF_CONTROL);
  3027. /* Always enable nonspread source */
  3028. temp &= ~DREF_NONSPREAD_SOURCE_MASK;
  3029. temp |= DREF_NONSPREAD_SOURCE_ENABLE;
  3030. I915_WRITE(PCH_DREF_CONTROL, temp);
  3031. POSTING_READ(PCH_DREF_CONTROL);
  3032. temp &= ~DREF_SSC_SOURCE_MASK;
  3033. temp |= DREF_SSC_SOURCE_ENABLE;
  3034. I915_WRITE(PCH_DREF_CONTROL, temp);
  3035. POSTING_READ(PCH_DREF_CONTROL);
  3036. udelay(200);
  3037. if (is_edp) {
  3038. if (dev_priv->lvds_use_ssc) {
  3039. temp |= DREF_SSC1_ENABLE;
  3040. I915_WRITE(PCH_DREF_CONTROL, temp);
  3041. POSTING_READ(PCH_DREF_CONTROL);
  3042. udelay(200);
  3043. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  3044. temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  3045. I915_WRITE(PCH_DREF_CONTROL, temp);
  3046. POSTING_READ(PCH_DREF_CONTROL);
  3047. } else {
  3048. temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  3049. I915_WRITE(PCH_DREF_CONTROL, temp);
  3050. POSTING_READ(PCH_DREF_CONTROL);
  3051. }
  3052. }
  3053. }
  3054. if (IS_PINEVIEW(dev)) {
  3055. fp = (1 << clock.n) << 16 | clock.m1 << 8 | clock.m2;
  3056. if (has_reduced_clock)
  3057. fp2 = (1 << reduced_clock.n) << 16 |
  3058. reduced_clock.m1 << 8 | reduced_clock.m2;
  3059. } else {
  3060. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  3061. if (has_reduced_clock)
  3062. fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
  3063. reduced_clock.m2;
  3064. }
  3065. if (!HAS_PCH_SPLIT(dev))
  3066. dpll = DPLL_VGA_MODE_DIS;
  3067. if (IS_I9XX(dev)) {
  3068. if (is_lvds)
  3069. dpll |= DPLLB_MODE_LVDS;
  3070. else
  3071. dpll |= DPLLB_MODE_DAC_SERIAL;
  3072. if (is_sdvo) {
  3073. dpll |= DPLL_DVO_HIGH_SPEED;
  3074. sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  3075. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  3076. dpll |= (sdvo_pixel_multiply - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  3077. else if (HAS_PCH_SPLIT(dev))
  3078. dpll |= (sdvo_pixel_multiply - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  3079. }
  3080. if (is_dp)
  3081. dpll |= DPLL_DVO_HIGH_SPEED;
  3082. /* compute bitmask from p1 value */
  3083. if (IS_PINEVIEW(dev))
  3084. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  3085. else {
  3086. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3087. /* also FPA1 */
  3088. if (HAS_PCH_SPLIT(dev))
  3089. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  3090. if (IS_G4X(dev) && has_reduced_clock)
  3091. dpll |= (1 << (reduced_clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  3092. }
  3093. switch (clock.p2) {
  3094. case 5:
  3095. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  3096. break;
  3097. case 7:
  3098. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  3099. break;
  3100. case 10:
  3101. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  3102. break;
  3103. case 14:
  3104. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  3105. break;
  3106. }
  3107. if (IS_I965G(dev) && !HAS_PCH_SPLIT(dev))
  3108. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  3109. } else {
  3110. if (is_lvds) {
  3111. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3112. } else {
  3113. if (clock.p1 == 2)
  3114. dpll |= PLL_P1_DIVIDE_BY_TWO;
  3115. else
  3116. dpll |= (clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3117. if (clock.p2 == 4)
  3118. dpll |= PLL_P2_DIVIDE_BY_4;
  3119. }
  3120. }
  3121. if (is_sdvo && is_tv)
  3122. dpll |= PLL_REF_INPUT_TVCLKINBC;
  3123. else if (is_tv)
  3124. /* XXX: just matching BIOS for now */
  3125. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  3126. dpll |= 3;
  3127. else if (is_lvds && dev_priv->lvds_use_ssc && num_connectors < 2)
  3128. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  3129. else
  3130. dpll |= PLL_REF_INPUT_DREFCLK;
  3131. /* setup pipeconf */
  3132. pipeconf = I915_READ(pipeconf_reg);
  3133. /* Set up the display plane register */
  3134. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3135. /* Ironlake's plane is forced to pipe, bit 24 is to
  3136. enable color space conversion */
  3137. if (!HAS_PCH_SPLIT(dev)) {
  3138. if (pipe == 0)
  3139. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  3140. else
  3141. dspcntr |= DISPPLANE_SEL_PIPE_B;
  3142. }
  3143. if (pipe == 0 && !IS_I965G(dev)) {
  3144. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  3145. * core speed.
  3146. *
  3147. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  3148. * pipe == 0 check?
  3149. */
  3150. if (mode->clock >
  3151. dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
  3152. pipeconf |= PIPEACONF_DOUBLE_WIDE;
  3153. else
  3154. pipeconf &= ~PIPEACONF_DOUBLE_WIDE;
  3155. }
  3156. /* Disable the panel fitter if it was on our pipe */
  3157. if (!HAS_PCH_SPLIT(dev) && intel_panel_fitter_pipe(dev) == pipe)
  3158. I915_WRITE(PFIT_CONTROL, 0);
  3159. DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  3160. drm_mode_debug_printmodeline(mode);
  3161. /* assign to Ironlake registers */
  3162. if (HAS_PCH_SPLIT(dev)) {
  3163. fp_reg = pch_fp_reg;
  3164. dpll_reg = pch_dpll_reg;
  3165. }
  3166. if (is_edp) {
  3167. ironlake_disable_pll_edp(crtc);
  3168. } else if ((dpll & DPLL_VCO_ENABLE)) {
  3169. I915_WRITE(fp_reg, fp);
  3170. I915_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE);
  3171. I915_READ(dpll_reg);
  3172. udelay(150);
  3173. }
  3174. /* enable transcoder DPLL */
  3175. if (HAS_PCH_CPT(dev)) {
  3176. temp = I915_READ(PCH_DPLL_SEL);
  3177. if (trans_dpll_sel == 0)
  3178. temp |= (TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL);
  3179. else
  3180. temp |= (TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  3181. I915_WRITE(PCH_DPLL_SEL, temp);
  3182. I915_READ(PCH_DPLL_SEL);
  3183. udelay(150);
  3184. }
  3185. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  3186. * This is an exception to the general rule that mode_set doesn't turn
  3187. * things on.
  3188. */
  3189. if (is_lvds) {
  3190. u32 lvds;
  3191. if (HAS_PCH_SPLIT(dev))
  3192. lvds_reg = PCH_LVDS;
  3193. lvds = I915_READ(lvds_reg);
  3194. lvds |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  3195. if (pipe == 1) {
  3196. if (HAS_PCH_CPT(dev))
  3197. lvds |= PORT_TRANS_B_SEL_CPT;
  3198. else
  3199. lvds |= LVDS_PIPEB_SELECT;
  3200. } else {
  3201. if (HAS_PCH_CPT(dev))
  3202. lvds &= ~PORT_TRANS_SEL_MASK;
  3203. else
  3204. lvds &= ~LVDS_PIPEB_SELECT;
  3205. }
  3206. /* set the corresponsding LVDS_BORDER bit */
  3207. lvds |= dev_priv->lvds_border_bits;
  3208. /* Set the B0-B3 data pairs corresponding to whether we're going to
  3209. * set the DPLLs for dual-channel mode or not.
  3210. */
  3211. if (clock.p2 == 7)
  3212. lvds |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  3213. else
  3214. lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  3215. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  3216. * appropriately here, but we need to look more thoroughly into how
  3217. * panels behave in the two modes.
  3218. */
  3219. /* set the dithering flag */
  3220. if (IS_I965G(dev)) {
  3221. if (dev_priv->lvds_dither) {
  3222. if (HAS_PCH_SPLIT(dev))
  3223. pipeconf |= PIPE_ENABLE_DITHER;
  3224. else
  3225. lvds |= LVDS_ENABLE_DITHER;
  3226. } else {
  3227. if (HAS_PCH_SPLIT(dev))
  3228. pipeconf &= ~PIPE_ENABLE_DITHER;
  3229. else
  3230. lvds &= ~LVDS_ENABLE_DITHER;
  3231. }
  3232. }
  3233. I915_WRITE(lvds_reg, lvds);
  3234. I915_READ(lvds_reg);
  3235. }
  3236. if (is_dp)
  3237. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  3238. else if (HAS_PCH_SPLIT(dev)) {
  3239. /* For non-DP output, clear any trans DP clock recovery setting.*/
  3240. if (pipe == 0) {
  3241. I915_WRITE(TRANSA_DATA_M1, 0);
  3242. I915_WRITE(TRANSA_DATA_N1, 0);
  3243. I915_WRITE(TRANSA_DP_LINK_M1, 0);
  3244. I915_WRITE(TRANSA_DP_LINK_N1, 0);
  3245. } else {
  3246. I915_WRITE(TRANSB_DATA_M1, 0);
  3247. I915_WRITE(TRANSB_DATA_N1, 0);
  3248. I915_WRITE(TRANSB_DP_LINK_M1, 0);
  3249. I915_WRITE(TRANSB_DP_LINK_N1, 0);
  3250. }
  3251. }
  3252. if (!is_edp) {
  3253. I915_WRITE(fp_reg, fp);
  3254. I915_WRITE(dpll_reg, dpll);
  3255. I915_READ(dpll_reg);
  3256. /* Wait for the clocks to stabilize. */
  3257. udelay(150);
  3258. if (IS_I965G(dev) && !HAS_PCH_SPLIT(dev)) {
  3259. if (is_sdvo) {
  3260. sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  3261. I915_WRITE(dpll_md_reg, (0 << DPLL_MD_UDI_DIVIDER_SHIFT) |
  3262. ((sdvo_pixel_multiply - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT));
  3263. } else
  3264. I915_WRITE(dpll_md_reg, 0);
  3265. } else {
  3266. /* write it again -- the BIOS does, after all */
  3267. I915_WRITE(dpll_reg, dpll);
  3268. }
  3269. I915_READ(dpll_reg);
  3270. /* Wait for the clocks to stabilize. */
  3271. udelay(150);
  3272. }
  3273. if (is_lvds && has_reduced_clock && i915_powersave) {
  3274. I915_WRITE(fp_reg + 4, fp2);
  3275. intel_crtc->lowfreq_avail = true;
  3276. if (HAS_PIPE_CXSR(dev)) {
  3277. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  3278. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  3279. }
  3280. } else {
  3281. I915_WRITE(fp_reg + 4, fp);
  3282. intel_crtc->lowfreq_avail = false;
  3283. if (HAS_PIPE_CXSR(dev)) {
  3284. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  3285. pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
  3286. }
  3287. }
  3288. I915_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) |
  3289. ((adjusted_mode->crtc_htotal - 1) << 16));
  3290. I915_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) |
  3291. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  3292. I915_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) |
  3293. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  3294. I915_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) |
  3295. ((adjusted_mode->crtc_vtotal - 1) << 16));
  3296. I915_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) |
  3297. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  3298. I915_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) |
  3299. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  3300. /* pipesrc and dspsize control the size that is scaled from, which should
  3301. * always be the user's requested size.
  3302. */
  3303. if (!HAS_PCH_SPLIT(dev)) {
  3304. I915_WRITE(dspsize_reg, ((mode->vdisplay - 1) << 16) |
  3305. (mode->hdisplay - 1));
  3306. I915_WRITE(dsppos_reg, 0);
  3307. }
  3308. I915_WRITE(pipesrc_reg, ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  3309. if (HAS_PCH_SPLIT(dev)) {
  3310. I915_WRITE(data_m1_reg, TU_SIZE(m_n.tu) | m_n.gmch_m);
  3311. I915_WRITE(data_n1_reg, TU_SIZE(m_n.tu) | m_n.gmch_n);
  3312. I915_WRITE(link_m1_reg, m_n.link_m);
  3313. I915_WRITE(link_n1_reg, m_n.link_n);
  3314. if (is_edp) {
  3315. ironlake_set_pll_edp(crtc, adjusted_mode->clock);
  3316. } else {
  3317. /* enable FDI RX PLL too */
  3318. temp = I915_READ(fdi_rx_reg);
  3319. I915_WRITE(fdi_rx_reg, temp | FDI_RX_PLL_ENABLE);
  3320. I915_READ(fdi_rx_reg);
  3321. udelay(200);
  3322. /* enable FDI TX PLL too */
  3323. temp = I915_READ(fdi_tx_reg);
  3324. I915_WRITE(fdi_tx_reg, temp | FDI_TX_PLL_ENABLE);
  3325. I915_READ(fdi_tx_reg);
  3326. /* enable FDI RX PCDCLK */
  3327. temp = I915_READ(fdi_rx_reg);
  3328. I915_WRITE(fdi_rx_reg, temp | FDI_SEL_PCDCLK);
  3329. I915_READ(fdi_rx_reg);
  3330. udelay(200);
  3331. }
  3332. }
  3333. I915_WRITE(pipeconf_reg, pipeconf);
  3334. I915_READ(pipeconf_reg);
  3335. intel_wait_for_vblank(dev);
  3336. if (IS_IRONLAKE(dev)) {
  3337. /* enable address swizzle for tiling buffer */
  3338. temp = I915_READ(DISP_ARB_CTL);
  3339. I915_WRITE(DISP_ARB_CTL, temp | DISP_TILE_SURFACE_SWIZZLING);
  3340. }
  3341. I915_WRITE(dspcntr_reg, dspcntr);
  3342. /* Flush the plane changes */
  3343. ret = intel_pipe_set_base(crtc, x, y, old_fb);
  3344. if ((IS_I965G(dev) || plane == 0))
  3345. intel_update_fbc(crtc, &crtc->mode);
  3346. intel_update_watermarks(dev);
  3347. drm_vblank_post_modeset(dev, pipe);
  3348. return ret;
  3349. }
  3350. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  3351. void intel_crtc_load_lut(struct drm_crtc *crtc)
  3352. {
  3353. struct drm_device *dev = crtc->dev;
  3354. struct drm_i915_private *dev_priv = dev->dev_private;
  3355. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3356. int palreg = (intel_crtc->pipe == 0) ? PALETTE_A : PALETTE_B;
  3357. int i;
  3358. /* The clocks have to be on to load the palette. */
  3359. if (!crtc->enabled)
  3360. return;
  3361. /* use legacy palette for Ironlake */
  3362. if (HAS_PCH_SPLIT(dev))
  3363. palreg = (intel_crtc->pipe == 0) ? LGC_PALETTE_A :
  3364. LGC_PALETTE_B;
  3365. for (i = 0; i < 256; i++) {
  3366. I915_WRITE(palreg + 4 * i,
  3367. (intel_crtc->lut_r[i] << 16) |
  3368. (intel_crtc->lut_g[i] << 8) |
  3369. intel_crtc->lut_b[i]);
  3370. }
  3371. }
  3372. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  3373. struct drm_file *file_priv,
  3374. uint32_t handle,
  3375. uint32_t width, uint32_t height)
  3376. {
  3377. struct drm_device *dev = crtc->dev;
  3378. struct drm_i915_private *dev_priv = dev->dev_private;
  3379. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3380. struct drm_gem_object *bo;
  3381. struct drm_i915_gem_object *obj_priv;
  3382. int pipe = intel_crtc->pipe;
  3383. uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR;
  3384. uint32_t base = (pipe == 0) ? CURABASE : CURBBASE;
  3385. uint32_t temp = I915_READ(control);
  3386. size_t addr;
  3387. int ret;
  3388. DRM_DEBUG_KMS("\n");
  3389. /* if we want to turn off the cursor ignore width and height */
  3390. if (!handle) {
  3391. DRM_DEBUG_KMS("cursor off\n");
  3392. if (IS_MOBILE(dev) || IS_I9XX(dev)) {
  3393. temp &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  3394. temp |= CURSOR_MODE_DISABLE;
  3395. } else {
  3396. temp &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
  3397. }
  3398. addr = 0;
  3399. bo = NULL;
  3400. mutex_lock(&dev->struct_mutex);
  3401. goto finish;
  3402. }
  3403. /* Currently we only support 64x64 cursors */
  3404. if (width != 64 || height != 64) {
  3405. DRM_ERROR("we currently only support 64x64 cursors\n");
  3406. return -EINVAL;
  3407. }
  3408. bo = drm_gem_object_lookup(dev, file_priv, handle);
  3409. if (!bo)
  3410. return -ENOENT;
  3411. obj_priv = to_intel_bo(bo);
  3412. if (bo->size < width * height * 4) {
  3413. DRM_ERROR("buffer is to small\n");
  3414. ret = -ENOMEM;
  3415. goto fail;
  3416. }
  3417. /* we only need to pin inside GTT if cursor is non-phy */
  3418. mutex_lock(&dev->struct_mutex);
  3419. if (!dev_priv->info->cursor_needs_physical) {
  3420. ret = i915_gem_object_pin(bo, PAGE_SIZE);
  3421. if (ret) {
  3422. DRM_ERROR("failed to pin cursor bo\n");
  3423. goto fail_locked;
  3424. }
  3425. addr = obj_priv->gtt_offset;
  3426. } else {
  3427. ret = i915_gem_attach_phys_object(dev, bo, (pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1);
  3428. if (ret) {
  3429. DRM_ERROR("failed to attach phys object\n");
  3430. goto fail_locked;
  3431. }
  3432. addr = obj_priv->phys_obj->handle->busaddr;
  3433. }
  3434. if (!IS_I9XX(dev))
  3435. I915_WRITE(CURSIZE, (height << 12) | width);
  3436. /* Hooray for CUR*CNTR differences */
  3437. if (IS_MOBILE(dev) || IS_I9XX(dev)) {
  3438. temp &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
  3439. temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  3440. temp |= (pipe << 28); /* Connect to correct pipe */
  3441. } else {
  3442. temp &= ~(CURSOR_FORMAT_MASK);
  3443. temp |= CURSOR_ENABLE;
  3444. temp |= CURSOR_FORMAT_ARGB | CURSOR_GAMMA_ENABLE;
  3445. }
  3446. finish:
  3447. I915_WRITE(control, temp);
  3448. I915_WRITE(base, addr);
  3449. if (intel_crtc->cursor_bo) {
  3450. if (dev_priv->info->cursor_needs_physical) {
  3451. if (intel_crtc->cursor_bo != bo)
  3452. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  3453. } else
  3454. i915_gem_object_unpin(intel_crtc->cursor_bo);
  3455. drm_gem_object_unreference(intel_crtc->cursor_bo);
  3456. }
  3457. mutex_unlock(&dev->struct_mutex);
  3458. intel_crtc->cursor_addr = addr;
  3459. intel_crtc->cursor_bo = bo;
  3460. return 0;
  3461. fail_locked:
  3462. mutex_unlock(&dev->struct_mutex);
  3463. fail:
  3464. drm_gem_object_unreference_unlocked(bo);
  3465. return ret;
  3466. }
  3467. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  3468. {
  3469. struct drm_device *dev = crtc->dev;
  3470. struct drm_i915_private *dev_priv = dev->dev_private;
  3471. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3472. struct intel_framebuffer *intel_fb;
  3473. int pipe = intel_crtc->pipe;
  3474. uint32_t temp = 0;
  3475. uint32_t adder;
  3476. if (crtc->fb) {
  3477. intel_fb = to_intel_framebuffer(crtc->fb);
  3478. intel_mark_busy(dev, intel_fb->obj);
  3479. }
  3480. if (x < 0) {
  3481. temp |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  3482. x = -x;
  3483. }
  3484. if (y < 0) {
  3485. temp |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  3486. y = -y;
  3487. }
  3488. temp |= x << CURSOR_X_SHIFT;
  3489. temp |= y << CURSOR_Y_SHIFT;
  3490. adder = intel_crtc->cursor_addr;
  3491. I915_WRITE((pipe == 0) ? CURAPOS : CURBPOS, temp);
  3492. I915_WRITE((pipe == 0) ? CURABASE : CURBBASE, adder);
  3493. return 0;
  3494. }
  3495. /** Sets the color ramps on behalf of RandR */
  3496. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  3497. u16 blue, int regno)
  3498. {
  3499. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3500. intel_crtc->lut_r[regno] = red >> 8;
  3501. intel_crtc->lut_g[regno] = green >> 8;
  3502. intel_crtc->lut_b[regno] = blue >> 8;
  3503. }
  3504. void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  3505. u16 *blue, int regno)
  3506. {
  3507. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3508. *red = intel_crtc->lut_r[regno] << 8;
  3509. *green = intel_crtc->lut_g[regno] << 8;
  3510. *blue = intel_crtc->lut_b[regno] << 8;
  3511. }
  3512. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  3513. u16 *blue, uint32_t size)
  3514. {
  3515. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3516. int i;
  3517. if (size != 256)
  3518. return;
  3519. for (i = 0; i < 256; i++) {
  3520. intel_crtc->lut_r[i] = red[i] >> 8;
  3521. intel_crtc->lut_g[i] = green[i] >> 8;
  3522. intel_crtc->lut_b[i] = blue[i] >> 8;
  3523. }
  3524. intel_crtc_load_lut(crtc);
  3525. }
  3526. /**
  3527. * Get a pipe with a simple mode set on it for doing load-based monitor
  3528. * detection.
  3529. *
  3530. * It will be up to the load-detect code to adjust the pipe as appropriate for
  3531. * its requirements. The pipe will be connected to no other encoders.
  3532. *
  3533. * Currently this code will only succeed if there is a pipe with no encoders
  3534. * configured for it. In the future, it could choose to temporarily disable
  3535. * some outputs to free up a pipe for its use.
  3536. *
  3537. * \return crtc, or NULL if no pipes are available.
  3538. */
  3539. /* VESA 640x480x72Hz mode to set on the pipe */
  3540. static struct drm_display_mode load_detect_mode = {
  3541. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  3542. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  3543. };
  3544. struct drm_crtc *intel_get_load_detect_pipe(struct intel_encoder *intel_encoder,
  3545. struct drm_connector *connector,
  3546. struct drm_display_mode *mode,
  3547. int *dpms_mode)
  3548. {
  3549. struct intel_crtc *intel_crtc;
  3550. struct drm_crtc *possible_crtc;
  3551. struct drm_crtc *supported_crtc =NULL;
  3552. struct drm_encoder *encoder = &intel_encoder->enc;
  3553. struct drm_crtc *crtc = NULL;
  3554. struct drm_device *dev = encoder->dev;
  3555. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  3556. struct drm_crtc_helper_funcs *crtc_funcs;
  3557. int i = -1;
  3558. /*
  3559. * Algorithm gets a little messy:
  3560. * - if the connector already has an assigned crtc, use it (but make
  3561. * sure it's on first)
  3562. * - try to find the first unused crtc that can drive this connector,
  3563. * and use that if we find one
  3564. * - if there are no unused crtcs available, try to use the first
  3565. * one we found that supports the connector
  3566. */
  3567. /* See if we already have a CRTC for this connector */
  3568. if (encoder->crtc) {
  3569. crtc = encoder->crtc;
  3570. /* Make sure the crtc and connector are running */
  3571. intel_crtc = to_intel_crtc(crtc);
  3572. *dpms_mode = intel_crtc->dpms_mode;
  3573. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  3574. crtc_funcs = crtc->helper_private;
  3575. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  3576. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  3577. }
  3578. return crtc;
  3579. }
  3580. /* Find an unused one (if possible) */
  3581. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  3582. i++;
  3583. if (!(encoder->possible_crtcs & (1 << i)))
  3584. continue;
  3585. if (!possible_crtc->enabled) {
  3586. crtc = possible_crtc;
  3587. break;
  3588. }
  3589. if (!supported_crtc)
  3590. supported_crtc = possible_crtc;
  3591. }
  3592. /*
  3593. * If we didn't find an unused CRTC, don't use any.
  3594. */
  3595. if (!crtc) {
  3596. return NULL;
  3597. }
  3598. encoder->crtc = crtc;
  3599. connector->encoder = encoder;
  3600. intel_encoder->load_detect_temp = true;
  3601. intel_crtc = to_intel_crtc(crtc);
  3602. *dpms_mode = intel_crtc->dpms_mode;
  3603. if (!crtc->enabled) {
  3604. if (!mode)
  3605. mode = &load_detect_mode;
  3606. drm_crtc_helper_set_mode(crtc, mode, 0, 0, crtc->fb);
  3607. } else {
  3608. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  3609. crtc_funcs = crtc->helper_private;
  3610. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  3611. }
  3612. /* Add this connector to the crtc */
  3613. encoder_funcs->mode_set(encoder, &crtc->mode, &crtc->mode);
  3614. encoder_funcs->commit(encoder);
  3615. }
  3616. /* let the connector get through one full cycle before testing */
  3617. intel_wait_for_vblank(dev);
  3618. return crtc;
  3619. }
  3620. void intel_release_load_detect_pipe(struct intel_encoder *intel_encoder,
  3621. struct drm_connector *connector, int dpms_mode)
  3622. {
  3623. struct drm_encoder *encoder = &intel_encoder->enc;
  3624. struct drm_device *dev = encoder->dev;
  3625. struct drm_crtc *crtc = encoder->crtc;
  3626. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  3627. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  3628. if (intel_encoder->load_detect_temp) {
  3629. encoder->crtc = NULL;
  3630. connector->encoder = NULL;
  3631. intel_encoder->load_detect_temp = false;
  3632. crtc->enabled = drm_helper_crtc_in_use(crtc);
  3633. drm_helper_disable_unused_functions(dev);
  3634. }
  3635. /* Switch crtc and encoder back off if necessary */
  3636. if (crtc->enabled && dpms_mode != DRM_MODE_DPMS_ON) {
  3637. if (encoder->crtc == crtc)
  3638. encoder_funcs->dpms(encoder, dpms_mode);
  3639. crtc_funcs->dpms(crtc, dpms_mode);
  3640. }
  3641. }
  3642. /* Returns the clock of the currently programmed mode of the given pipe. */
  3643. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  3644. {
  3645. struct drm_i915_private *dev_priv = dev->dev_private;
  3646. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3647. int pipe = intel_crtc->pipe;
  3648. u32 dpll = I915_READ((pipe == 0) ? DPLL_A : DPLL_B);
  3649. u32 fp;
  3650. intel_clock_t clock;
  3651. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  3652. fp = I915_READ((pipe == 0) ? FPA0 : FPB0);
  3653. else
  3654. fp = I915_READ((pipe == 0) ? FPA1 : FPB1);
  3655. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  3656. if (IS_PINEVIEW(dev)) {
  3657. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  3658. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  3659. } else {
  3660. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  3661. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  3662. }
  3663. if (IS_I9XX(dev)) {
  3664. if (IS_PINEVIEW(dev))
  3665. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  3666. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  3667. else
  3668. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  3669. DPLL_FPA01_P1_POST_DIV_SHIFT);
  3670. switch (dpll & DPLL_MODE_MASK) {
  3671. case DPLLB_MODE_DAC_SERIAL:
  3672. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  3673. 5 : 10;
  3674. break;
  3675. case DPLLB_MODE_LVDS:
  3676. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  3677. 7 : 14;
  3678. break;
  3679. default:
  3680. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  3681. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  3682. return 0;
  3683. }
  3684. /* XXX: Handle the 100Mhz refclk */
  3685. intel_clock(dev, 96000, &clock);
  3686. } else {
  3687. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  3688. if (is_lvds) {
  3689. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  3690. DPLL_FPA01_P1_POST_DIV_SHIFT);
  3691. clock.p2 = 14;
  3692. if ((dpll & PLL_REF_INPUT_MASK) ==
  3693. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  3694. /* XXX: might not be 66MHz */
  3695. intel_clock(dev, 66000, &clock);
  3696. } else
  3697. intel_clock(dev, 48000, &clock);
  3698. } else {
  3699. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  3700. clock.p1 = 2;
  3701. else {
  3702. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  3703. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  3704. }
  3705. if (dpll & PLL_P2_DIVIDE_BY_4)
  3706. clock.p2 = 4;
  3707. else
  3708. clock.p2 = 2;
  3709. intel_clock(dev, 48000, &clock);
  3710. }
  3711. }
  3712. /* XXX: It would be nice to validate the clocks, but we can't reuse
  3713. * i830PllIsValid() because it relies on the xf86_config connector
  3714. * configuration being accurate, which it isn't necessarily.
  3715. */
  3716. return clock.dot;
  3717. }
  3718. /** Returns the currently programmed mode of the given pipe. */
  3719. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  3720. struct drm_crtc *crtc)
  3721. {
  3722. struct drm_i915_private *dev_priv = dev->dev_private;
  3723. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3724. int pipe = intel_crtc->pipe;
  3725. struct drm_display_mode *mode;
  3726. int htot = I915_READ((pipe == 0) ? HTOTAL_A : HTOTAL_B);
  3727. int hsync = I915_READ((pipe == 0) ? HSYNC_A : HSYNC_B);
  3728. int vtot = I915_READ((pipe == 0) ? VTOTAL_A : VTOTAL_B);
  3729. int vsync = I915_READ((pipe == 0) ? VSYNC_A : VSYNC_B);
  3730. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  3731. if (!mode)
  3732. return NULL;
  3733. mode->clock = intel_crtc_clock_get(dev, crtc);
  3734. mode->hdisplay = (htot & 0xffff) + 1;
  3735. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  3736. mode->hsync_start = (hsync & 0xffff) + 1;
  3737. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  3738. mode->vdisplay = (vtot & 0xffff) + 1;
  3739. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  3740. mode->vsync_start = (vsync & 0xffff) + 1;
  3741. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  3742. drm_mode_set_name(mode);
  3743. drm_mode_set_crtcinfo(mode, 0);
  3744. return mode;
  3745. }
  3746. #define GPU_IDLE_TIMEOUT 500 /* ms */
  3747. /* When this timer fires, we've been idle for awhile */
  3748. static void intel_gpu_idle_timer(unsigned long arg)
  3749. {
  3750. struct drm_device *dev = (struct drm_device *)arg;
  3751. drm_i915_private_t *dev_priv = dev->dev_private;
  3752. DRM_DEBUG_DRIVER("idle timer fired, downclocking\n");
  3753. dev_priv->busy = false;
  3754. queue_work(dev_priv->wq, &dev_priv->idle_work);
  3755. }
  3756. #define CRTC_IDLE_TIMEOUT 1000 /* ms */
  3757. static void intel_crtc_idle_timer(unsigned long arg)
  3758. {
  3759. struct intel_crtc *intel_crtc = (struct intel_crtc *)arg;
  3760. struct drm_crtc *crtc = &intel_crtc->base;
  3761. drm_i915_private_t *dev_priv = crtc->dev->dev_private;
  3762. DRM_DEBUG_DRIVER("idle timer fired, downclocking\n");
  3763. intel_crtc->busy = false;
  3764. queue_work(dev_priv->wq, &dev_priv->idle_work);
  3765. }
  3766. static void intel_increase_pllclock(struct drm_crtc *crtc, bool schedule)
  3767. {
  3768. struct drm_device *dev = crtc->dev;
  3769. drm_i915_private_t *dev_priv = dev->dev_private;
  3770. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3771. int pipe = intel_crtc->pipe;
  3772. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  3773. int dpll = I915_READ(dpll_reg);
  3774. if (HAS_PCH_SPLIT(dev))
  3775. return;
  3776. if (!dev_priv->lvds_downclock_avail)
  3777. return;
  3778. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  3779. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  3780. /* Unlock panel regs */
  3781. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) | (0xabcd << 16));
  3782. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  3783. I915_WRITE(dpll_reg, dpll);
  3784. dpll = I915_READ(dpll_reg);
  3785. intel_wait_for_vblank(dev);
  3786. dpll = I915_READ(dpll_reg);
  3787. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  3788. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  3789. /* ...and lock them again */
  3790. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
  3791. }
  3792. /* Schedule downclock */
  3793. if (schedule)
  3794. mod_timer(&intel_crtc->idle_timer, jiffies +
  3795. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  3796. }
  3797. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  3798. {
  3799. struct drm_device *dev = crtc->dev;
  3800. drm_i915_private_t *dev_priv = dev->dev_private;
  3801. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3802. int pipe = intel_crtc->pipe;
  3803. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  3804. int dpll = I915_READ(dpll_reg);
  3805. if (HAS_PCH_SPLIT(dev))
  3806. return;
  3807. if (!dev_priv->lvds_downclock_avail)
  3808. return;
  3809. /*
  3810. * Since this is called by a timer, we should never get here in
  3811. * the manual case.
  3812. */
  3813. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  3814. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  3815. /* Unlock panel regs */
  3816. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) | (0xabcd << 16));
  3817. dpll |= DISPLAY_RATE_SELECT_FPA1;
  3818. I915_WRITE(dpll_reg, dpll);
  3819. dpll = I915_READ(dpll_reg);
  3820. intel_wait_for_vblank(dev);
  3821. dpll = I915_READ(dpll_reg);
  3822. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  3823. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  3824. /* ...and lock them again */
  3825. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
  3826. }
  3827. }
  3828. /**
  3829. * intel_idle_update - adjust clocks for idleness
  3830. * @work: work struct
  3831. *
  3832. * Either the GPU or display (or both) went idle. Check the busy status
  3833. * here and adjust the CRTC and GPU clocks as necessary.
  3834. */
  3835. static void intel_idle_update(struct work_struct *work)
  3836. {
  3837. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  3838. idle_work);
  3839. struct drm_device *dev = dev_priv->dev;
  3840. struct drm_crtc *crtc;
  3841. struct intel_crtc *intel_crtc;
  3842. if (!i915_powersave)
  3843. return;
  3844. mutex_lock(&dev->struct_mutex);
  3845. if (IS_I945G(dev) || IS_I945GM(dev)) {
  3846. DRM_DEBUG_DRIVER("enable memory self refresh on 945\n");
  3847. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN_MASK | FW_BLC_SELF_EN);
  3848. }
  3849. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3850. /* Skip inactive CRTCs */
  3851. if (!crtc->fb)
  3852. continue;
  3853. intel_crtc = to_intel_crtc(crtc);
  3854. if (!intel_crtc->busy)
  3855. intel_decrease_pllclock(crtc);
  3856. }
  3857. mutex_unlock(&dev->struct_mutex);
  3858. }
  3859. /**
  3860. * intel_mark_busy - mark the GPU and possibly the display busy
  3861. * @dev: drm device
  3862. * @obj: object we're operating on
  3863. *
  3864. * Callers can use this function to indicate that the GPU is busy processing
  3865. * commands. If @obj matches one of the CRTC objects (i.e. it's a scanout
  3866. * buffer), we'll also mark the display as busy, so we know to increase its
  3867. * clock frequency.
  3868. */
  3869. void intel_mark_busy(struct drm_device *dev, struct drm_gem_object *obj)
  3870. {
  3871. drm_i915_private_t *dev_priv = dev->dev_private;
  3872. struct drm_crtc *crtc = NULL;
  3873. struct intel_framebuffer *intel_fb;
  3874. struct intel_crtc *intel_crtc;
  3875. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  3876. return;
  3877. if (!dev_priv->busy) {
  3878. if (IS_I945G(dev) || IS_I945GM(dev)) {
  3879. u32 fw_blc_self;
  3880. DRM_DEBUG_DRIVER("disable memory self refresh on 945\n");
  3881. fw_blc_self = I915_READ(FW_BLC_SELF);
  3882. fw_blc_self &= ~FW_BLC_SELF_EN;
  3883. I915_WRITE(FW_BLC_SELF, fw_blc_self | FW_BLC_SELF_EN_MASK);
  3884. }
  3885. dev_priv->busy = true;
  3886. } else
  3887. mod_timer(&dev_priv->idle_timer, jiffies +
  3888. msecs_to_jiffies(GPU_IDLE_TIMEOUT));
  3889. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3890. if (!crtc->fb)
  3891. continue;
  3892. intel_crtc = to_intel_crtc(crtc);
  3893. intel_fb = to_intel_framebuffer(crtc->fb);
  3894. if (intel_fb->obj == obj) {
  3895. if (!intel_crtc->busy) {
  3896. if (IS_I945G(dev) || IS_I945GM(dev)) {
  3897. u32 fw_blc_self;
  3898. DRM_DEBUG_DRIVER("disable memory self refresh on 945\n");
  3899. fw_blc_self = I915_READ(FW_BLC_SELF);
  3900. fw_blc_self &= ~FW_BLC_SELF_EN;
  3901. I915_WRITE(FW_BLC_SELF, fw_blc_self | FW_BLC_SELF_EN_MASK);
  3902. }
  3903. /* Non-busy -> busy, upclock */
  3904. intel_increase_pllclock(crtc, true);
  3905. intel_crtc->busy = true;
  3906. } else {
  3907. /* Busy -> busy, put off timer */
  3908. mod_timer(&intel_crtc->idle_timer, jiffies +
  3909. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  3910. }
  3911. }
  3912. }
  3913. }
  3914. static void intel_crtc_destroy(struct drm_crtc *crtc)
  3915. {
  3916. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3917. drm_crtc_cleanup(crtc);
  3918. kfree(intel_crtc);
  3919. }
  3920. struct intel_unpin_work {
  3921. struct work_struct work;
  3922. struct drm_device *dev;
  3923. struct drm_gem_object *old_fb_obj;
  3924. struct drm_gem_object *pending_flip_obj;
  3925. struct drm_pending_vblank_event *event;
  3926. int pending;
  3927. };
  3928. static void intel_unpin_work_fn(struct work_struct *__work)
  3929. {
  3930. struct intel_unpin_work *work =
  3931. container_of(__work, struct intel_unpin_work, work);
  3932. mutex_lock(&work->dev->struct_mutex);
  3933. i915_gem_object_unpin(work->old_fb_obj);
  3934. drm_gem_object_unreference(work->pending_flip_obj);
  3935. drm_gem_object_unreference(work->old_fb_obj);
  3936. mutex_unlock(&work->dev->struct_mutex);
  3937. kfree(work);
  3938. }
  3939. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  3940. {
  3941. drm_i915_private_t *dev_priv = dev->dev_private;
  3942. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  3943. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3944. struct intel_unpin_work *work;
  3945. struct drm_i915_gem_object *obj_priv;
  3946. struct drm_pending_vblank_event *e;
  3947. struct timeval now;
  3948. unsigned long flags;
  3949. /* Ignore early vblank irqs */
  3950. if (intel_crtc == NULL)
  3951. return;
  3952. spin_lock_irqsave(&dev->event_lock, flags);
  3953. work = intel_crtc->unpin_work;
  3954. if (work == NULL || !work->pending) {
  3955. if (work && !work->pending) {
  3956. obj_priv = to_intel_bo(work->pending_flip_obj);
  3957. DRM_DEBUG_DRIVER("flip finish: %p (%d) not pending?\n",
  3958. obj_priv,
  3959. atomic_read(&obj_priv->pending_flip));
  3960. }
  3961. spin_unlock_irqrestore(&dev->event_lock, flags);
  3962. return;
  3963. }
  3964. intel_crtc->unpin_work = NULL;
  3965. drm_vblank_put(dev, intel_crtc->pipe);
  3966. if (work->event) {
  3967. e = work->event;
  3968. do_gettimeofday(&now);
  3969. e->event.sequence = drm_vblank_count(dev, intel_crtc->pipe);
  3970. e->event.tv_sec = now.tv_sec;
  3971. e->event.tv_usec = now.tv_usec;
  3972. list_add_tail(&e->base.link,
  3973. &e->base.file_priv->event_list);
  3974. wake_up_interruptible(&e->base.file_priv->event_wait);
  3975. }
  3976. spin_unlock_irqrestore(&dev->event_lock, flags);
  3977. obj_priv = to_intel_bo(work->pending_flip_obj);
  3978. /* Initial scanout buffer will have a 0 pending flip count */
  3979. if ((atomic_read(&obj_priv->pending_flip) == 0) ||
  3980. atomic_dec_and_test(&obj_priv->pending_flip))
  3981. DRM_WAKEUP(&dev_priv->pending_flip_queue);
  3982. schedule_work(&work->work);
  3983. }
  3984. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  3985. {
  3986. drm_i915_private_t *dev_priv = dev->dev_private;
  3987. struct intel_crtc *intel_crtc =
  3988. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  3989. unsigned long flags;
  3990. spin_lock_irqsave(&dev->event_lock, flags);
  3991. if (intel_crtc->unpin_work) {
  3992. intel_crtc->unpin_work->pending = 1;
  3993. } else {
  3994. DRM_DEBUG_DRIVER("preparing flip with no unpin work?\n");
  3995. }
  3996. spin_unlock_irqrestore(&dev->event_lock, flags);
  3997. }
  3998. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  3999. struct drm_framebuffer *fb,
  4000. struct drm_pending_vblank_event *event)
  4001. {
  4002. struct drm_device *dev = crtc->dev;
  4003. struct drm_i915_private *dev_priv = dev->dev_private;
  4004. struct intel_framebuffer *intel_fb;
  4005. struct drm_i915_gem_object *obj_priv;
  4006. struct drm_gem_object *obj;
  4007. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4008. struct intel_unpin_work *work;
  4009. unsigned long flags;
  4010. int pipesrc_reg = (intel_crtc->pipe == 0) ? PIPEASRC : PIPEBSRC;
  4011. int ret, pipesrc;
  4012. RING_LOCALS;
  4013. work = kzalloc(sizeof *work, GFP_KERNEL);
  4014. if (work == NULL)
  4015. return -ENOMEM;
  4016. mutex_lock(&dev->struct_mutex);
  4017. work->event = event;
  4018. work->dev = crtc->dev;
  4019. intel_fb = to_intel_framebuffer(crtc->fb);
  4020. work->old_fb_obj = intel_fb->obj;
  4021. INIT_WORK(&work->work, intel_unpin_work_fn);
  4022. /* We borrow the event spin lock for protecting unpin_work */
  4023. spin_lock_irqsave(&dev->event_lock, flags);
  4024. if (intel_crtc->unpin_work) {
  4025. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  4026. spin_unlock_irqrestore(&dev->event_lock, flags);
  4027. kfree(work);
  4028. mutex_unlock(&dev->struct_mutex);
  4029. return -EBUSY;
  4030. }
  4031. intel_crtc->unpin_work = work;
  4032. spin_unlock_irqrestore(&dev->event_lock, flags);
  4033. intel_fb = to_intel_framebuffer(fb);
  4034. obj = intel_fb->obj;
  4035. ret = intel_pin_and_fence_fb_obj(dev, obj);
  4036. if (ret != 0) {
  4037. DRM_DEBUG_DRIVER("flip queue: %p pin & fence failed\n",
  4038. to_intel_bo(obj));
  4039. kfree(work);
  4040. intel_crtc->unpin_work = NULL;
  4041. mutex_unlock(&dev->struct_mutex);
  4042. return ret;
  4043. }
  4044. /* Reference the objects for the scheduled work. */
  4045. drm_gem_object_reference(work->old_fb_obj);
  4046. drm_gem_object_reference(obj);
  4047. crtc->fb = fb;
  4048. i915_gem_object_flush_write_domain(obj);
  4049. drm_vblank_get(dev, intel_crtc->pipe);
  4050. obj_priv = to_intel_bo(obj);
  4051. atomic_inc(&obj_priv->pending_flip);
  4052. work->pending_flip_obj = obj;
  4053. BEGIN_LP_RING(4);
  4054. OUT_RING(MI_DISPLAY_FLIP |
  4055. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  4056. OUT_RING(fb->pitch);
  4057. if (IS_I965G(dev)) {
  4058. OUT_RING(obj_priv->gtt_offset | obj_priv->tiling_mode);
  4059. pipesrc = I915_READ(pipesrc_reg);
  4060. OUT_RING(pipesrc & 0x0fff0fff);
  4061. } else {
  4062. OUT_RING(obj_priv->gtt_offset);
  4063. OUT_RING(MI_NOOP);
  4064. }
  4065. ADVANCE_LP_RING();
  4066. mutex_unlock(&dev->struct_mutex);
  4067. return 0;
  4068. }
  4069. static const struct drm_crtc_helper_funcs intel_helper_funcs = {
  4070. .dpms = intel_crtc_dpms,
  4071. .mode_fixup = intel_crtc_mode_fixup,
  4072. .mode_set = intel_crtc_mode_set,
  4073. .mode_set_base = intel_pipe_set_base,
  4074. .prepare = intel_crtc_prepare,
  4075. .commit = intel_crtc_commit,
  4076. .load_lut = intel_crtc_load_lut,
  4077. };
  4078. static const struct drm_crtc_funcs intel_crtc_funcs = {
  4079. .cursor_set = intel_crtc_cursor_set,
  4080. .cursor_move = intel_crtc_cursor_move,
  4081. .gamma_set = intel_crtc_gamma_set,
  4082. .set_config = drm_crtc_helper_set_config,
  4083. .destroy = intel_crtc_destroy,
  4084. .page_flip = intel_crtc_page_flip,
  4085. };
  4086. static void intel_crtc_init(struct drm_device *dev, int pipe)
  4087. {
  4088. drm_i915_private_t *dev_priv = dev->dev_private;
  4089. struct intel_crtc *intel_crtc;
  4090. int i;
  4091. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  4092. if (intel_crtc == NULL)
  4093. return;
  4094. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  4095. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  4096. intel_crtc->pipe = pipe;
  4097. intel_crtc->plane = pipe;
  4098. for (i = 0; i < 256; i++) {
  4099. intel_crtc->lut_r[i] = i;
  4100. intel_crtc->lut_g[i] = i;
  4101. intel_crtc->lut_b[i] = i;
  4102. }
  4103. /* Swap pipes & planes for FBC on pre-965 */
  4104. intel_crtc->pipe = pipe;
  4105. intel_crtc->plane = pipe;
  4106. if (IS_MOBILE(dev) && (IS_I9XX(dev) && !IS_I965G(dev))) {
  4107. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  4108. intel_crtc->plane = ((pipe == 0) ? 1 : 0);
  4109. }
  4110. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  4111. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  4112. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  4113. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  4114. intel_crtc->cursor_addr = 0;
  4115. intel_crtc->dpms_mode = DRM_MODE_DPMS_OFF;
  4116. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  4117. intel_crtc->busy = false;
  4118. setup_timer(&intel_crtc->idle_timer, intel_crtc_idle_timer,
  4119. (unsigned long)intel_crtc);
  4120. }
  4121. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  4122. struct drm_file *file_priv)
  4123. {
  4124. drm_i915_private_t *dev_priv = dev->dev_private;
  4125. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  4126. struct drm_mode_object *drmmode_obj;
  4127. struct intel_crtc *crtc;
  4128. if (!dev_priv) {
  4129. DRM_ERROR("called with no initialization\n");
  4130. return -EINVAL;
  4131. }
  4132. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  4133. DRM_MODE_OBJECT_CRTC);
  4134. if (!drmmode_obj) {
  4135. DRM_ERROR("no such CRTC id\n");
  4136. return -EINVAL;
  4137. }
  4138. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  4139. pipe_from_crtc_id->pipe = crtc->pipe;
  4140. return 0;
  4141. }
  4142. struct drm_crtc *intel_get_crtc_from_pipe(struct drm_device *dev, int pipe)
  4143. {
  4144. struct drm_crtc *crtc = NULL;
  4145. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  4146. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4147. if (intel_crtc->pipe == pipe)
  4148. break;
  4149. }
  4150. return crtc;
  4151. }
  4152. static int intel_encoder_clones(struct drm_device *dev, int type_mask)
  4153. {
  4154. int index_mask = 0;
  4155. struct drm_encoder *encoder;
  4156. int entry = 0;
  4157. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  4158. struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
  4159. if (type_mask & intel_encoder->clone_mask)
  4160. index_mask |= (1 << entry);
  4161. entry++;
  4162. }
  4163. return index_mask;
  4164. }
  4165. static void intel_setup_outputs(struct drm_device *dev)
  4166. {
  4167. struct drm_i915_private *dev_priv = dev->dev_private;
  4168. struct drm_encoder *encoder;
  4169. intel_crt_init(dev);
  4170. /* Set up integrated LVDS */
  4171. if (IS_MOBILE(dev) && !IS_I830(dev))
  4172. intel_lvds_init(dev);
  4173. if (HAS_PCH_SPLIT(dev)) {
  4174. int found;
  4175. if (IS_MOBILE(dev) && (I915_READ(DP_A) & DP_DETECTED))
  4176. intel_dp_init(dev, DP_A);
  4177. if (I915_READ(HDMIB) & PORT_DETECTED) {
  4178. /* PCH SDVOB multiplex with HDMIB */
  4179. found = intel_sdvo_init(dev, PCH_SDVOB);
  4180. if (!found)
  4181. intel_hdmi_init(dev, HDMIB);
  4182. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  4183. intel_dp_init(dev, PCH_DP_B);
  4184. }
  4185. if (I915_READ(HDMIC) & PORT_DETECTED)
  4186. intel_hdmi_init(dev, HDMIC);
  4187. if (I915_READ(HDMID) & PORT_DETECTED)
  4188. intel_hdmi_init(dev, HDMID);
  4189. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  4190. intel_dp_init(dev, PCH_DP_C);
  4191. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  4192. intel_dp_init(dev, PCH_DP_D);
  4193. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  4194. bool found = false;
  4195. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  4196. DRM_DEBUG_KMS("probing SDVOB\n");
  4197. found = intel_sdvo_init(dev, SDVOB);
  4198. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  4199. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  4200. intel_hdmi_init(dev, SDVOB);
  4201. }
  4202. if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
  4203. DRM_DEBUG_KMS("probing DP_B\n");
  4204. intel_dp_init(dev, DP_B);
  4205. }
  4206. }
  4207. /* Before G4X SDVOC doesn't have its own detect register */
  4208. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  4209. DRM_DEBUG_KMS("probing SDVOC\n");
  4210. found = intel_sdvo_init(dev, SDVOC);
  4211. }
  4212. if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
  4213. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  4214. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  4215. intel_hdmi_init(dev, SDVOC);
  4216. }
  4217. if (SUPPORTS_INTEGRATED_DP(dev)) {
  4218. DRM_DEBUG_KMS("probing DP_C\n");
  4219. intel_dp_init(dev, DP_C);
  4220. }
  4221. }
  4222. if (SUPPORTS_INTEGRATED_DP(dev) &&
  4223. (I915_READ(DP_D) & DP_DETECTED)) {
  4224. DRM_DEBUG_KMS("probing DP_D\n");
  4225. intel_dp_init(dev, DP_D);
  4226. }
  4227. } else if (IS_GEN2(dev))
  4228. intel_dvo_init(dev);
  4229. if (SUPPORTS_TV(dev))
  4230. intel_tv_init(dev);
  4231. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  4232. struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
  4233. encoder->possible_crtcs = intel_encoder->crtc_mask;
  4234. encoder->possible_clones = intel_encoder_clones(dev,
  4235. intel_encoder->clone_mask);
  4236. }
  4237. }
  4238. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  4239. {
  4240. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  4241. struct drm_device *dev = fb->dev;
  4242. if (fb->fbdev)
  4243. intelfb_remove(dev, fb);
  4244. drm_framebuffer_cleanup(fb);
  4245. drm_gem_object_unreference_unlocked(intel_fb->obj);
  4246. kfree(intel_fb);
  4247. }
  4248. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  4249. struct drm_file *file_priv,
  4250. unsigned int *handle)
  4251. {
  4252. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  4253. struct drm_gem_object *object = intel_fb->obj;
  4254. return drm_gem_handle_create(file_priv, object, handle);
  4255. }
  4256. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  4257. .destroy = intel_user_framebuffer_destroy,
  4258. .create_handle = intel_user_framebuffer_create_handle,
  4259. };
  4260. int intel_framebuffer_create(struct drm_device *dev,
  4261. struct drm_mode_fb_cmd *mode_cmd,
  4262. struct drm_framebuffer **fb,
  4263. struct drm_gem_object *obj)
  4264. {
  4265. struct intel_framebuffer *intel_fb;
  4266. int ret;
  4267. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  4268. if (!intel_fb)
  4269. return -ENOMEM;
  4270. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  4271. if (ret) {
  4272. DRM_ERROR("framebuffer init failed %d\n", ret);
  4273. return ret;
  4274. }
  4275. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  4276. intel_fb->obj = obj;
  4277. *fb = &intel_fb->base;
  4278. return 0;
  4279. }
  4280. static struct drm_framebuffer *
  4281. intel_user_framebuffer_create(struct drm_device *dev,
  4282. struct drm_file *filp,
  4283. struct drm_mode_fb_cmd *mode_cmd)
  4284. {
  4285. struct drm_gem_object *obj;
  4286. struct drm_framebuffer *fb;
  4287. int ret;
  4288. obj = drm_gem_object_lookup(dev, filp, mode_cmd->handle);
  4289. if (!obj)
  4290. return NULL;
  4291. ret = intel_framebuffer_create(dev, mode_cmd, &fb, obj);
  4292. if (ret) {
  4293. drm_gem_object_unreference_unlocked(obj);
  4294. return NULL;
  4295. }
  4296. return fb;
  4297. }
  4298. static const struct drm_mode_config_funcs intel_mode_funcs = {
  4299. .fb_create = intel_user_framebuffer_create,
  4300. .fb_changed = intelfb_probe,
  4301. };
  4302. static struct drm_gem_object *
  4303. intel_alloc_power_context(struct drm_device *dev)
  4304. {
  4305. struct drm_gem_object *pwrctx;
  4306. int ret;
  4307. pwrctx = drm_gem_object_alloc(dev, 4096);
  4308. if (!pwrctx) {
  4309. DRM_DEBUG("failed to alloc power context, RC6 disabled\n");
  4310. return NULL;
  4311. }
  4312. mutex_lock(&dev->struct_mutex);
  4313. ret = i915_gem_object_pin(pwrctx, 4096);
  4314. if (ret) {
  4315. DRM_ERROR("failed to pin power context: %d\n", ret);
  4316. goto err_unref;
  4317. }
  4318. ret = i915_gem_object_set_to_gtt_domain(pwrctx, 1);
  4319. if (ret) {
  4320. DRM_ERROR("failed to set-domain on power context: %d\n", ret);
  4321. goto err_unpin;
  4322. }
  4323. mutex_unlock(&dev->struct_mutex);
  4324. return pwrctx;
  4325. err_unpin:
  4326. i915_gem_object_unpin(pwrctx);
  4327. err_unref:
  4328. drm_gem_object_unreference(pwrctx);
  4329. mutex_unlock(&dev->struct_mutex);
  4330. return NULL;
  4331. }
  4332. void ironlake_enable_drps(struct drm_device *dev)
  4333. {
  4334. struct drm_i915_private *dev_priv = dev->dev_private;
  4335. u32 rgvmodectl = I915_READ(MEMMODECTL), rgvswctl;
  4336. u8 fmax, fmin, fstart, vstart;
  4337. int i = 0;
  4338. /* 100ms RC evaluation intervals */
  4339. I915_WRITE(RCUPEI, 100000);
  4340. I915_WRITE(RCDNEI, 100000);
  4341. /* Set max/min thresholds to 90ms and 80ms respectively */
  4342. I915_WRITE(RCBMAXAVG, 90000);
  4343. I915_WRITE(RCBMINAVG, 80000);
  4344. I915_WRITE(MEMIHYST, 1);
  4345. /* Set up min, max, and cur for interrupt handling */
  4346. fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT;
  4347. fmin = (rgvmodectl & MEMMODE_FMIN_MASK);
  4348. fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >>
  4349. MEMMODE_FSTART_SHIFT;
  4350. vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >>
  4351. PXVFREQ_PX_SHIFT;
  4352. dev_priv->max_delay = fstart; /* can't go to fmax w/o IPS */
  4353. dev_priv->min_delay = fmin;
  4354. dev_priv->cur_delay = fstart;
  4355. I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN);
  4356. /*
  4357. * Interrupts will be enabled in ironlake_irq_postinstall
  4358. */
  4359. I915_WRITE(VIDSTART, vstart);
  4360. POSTING_READ(VIDSTART);
  4361. rgvmodectl |= MEMMODE_SWMODE_EN;
  4362. I915_WRITE(MEMMODECTL, rgvmodectl);
  4363. while (I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) {
  4364. if (i++ > 100) {
  4365. DRM_ERROR("stuck trying to change perf mode\n");
  4366. break;
  4367. }
  4368. msleep(1);
  4369. }
  4370. msleep(1);
  4371. rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) |
  4372. (fstart << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM;
  4373. I915_WRITE(MEMSWCTL, rgvswctl);
  4374. POSTING_READ(MEMSWCTL);
  4375. rgvswctl |= MEMCTL_CMD_STS;
  4376. I915_WRITE(MEMSWCTL, rgvswctl);
  4377. }
  4378. void ironlake_disable_drps(struct drm_device *dev)
  4379. {
  4380. struct drm_i915_private *dev_priv = dev->dev_private;
  4381. u32 rgvswctl;
  4382. u8 fstart;
  4383. /* Ack interrupts, disable EFC interrupt */
  4384. I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN);
  4385. I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG);
  4386. I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT);
  4387. I915_WRITE(DEIIR, DE_PCU_EVENT);
  4388. I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT);
  4389. /* Go back to the starting frequency */
  4390. fstart = (I915_READ(MEMMODECTL) & MEMMODE_FSTART_MASK) >>
  4391. MEMMODE_FSTART_SHIFT;
  4392. rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) |
  4393. (fstart << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM;
  4394. I915_WRITE(MEMSWCTL, rgvswctl);
  4395. msleep(1);
  4396. rgvswctl |= MEMCTL_CMD_STS;
  4397. I915_WRITE(MEMSWCTL, rgvswctl);
  4398. msleep(1);
  4399. }
  4400. void intel_init_clock_gating(struct drm_device *dev)
  4401. {
  4402. struct drm_i915_private *dev_priv = dev->dev_private;
  4403. /*
  4404. * Disable clock gating reported to work incorrectly according to the
  4405. * specs, but enable as much else as we can.
  4406. */
  4407. if (HAS_PCH_SPLIT(dev)) {
  4408. uint32_t dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE;
  4409. if (IS_IRONLAKE(dev)) {
  4410. /* Required for FBC */
  4411. dspclk_gate |= DPFDUNIT_CLOCK_GATE_DISABLE;
  4412. /* Required for CxSR */
  4413. dspclk_gate |= DPARBUNIT_CLOCK_GATE_DISABLE;
  4414. I915_WRITE(PCH_3DCGDIS0,
  4415. MARIUNIT_CLOCK_GATE_DISABLE |
  4416. SVSMUNIT_CLOCK_GATE_DISABLE);
  4417. }
  4418. I915_WRITE(PCH_DSPCLK_GATE_D, dspclk_gate);
  4419. /*
  4420. * According to the spec the following bits should be set in
  4421. * order to enable memory self-refresh
  4422. * The bit 22/21 of 0x42004
  4423. * The bit 5 of 0x42020
  4424. * The bit 15 of 0x45000
  4425. */
  4426. if (IS_IRONLAKE(dev)) {
  4427. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  4428. (I915_READ(ILK_DISPLAY_CHICKEN2) |
  4429. ILK_DPARB_GATE | ILK_VSDPFD_FULL));
  4430. I915_WRITE(ILK_DSPCLK_GATE,
  4431. (I915_READ(ILK_DSPCLK_GATE) |
  4432. ILK_DPARB_CLK_GATE));
  4433. I915_WRITE(DISP_ARB_CTL,
  4434. (I915_READ(DISP_ARB_CTL) |
  4435. DISP_FBC_WM_DIS));
  4436. }
  4437. return;
  4438. } else if (IS_G4X(dev)) {
  4439. uint32_t dspclk_gate;
  4440. I915_WRITE(RENCLK_GATE_D1, 0);
  4441. I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
  4442. GS_UNIT_CLOCK_GATE_DISABLE |
  4443. CL_UNIT_CLOCK_GATE_DISABLE);
  4444. I915_WRITE(RAMCLK_GATE_D, 0);
  4445. dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
  4446. OVRUNIT_CLOCK_GATE_DISABLE |
  4447. OVCUNIT_CLOCK_GATE_DISABLE;
  4448. if (IS_GM45(dev))
  4449. dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
  4450. I915_WRITE(DSPCLK_GATE_D, dspclk_gate);
  4451. } else if (IS_I965GM(dev)) {
  4452. I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
  4453. I915_WRITE(RENCLK_GATE_D2, 0);
  4454. I915_WRITE(DSPCLK_GATE_D, 0);
  4455. I915_WRITE(RAMCLK_GATE_D, 0);
  4456. I915_WRITE16(DEUC, 0);
  4457. } else if (IS_I965G(dev)) {
  4458. I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
  4459. I965_RCC_CLOCK_GATE_DISABLE |
  4460. I965_RCPB_CLOCK_GATE_DISABLE |
  4461. I965_ISC_CLOCK_GATE_DISABLE |
  4462. I965_FBC_CLOCK_GATE_DISABLE);
  4463. I915_WRITE(RENCLK_GATE_D2, 0);
  4464. } else if (IS_I9XX(dev)) {
  4465. u32 dstate = I915_READ(D_STATE);
  4466. dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
  4467. DSTATE_DOT_CLOCK_GATING;
  4468. I915_WRITE(D_STATE, dstate);
  4469. } else if (IS_I85X(dev) || IS_I865G(dev)) {
  4470. I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
  4471. } else if (IS_I830(dev)) {
  4472. I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE);
  4473. }
  4474. /*
  4475. * GPU can automatically power down the render unit if given a page
  4476. * to save state.
  4477. */
  4478. if (I915_HAS_RC6(dev) && drm_core_check_feature(dev, DRIVER_MODESET)) {
  4479. struct drm_i915_gem_object *obj_priv = NULL;
  4480. if (dev_priv->pwrctx) {
  4481. obj_priv = to_intel_bo(dev_priv->pwrctx);
  4482. } else {
  4483. struct drm_gem_object *pwrctx;
  4484. pwrctx = intel_alloc_power_context(dev);
  4485. if (pwrctx) {
  4486. dev_priv->pwrctx = pwrctx;
  4487. obj_priv = to_intel_bo(pwrctx);
  4488. }
  4489. }
  4490. if (obj_priv) {
  4491. I915_WRITE(PWRCTXA, obj_priv->gtt_offset | PWRCTX_EN);
  4492. I915_WRITE(MCHBAR_RENDER_STANDBY,
  4493. I915_READ(MCHBAR_RENDER_STANDBY) & ~RCX_SW_EXIT);
  4494. }
  4495. }
  4496. }
  4497. /* Set up chip specific display functions */
  4498. static void intel_init_display(struct drm_device *dev)
  4499. {
  4500. struct drm_i915_private *dev_priv = dev->dev_private;
  4501. /* We always want a DPMS function */
  4502. if (HAS_PCH_SPLIT(dev))
  4503. dev_priv->display.dpms = ironlake_crtc_dpms;
  4504. else
  4505. dev_priv->display.dpms = i9xx_crtc_dpms;
  4506. /* Only mobile has FBC, leave pointers NULL for other chips */
  4507. if (IS_MOBILE(dev)) {
  4508. if (IS_GM45(dev)) {
  4509. dev_priv->display.fbc_enabled = g4x_fbc_enabled;
  4510. dev_priv->display.enable_fbc = g4x_enable_fbc;
  4511. dev_priv->display.disable_fbc = g4x_disable_fbc;
  4512. } else if (IS_I965GM(dev)) {
  4513. dev_priv->display.fbc_enabled = i8xx_fbc_enabled;
  4514. dev_priv->display.enable_fbc = i8xx_enable_fbc;
  4515. dev_priv->display.disable_fbc = i8xx_disable_fbc;
  4516. }
  4517. /* 855GM needs testing */
  4518. }
  4519. /* Returns the core display clock speed */
  4520. if (IS_I945G(dev) || (IS_G33(dev) && ! IS_PINEVIEW_M(dev)))
  4521. dev_priv->display.get_display_clock_speed =
  4522. i945_get_display_clock_speed;
  4523. else if (IS_I915G(dev))
  4524. dev_priv->display.get_display_clock_speed =
  4525. i915_get_display_clock_speed;
  4526. else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev))
  4527. dev_priv->display.get_display_clock_speed =
  4528. i9xx_misc_get_display_clock_speed;
  4529. else if (IS_I915GM(dev))
  4530. dev_priv->display.get_display_clock_speed =
  4531. i915gm_get_display_clock_speed;
  4532. else if (IS_I865G(dev))
  4533. dev_priv->display.get_display_clock_speed =
  4534. i865_get_display_clock_speed;
  4535. else if (IS_I85X(dev))
  4536. dev_priv->display.get_display_clock_speed =
  4537. i855_get_display_clock_speed;
  4538. else /* 852, 830 */
  4539. dev_priv->display.get_display_clock_speed =
  4540. i830_get_display_clock_speed;
  4541. /* For FIFO watermark updates */
  4542. if (HAS_PCH_SPLIT(dev)) {
  4543. if (IS_IRONLAKE(dev)) {
  4544. if (I915_READ(MLTR_ILK) & ILK_SRLT_MASK)
  4545. dev_priv->display.update_wm = ironlake_update_wm;
  4546. else {
  4547. DRM_DEBUG_KMS("Failed to get proper latency. "
  4548. "Disable CxSR\n");
  4549. dev_priv->display.update_wm = NULL;
  4550. }
  4551. } else
  4552. dev_priv->display.update_wm = NULL;
  4553. } else if (IS_PINEVIEW(dev)) {
  4554. if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev),
  4555. dev_priv->fsb_freq,
  4556. dev_priv->mem_freq)) {
  4557. DRM_INFO("failed to find known CxSR latency "
  4558. "(found fsb freq %d, mem freq %d), "
  4559. "disabling CxSR\n",
  4560. dev_priv->fsb_freq, dev_priv->mem_freq);
  4561. /* Disable CxSR and never update its watermark again */
  4562. pineview_disable_cxsr(dev);
  4563. dev_priv->display.update_wm = NULL;
  4564. } else
  4565. dev_priv->display.update_wm = pineview_update_wm;
  4566. } else if (IS_G4X(dev))
  4567. dev_priv->display.update_wm = g4x_update_wm;
  4568. else if (IS_I965G(dev))
  4569. dev_priv->display.update_wm = i965_update_wm;
  4570. else if (IS_I9XX(dev) || IS_MOBILE(dev)) {
  4571. dev_priv->display.update_wm = i9xx_update_wm;
  4572. dev_priv->display.get_fifo_size = i9xx_get_fifo_size;
  4573. } else {
  4574. if (IS_I85X(dev))
  4575. dev_priv->display.get_fifo_size = i85x_get_fifo_size;
  4576. else if (IS_845G(dev))
  4577. dev_priv->display.get_fifo_size = i845_get_fifo_size;
  4578. else
  4579. dev_priv->display.get_fifo_size = i830_get_fifo_size;
  4580. dev_priv->display.update_wm = i830_update_wm;
  4581. }
  4582. }
  4583. void intel_modeset_init(struct drm_device *dev)
  4584. {
  4585. struct drm_i915_private *dev_priv = dev->dev_private;
  4586. int num_pipe;
  4587. int i;
  4588. drm_mode_config_init(dev);
  4589. dev->mode_config.min_width = 0;
  4590. dev->mode_config.min_height = 0;
  4591. dev->mode_config.funcs = (void *)&intel_mode_funcs;
  4592. intel_init_display(dev);
  4593. if (IS_I965G(dev)) {
  4594. dev->mode_config.max_width = 8192;
  4595. dev->mode_config.max_height = 8192;
  4596. } else if (IS_I9XX(dev)) {
  4597. dev->mode_config.max_width = 4096;
  4598. dev->mode_config.max_height = 4096;
  4599. } else {
  4600. dev->mode_config.max_width = 2048;
  4601. dev->mode_config.max_height = 2048;
  4602. }
  4603. /* set memory base */
  4604. if (IS_I9XX(dev))
  4605. dev->mode_config.fb_base = pci_resource_start(dev->pdev, 2);
  4606. else
  4607. dev->mode_config.fb_base = pci_resource_start(dev->pdev, 0);
  4608. if (IS_MOBILE(dev) || IS_I9XX(dev))
  4609. num_pipe = 2;
  4610. else
  4611. num_pipe = 1;
  4612. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  4613. num_pipe, num_pipe > 1 ? "s" : "");
  4614. for (i = 0; i < num_pipe; i++) {
  4615. intel_crtc_init(dev, i);
  4616. }
  4617. intel_setup_outputs(dev);
  4618. intel_init_clock_gating(dev);
  4619. if (IS_IRONLAKE_M(dev))
  4620. ironlake_enable_drps(dev);
  4621. INIT_WORK(&dev_priv->idle_work, intel_idle_update);
  4622. setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer,
  4623. (unsigned long)dev);
  4624. intel_setup_overlay(dev);
  4625. }
  4626. void intel_modeset_cleanup(struct drm_device *dev)
  4627. {
  4628. struct drm_i915_private *dev_priv = dev->dev_private;
  4629. struct drm_crtc *crtc;
  4630. struct intel_crtc *intel_crtc;
  4631. mutex_lock(&dev->struct_mutex);
  4632. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  4633. /* Skip inactive CRTCs */
  4634. if (!crtc->fb)
  4635. continue;
  4636. intel_crtc = to_intel_crtc(crtc);
  4637. intel_increase_pllclock(crtc, false);
  4638. del_timer_sync(&intel_crtc->idle_timer);
  4639. }
  4640. del_timer_sync(&dev_priv->idle_timer);
  4641. if (dev_priv->display.disable_fbc)
  4642. dev_priv->display.disable_fbc(dev);
  4643. if (dev_priv->pwrctx) {
  4644. struct drm_i915_gem_object *obj_priv;
  4645. obj_priv = to_intel_bo(dev_priv->pwrctx);
  4646. I915_WRITE(PWRCTXA, obj_priv->gtt_offset &~ PWRCTX_EN);
  4647. I915_READ(PWRCTXA);
  4648. i915_gem_object_unpin(dev_priv->pwrctx);
  4649. drm_gem_object_unreference(dev_priv->pwrctx);
  4650. }
  4651. if (IS_IRONLAKE_M(dev))
  4652. ironlake_disable_drps(dev);
  4653. mutex_unlock(&dev->struct_mutex);
  4654. drm_mode_config_cleanup(dev);
  4655. }
  4656. /*
  4657. * Return which encoder is currently attached for connector.
  4658. */
  4659. struct drm_encoder *intel_attached_encoder (struct drm_connector *connector)
  4660. {
  4661. struct drm_mode_object *obj;
  4662. struct drm_encoder *encoder;
  4663. int i;
  4664. for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
  4665. if (connector->encoder_ids[i] == 0)
  4666. break;
  4667. obj = drm_mode_object_find(connector->dev,
  4668. connector->encoder_ids[i],
  4669. DRM_MODE_OBJECT_ENCODER);
  4670. if (!obj)
  4671. continue;
  4672. encoder = obj_to_encoder(obj);
  4673. return encoder;
  4674. }
  4675. return NULL;
  4676. }
  4677. /*
  4678. * set vga decode state - true == enable VGA decode
  4679. */
  4680. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  4681. {
  4682. struct drm_i915_private *dev_priv = dev->dev_private;
  4683. u16 gmch_ctrl;
  4684. pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
  4685. if (state)
  4686. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  4687. else
  4688. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  4689. pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
  4690. return 0;
  4691. }