intel_display.c 169 KB

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