intel_display.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  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/i2c.h>
  27. #include "drmP.h"
  28. #include "intel_drv.h"
  29. #include "i915_drm.h"
  30. #include "i915_drv.h"
  31. #include "drm_crtc_helper.h"
  32. bool intel_pipe_has_type (struct drm_crtc *crtc, int type);
  33. typedef struct {
  34. /* given values */
  35. int n;
  36. int m1, m2;
  37. int p1, p2;
  38. /* derived values */
  39. int dot;
  40. int vco;
  41. int m;
  42. int p;
  43. } intel_clock_t;
  44. typedef struct {
  45. int min, max;
  46. } intel_range_t;
  47. typedef struct {
  48. int dot_limit;
  49. int p2_slow, p2_fast;
  50. } intel_p2_t;
  51. #define INTEL_P2_NUM 2
  52. typedef struct {
  53. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  54. intel_p2_t p2;
  55. } intel_limit_t;
  56. #define I8XX_DOT_MIN 25000
  57. #define I8XX_DOT_MAX 350000
  58. #define I8XX_VCO_MIN 930000
  59. #define I8XX_VCO_MAX 1400000
  60. #define I8XX_N_MIN 3
  61. #define I8XX_N_MAX 16
  62. #define I8XX_M_MIN 96
  63. #define I8XX_M_MAX 140
  64. #define I8XX_M1_MIN 18
  65. #define I8XX_M1_MAX 26
  66. #define I8XX_M2_MIN 6
  67. #define I8XX_M2_MAX 16
  68. #define I8XX_P_MIN 4
  69. #define I8XX_P_MAX 128
  70. #define I8XX_P1_MIN 2
  71. #define I8XX_P1_MAX 33
  72. #define I8XX_P1_LVDS_MIN 1
  73. #define I8XX_P1_LVDS_MAX 6
  74. #define I8XX_P2_SLOW 4
  75. #define I8XX_P2_FAST 2
  76. #define I8XX_P2_LVDS_SLOW 14
  77. #define I8XX_P2_LVDS_FAST 14 /* No fast option */
  78. #define I8XX_P2_SLOW_LIMIT 165000
  79. #define I9XX_DOT_MIN 20000
  80. #define I9XX_DOT_MAX 400000
  81. #define I9XX_VCO_MIN 1400000
  82. #define I9XX_VCO_MAX 2800000
  83. #define I9XX_N_MIN 3
  84. #define I9XX_N_MAX 8
  85. #define I9XX_M_MIN 70
  86. #define I9XX_M_MAX 120
  87. #define I9XX_M1_MIN 10
  88. #define I9XX_M1_MAX 20
  89. #define I9XX_M2_MIN 5
  90. #define I9XX_M2_MAX 9
  91. #define I9XX_P_SDVO_DAC_MIN 5
  92. #define I9XX_P_SDVO_DAC_MAX 80
  93. #define I9XX_P_LVDS_MIN 7
  94. #define I9XX_P_LVDS_MAX 98
  95. #define I9XX_P1_MIN 1
  96. #define I9XX_P1_MAX 8
  97. #define I9XX_P2_SDVO_DAC_SLOW 10
  98. #define I9XX_P2_SDVO_DAC_FAST 5
  99. #define I9XX_P2_SDVO_DAC_SLOW_LIMIT 200000
  100. #define I9XX_P2_LVDS_SLOW 14
  101. #define I9XX_P2_LVDS_FAST 7
  102. #define I9XX_P2_LVDS_SLOW_LIMIT 112000
  103. #define INTEL_LIMIT_I8XX_DVO_DAC 0
  104. #define INTEL_LIMIT_I8XX_LVDS 1
  105. #define INTEL_LIMIT_I9XX_SDVO_DAC 2
  106. #define INTEL_LIMIT_I9XX_LVDS 3
  107. static const intel_limit_t intel_limits[] = {
  108. { /* INTEL_LIMIT_I8XX_DVO_DAC */
  109. .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
  110. .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
  111. .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
  112. .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
  113. .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
  114. .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
  115. .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
  116. .p1 = { .min = I8XX_P1_MIN, .max = I8XX_P1_MAX },
  117. .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
  118. .p2_slow = I8XX_P2_SLOW, .p2_fast = I8XX_P2_FAST },
  119. },
  120. { /* INTEL_LIMIT_I8XX_LVDS */
  121. .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
  122. .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
  123. .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
  124. .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
  125. .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
  126. .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
  127. .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
  128. .p1 = { .min = I8XX_P1_LVDS_MIN, .max = I8XX_P1_LVDS_MAX },
  129. .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
  130. .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST },
  131. },
  132. { /* INTEL_LIMIT_I9XX_SDVO_DAC */
  133. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  134. .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
  135. .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
  136. .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
  137. .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
  138. .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
  139. .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX },
  140. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  141. .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
  142. .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
  143. },
  144. { /* INTEL_LIMIT_I9XX_LVDS */
  145. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  146. .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
  147. .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
  148. .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
  149. .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
  150. .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
  151. .p = { .min = I9XX_P_LVDS_MIN, .max = I9XX_P_LVDS_MAX },
  152. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  153. /* The single-channel range is 25-112Mhz, and dual-channel
  154. * is 80-224Mhz. Prefer single channel as much as possible.
  155. */
  156. .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
  157. .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST },
  158. },
  159. };
  160. static const intel_limit_t *intel_limit(struct drm_crtc *crtc)
  161. {
  162. struct drm_device *dev = crtc->dev;
  163. const intel_limit_t *limit;
  164. if (IS_I9XX(dev)) {
  165. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  166. limit = &intel_limits[INTEL_LIMIT_I9XX_LVDS];
  167. else
  168. limit = &intel_limits[INTEL_LIMIT_I9XX_SDVO_DAC];
  169. } else {
  170. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  171. limit = &intel_limits[INTEL_LIMIT_I8XX_LVDS];
  172. else
  173. limit = &intel_limits[INTEL_LIMIT_I8XX_DVO_DAC];
  174. }
  175. return limit;
  176. }
  177. /** Derive the pixel clock for the given refclk and divisors for 8xx chips. */
  178. static void i8xx_clock(int refclk, intel_clock_t *clock)
  179. {
  180. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  181. clock->p = clock->p1 * clock->p2;
  182. clock->vco = refclk * clock->m / (clock->n + 2);
  183. clock->dot = clock->vco / clock->p;
  184. }
  185. /** Derive the pixel clock for the given refclk and divisors for 9xx chips. */
  186. static void i9xx_clock(int refclk, intel_clock_t *clock)
  187. {
  188. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  189. clock->p = clock->p1 * clock->p2;
  190. clock->vco = refclk * clock->m / (clock->n + 2);
  191. clock->dot = clock->vco / clock->p;
  192. }
  193. static void intel_clock(struct drm_device *dev, int refclk,
  194. intel_clock_t *clock)
  195. {
  196. if (IS_I9XX(dev))
  197. i9xx_clock (refclk, clock);
  198. else
  199. i8xx_clock (refclk, clock);
  200. }
  201. /**
  202. * Returns whether any output on the specified pipe is of the specified type
  203. */
  204. bool intel_pipe_has_type (struct drm_crtc *crtc, int type)
  205. {
  206. struct drm_device *dev = crtc->dev;
  207. struct drm_mode_config *mode_config = &dev->mode_config;
  208. struct drm_connector *l_entry;
  209. list_for_each_entry(l_entry, &mode_config->connector_list, head) {
  210. if (l_entry->encoder &&
  211. l_entry->encoder->crtc == crtc) {
  212. struct intel_output *intel_output = to_intel_output(l_entry);
  213. if (intel_output->type == type)
  214. return true;
  215. }
  216. }
  217. return false;
  218. }
  219. #define INTELPllInvalid(s) { /* ErrorF (s) */; return false; }
  220. /**
  221. * Returns whether the given set of divisors are valid for a given refclk with
  222. * the given connectors.
  223. */
  224. static bool intel_PLL_is_valid(struct drm_crtc *crtc, intel_clock_t *clock)
  225. {
  226. const intel_limit_t *limit = intel_limit (crtc);
  227. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  228. INTELPllInvalid ("p1 out of range\n");
  229. if (clock->p < limit->p.min || limit->p.max < clock->p)
  230. INTELPllInvalid ("p out of range\n");
  231. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  232. INTELPllInvalid ("m2 out of range\n");
  233. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  234. INTELPllInvalid ("m1 out of range\n");
  235. if (clock->m1 <= clock->m2)
  236. INTELPllInvalid ("m1 <= m2\n");
  237. if (clock->m < limit->m.min || limit->m.max < clock->m)
  238. INTELPllInvalid ("m out of range\n");
  239. if (clock->n < limit->n.min || limit->n.max < clock->n)
  240. INTELPllInvalid ("n out of range\n");
  241. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  242. INTELPllInvalid ("vco out of range\n");
  243. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  244. * connector, etc., rather than just a single range.
  245. */
  246. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  247. INTELPllInvalid ("dot out of range\n");
  248. return true;
  249. }
  250. /**
  251. * Returns a set of divisors for the desired target clock with the given
  252. * refclk, or FALSE. The returned values represent the clock equation:
  253. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  254. */
  255. static bool intel_find_best_PLL(struct drm_crtc *crtc, int target,
  256. int refclk, intel_clock_t *best_clock)
  257. {
  258. struct drm_device *dev = crtc->dev;
  259. struct drm_i915_private *dev_priv = dev->dev_private;
  260. intel_clock_t clock;
  261. const intel_limit_t *limit = intel_limit(crtc);
  262. int err = target;
  263. if (IS_I9XX(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  264. (I915_READ(LVDS) & LVDS_PORT_EN) != 0) {
  265. /*
  266. * For LVDS, if the panel is on, just rely on its current
  267. * settings for dual-channel. We haven't figured out how to
  268. * reliably set up different single/dual channel state, if we
  269. * even can.
  270. */
  271. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  272. LVDS_CLKB_POWER_UP)
  273. clock.p2 = limit->p2.p2_fast;
  274. else
  275. clock.p2 = limit->p2.p2_slow;
  276. } else {
  277. if (target < limit->p2.dot_limit)
  278. clock.p2 = limit->p2.p2_slow;
  279. else
  280. clock.p2 = limit->p2.p2_fast;
  281. }
  282. memset (best_clock, 0, sizeof (*best_clock));
  283. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  284. for (clock.m2 = limit->m2.min; clock.m2 < clock.m1 &&
  285. clock.m2 <= limit->m2.max; clock.m2++) {
  286. for (clock.n = limit->n.min; clock.n <= limit->n.max;
  287. clock.n++) {
  288. for (clock.p1 = limit->p1.min;
  289. clock.p1 <= limit->p1.max; clock.p1++) {
  290. int this_err;
  291. intel_clock(dev, refclk, &clock);
  292. if (!intel_PLL_is_valid(crtc, &clock))
  293. continue;
  294. this_err = abs(clock.dot - target);
  295. if (this_err < err) {
  296. *best_clock = clock;
  297. err = this_err;
  298. }
  299. }
  300. }
  301. }
  302. }
  303. return (err != target);
  304. }
  305. void
  306. intel_wait_for_vblank(struct drm_device *dev)
  307. {
  308. /* Wait for 20ms, i.e. one cycle at 50hz. */
  309. udelay(20000);
  310. }
  311. static void
  312. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  313. struct drm_framebuffer *old_fb)
  314. {
  315. struct drm_device *dev = crtc->dev;
  316. struct drm_i915_private *dev_priv = dev->dev_private;
  317. struct drm_i915_master_private *master_priv;
  318. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  319. struct intel_framebuffer *intel_fb;
  320. struct drm_i915_gem_object *obj_priv;
  321. struct drm_gem_object *obj;
  322. int pipe = intel_crtc->pipe;
  323. unsigned long Start, Offset;
  324. int dspbase = (pipe == 0 ? DSPAADDR : DSPBADDR);
  325. int dspsurf = (pipe == 0 ? DSPASURF : DSPBSURF);
  326. int dspstride = (pipe == 0) ? DSPASTRIDE : DSPBSTRIDE;
  327. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  328. u32 dspcntr, alignment;
  329. /* no fb bound */
  330. if (!crtc->fb) {
  331. DRM_DEBUG("No FB bound\n");
  332. return;
  333. }
  334. intel_fb = to_intel_framebuffer(crtc->fb);
  335. obj = intel_fb->obj;
  336. obj_priv = obj->driver_private;
  337. switch (obj_priv->tiling_mode) {
  338. case I915_TILING_NONE:
  339. alignment = 64 * 1024;
  340. break;
  341. case I915_TILING_X:
  342. if (IS_I9XX(dev))
  343. alignment = 1024 * 1024;
  344. else
  345. alignment = 512 * 1024;
  346. break;
  347. case I915_TILING_Y:
  348. /* FIXME: Is this true? */
  349. DRM_ERROR("Y tiled not allowed for scan out buffers\n");
  350. return;
  351. default:
  352. BUG();
  353. }
  354. if (i915_gem_object_pin(intel_fb->obj, alignment))
  355. return;
  356. i915_gem_object_set_to_gtt_domain(intel_fb->obj, 1);
  357. Start = obj_priv->gtt_offset;
  358. Offset = y * crtc->fb->pitch + x * (crtc->fb->bits_per_pixel / 8);
  359. I915_WRITE(dspstride, crtc->fb->pitch);
  360. dspcntr = I915_READ(dspcntr_reg);
  361. /* Mask out pixel format bits in case we change it */
  362. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  363. switch (crtc->fb->bits_per_pixel) {
  364. case 8:
  365. dspcntr |= DISPPLANE_8BPP;
  366. break;
  367. case 16:
  368. if (crtc->fb->depth == 15)
  369. dspcntr |= DISPPLANE_15_16BPP;
  370. else
  371. dspcntr |= DISPPLANE_16BPP;
  372. break;
  373. case 24:
  374. case 32:
  375. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  376. break;
  377. default:
  378. DRM_ERROR("Unknown color depth\n");
  379. return;
  380. }
  381. I915_WRITE(dspcntr_reg, dspcntr);
  382. DRM_DEBUG("Writing base %08lX %08lX %d %d\n", Start, Offset, x, y);
  383. if (IS_I965G(dev)) {
  384. I915_WRITE(dspbase, Offset);
  385. I915_READ(dspbase);
  386. I915_WRITE(dspsurf, Start);
  387. I915_READ(dspsurf);
  388. } else {
  389. I915_WRITE(dspbase, Start + Offset);
  390. I915_READ(dspbase);
  391. }
  392. intel_wait_for_vblank(dev);
  393. if (old_fb) {
  394. intel_fb = to_intel_framebuffer(old_fb);
  395. i915_gem_object_unpin(intel_fb->obj);
  396. }
  397. if (!dev->primary->master)
  398. return;
  399. master_priv = dev->primary->master->driver_priv;
  400. if (!master_priv->sarea_priv)
  401. return;
  402. switch (pipe) {
  403. case 0:
  404. master_priv->sarea_priv->pipeA_x = x;
  405. master_priv->sarea_priv->pipeA_y = y;
  406. break;
  407. case 1:
  408. master_priv->sarea_priv->pipeB_x = x;
  409. master_priv->sarea_priv->pipeB_y = y;
  410. break;
  411. default:
  412. DRM_ERROR("Can't update pipe %d in SAREA\n", pipe);
  413. break;
  414. }
  415. }
  416. /**
  417. * Sets the power management mode of the pipe and plane.
  418. *
  419. * This code should probably grow support for turning the cursor off and back
  420. * on appropriately at the same time as we're turning the pipe off/on.
  421. */
  422. static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
  423. {
  424. struct drm_device *dev = crtc->dev;
  425. struct drm_i915_master_private *master_priv;
  426. struct drm_i915_private *dev_priv = dev->dev_private;
  427. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  428. int pipe = intel_crtc->pipe;
  429. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  430. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  431. int dspbase_reg = (pipe == 0) ? DSPAADDR : DSPBADDR;
  432. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  433. u32 temp;
  434. bool enabled;
  435. /* XXX: When our outputs are all unaware of DPMS modes other than off
  436. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  437. */
  438. switch (mode) {
  439. case DRM_MODE_DPMS_ON:
  440. case DRM_MODE_DPMS_STANDBY:
  441. case DRM_MODE_DPMS_SUSPEND:
  442. /* Enable the DPLL */
  443. temp = I915_READ(dpll_reg);
  444. if ((temp & DPLL_VCO_ENABLE) == 0) {
  445. I915_WRITE(dpll_reg, temp);
  446. I915_READ(dpll_reg);
  447. /* Wait for the clocks to stabilize. */
  448. udelay(150);
  449. I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  450. I915_READ(dpll_reg);
  451. /* Wait for the clocks to stabilize. */
  452. udelay(150);
  453. I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  454. I915_READ(dpll_reg);
  455. /* Wait for the clocks to stabilize. */
  456. udelay(150);
  457. }
  458. /* Enable the pipe */
  459. temp = I915_READ(pipeconf_reg);
  460. if ((temp & PIPEACONF_ENABLE) == 0)
  461. I915_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE);
  462. /* Enable the plane */
  463. temp = I915_READ(dspcntr_reg);
  464. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  465. I915_WRITE(dspcntr_reg, temp | DISPLAY_PLANE_ENABLE);
  466. /* Flush the plane changes */
  467. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  468. }
  469. intel_crtc_load_lut(crtc);
  470. /* Give the overlay scaler a chance to enable if it's on this pipe */
  471. //intel_crtc_dpms_video(crtc, true); TODO
  472. break;
  473. case DRM_MODE_DPMS_OFF:
  474. /* Give the overlay scaler a chance to disable if it's on this pipe */
  475. //intel_crtc_dpms_video(crtc, FALSE); TODO
  476. /* Disable the VGA plane that we never use */
  477. I915_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  478. /* Disable display plane */
  479. temp = I915_READ(dspcntr_reg);
  480. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  481. I915_WRITE(dspcntr_reg, temp & ~DISPLAY_PLANE_ENABLE);
  482. /* Flush the plane changes */
  483. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  484. I915_READ(dspbase_reg);
  485. }
  486. if (!IS_I9XX(dev)) {
  487. /* Wait for vblank for the disable to take effect */
  488. intel_wait_for_vblank(dev);
  489. }
  490. /* Next, disable display pipes */
  491. temp = I915_READ(pipeconf_reg);
  492. if ((temp & PIPEACONF_ENABLE) != 0) {
  493. I915_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE);
  494. I915_READ(pipeconf_reg);
  495. }
  496. /* Wait for vblank for the disable to take effect. */
  497. intel_wait_for_vblank(dev);
  498. temp = I915_READ(dpll_reg);
  499. if ((temp & DPLL_VCO_ENABLE) != 0) {
  500. I915_WRITE(dpll_reg, temp & ~DPLL_VCO_ENABLE);
  501. I915_READ(dpll_reg);
  502. }
  503. /* Wait for the clocks to turn off. */
  504. udelay(150);
  505. break;
  506. }
  507. if (!dev->primary->master)
  508. return;
  509. master_priv = dev->primary->master->driver_priv;
  510. if (!master_priv->sarea_priv)
  511. return;
  512. enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
  513. switch (pipe) {
  514. case 0:
  515. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  516. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  517. break;
  518. case 1:
  519. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  520. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  521. break;
  522. default:
  523. DRM_ERROR("Can't update pipe %d in SAREA\n", pipe);
  524. break;
  525. }
  526. intel_crtc->dpms_mode = mode;
  527. }
  528. static void intel_crtc_prepare (struct drm_crtc *crtc)
  529. {
  530. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  531. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  532. }
  533. static void intel_crtc_commit (struct drm_crtc *crtc)
  534. {
  535. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  536. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  537. }
  538. void intel_encoder_prepare (struct drm_encoder *encoder)
  539. {
  540. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  541. /* lvds has its own version of prepare see intel_lvds_prepare */
  542. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
  543. }
  544. void intel_encoder_commit (struct drm_encoder *encoder)
  545. {
  546. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  547. /* lvds has its own version of commit see intel_lvds_commit */
  548. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  549. }
  550. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  551. struct drm_display_mode *mode,
  552. struct drm_display_mode *adjusted_mode)
  553. {
  554. return true;
  555. }
  556. /** Returns the core display clock speed for i830 - i945 */
  557. static int intel_get_core_clock_speed(struct drm_device *dev)
  558. {
  559. /* Core clock values taken from the published datasheets.
  560. * The 830 may go up to 166 Mhz, which we should check.
  561. */
  562. if (IS_I945G(dev))
  563. return 400000;
  564. else if (IS_I915G(dev))
  565. return 333000;
  566. else if (IS_I945GM(dev) || IS_845G(dev))
  567. return 200000;
  568. else if (IS_I915GM(dev)) {
  569. u16 gcfgc = 0;
  570. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  571. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  572. return 133000;
  573. else {
  574. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  575. case GC_DISPLAY_CLOCK_333_MHZ:
  576. return 333000;
  577. default:
  578. case GC_DISPLAY_CLOCK_190_200_MHZ:
  579. return 190000;
  580. }
  581. }
  582. } else if (IS_I865G(dev))
  583. return 266000;
  584. else if (IS_I855(dev)) {
  585. u16 hpllcc = 0;
  586. /* Assume that the hardware is in the high speed state. This
  587. * should be the default.
  588. */
  589. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  590. case GC_CLOCK_133_200:
  591. case GC_CLOCK_100_200:
  592. return 200000;
  593. case GC_CLOCK_166_250:
  594. return 250000;
  595. case GC_CLOCK_100_133:
  596. return 133000;
  597. }
  598. } else /* 852, 830 */
  599. return 133000;
  600. return 0; /* Silence gcc warning */
  601. }
  602. /**
  603. * Return the pipe currently connected to the panel fitter,
  604. * or -1 if the panel fitter is not present or not in use
  605. */
  606. static int intel_panel_fitter_pipe (struct drm_device *dev)
  607. {
  608. struct drm_i915_private *dev_priv = dev->dev_private;
  609. u32 pfit_control;
  610. /* i830 doesn't have a panel fitter */
  611. if (IS_I830(dev))
  612. return -1;
  613. pfit_control = I915_READ(PFIT_CONTROL);
  614. /* See if the panel fitter is in use */
  615. if ((pfit_control & PFIT_ENABLE) == 0)
  616. return -1;
  617. /* 965 can place panel fitter on either pipe */
  618. if (IS_I965G(dev))
  619. return (pfit_control >> 29) & 0x3;
  620. /* older chips can only use pipe 1 */
  621. return 1;
  622. }
  623. static void intel_crtc_mode_set(struct drm_crtc *crtc,
  624. struct drm_display_mode *mode,
  625. struct drm_display_mode *adjusted_mode,
  626. int x, int y,
  627. struct drm_framebuffer *old_fb)
  628. {
  629. struct drm_device *dev = crtc->dev;
  630. struct drm_i915_private *dev_priv = dev->dev_private;
  631. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  632. int pipe = intel_crtc->pipe;
  633. int fp_reg = (pipe == 0) ? FPA0 : FPB0;
  634. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  635. int dpll_md_reg = (intel_crtc->pipe == 0) ? DPLL_A_MD : DPLL_B_MD;
  636. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  637. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  638. int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
  639. int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
  640. int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
  641. int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
  642. int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
  643. int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
  644. int dspsize_reg = (pipe == 0) ? DSPASIZE : DSPBSIZE;
  645. int dsppos_reg = (pipe == 0) ? DSPAPOS : DSPBPOS;
  646. int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC;
  647. int refclk;
  648. intel_clock_t clock;
  649. u32 dpll = 0, fp = 0, dspcntr, pipeconf;
  650. bool ok, is_sdvo = false, is_dvo = false;
  651. bool is_crt = false, is_lvds = false, is_tv = false;
  652. struct drm_mode_config *mode_config = &dev->mode_config;
  653. struct drm_connector *connector;
  654. drm_vblank_pre_modeset(dev, pipe);
  655. list_for_each_entry(connector, &mode_config->connector_list, head) {
  656. struct intel_output *intel_output = to_intel_output(connector);
  657. if (!connector->encoder || connector->encoder->crtc != crtc)
  658. continue;
  659. switch (intel_output->type) {
  660. case INTEL_OUTPUT_LVDS:
  661. is_lvds = true;
  662. break;
  663. case INTEL_OUTPUT_SDVO:
  664. case INTEL_OUTPUT_HDMI:
  665. is_sdvo = true;
  666. break;
  667. case INTEL_OUTPUT_DVO:
  668. is_dvo = true;
  669. break;
  670. case INTEL_OUTPUT_TVOUT:
  671. is_tv = true;
  672. break;
  673. case INTEL_OUTPUT_ANALOG:
  674. is_crt = true;
  675. break;
  676. }
  677. }
  678. if (IS_I9XX(dev)) {
  679. refclk = 96000;
  680. } else {
  681. refclk = 48000;
  682. }
  683. ok = intel_find_best_PLL(crtc, adjusted_mode->clock, refclk, &clock);
  684. if (!ok) {
  685. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  686. return;
  687. }
  688. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  689. dpll = DPLL_VGA_MODE_DIS;
  690. if (IS_I9XX(dev)) {
  691. if (is_lvds)
  692. dpll |= DPLLB_MODE_LVDS;
  693. else
  694. dpll |= DPLLB_MODE_DAC_SERIAL;
  695. if (is_sdvo) {
  696. dpll |= DPLL_DVO_HIGH_SPEED;
  697. if (IS_I945G(dev) || IS_I945GM(dev)) {
  698. int sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  699. dpll |= (sdvo_pixel_multiply - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  700. }
  701. }
  702. /* compute bitmask from p1 value */
  703. dpll |= (1 << (clock.p1 - 1)) << 16;
  704. switch (clock.p2) {
  705. case 5:
  706. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  707. break;
  708. case 7:
  709. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  710. break;
  711. case 10:
  712. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  713. break;
  714. case 14:
  715. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  716. break;
  717. }
  718. if (IS_I965G(dev))
  719. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  720. } else {
  721. if (is_lvds) {
  722. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  723. } else {
  724. if (clock.p1 == 2)
  725. dpll |= PLL_P1_DIVIDE_BY_TWO;
  726. else
  727. dpll |= (clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  728. if (clock.p2 == 4)
  729. dpll |= PLL_P2_DIVIDE_BY_4;
  730. }
  731. }
  732. if (is_tv) {
  733. /* XXX: just matching BIOS for now */
  734. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  735. dpll |= 3;
  736. }
  737. else
  738. dpll |= PLL_REF_INPUT_DREFCLK;
  739. /* setup pipeconf */
  740. pipeconf = I915_READ(pipeconf_reg);
  741. /* Set up the display plane register */
  742. dspcntr = DISPPLANE_GAMMA_ENABLE;
  743. if (pipe == 0)
  744. dspcntr |= DISPPLANE_SEL_PIPE_A;
  745. else
  746. dspcntr |= DISPPLANE_SEL_PIPE_B;
  747. if (pipe == 0 && !IS_I965G(dev)) {
  748. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  749. * core speed.
  750. *
  751. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  752. * pipe == 0 check?
  753. */
  754. if (mode->clock > intel_get_core_clock_speed(dev) * 9 / 10)
  755. pipeconf |= PIPEACONF_DOUBLE_WIDE;
  756. else
  757. pipeconf &= ~PIPEACONF_DOUBLE_WIDE;
  758. }
  759. dspcntr |= DISPLAY_PLANE_ENABLE;
  760. pipeconf |= PIPEACONF_ENABLE;
  761. dpll |= DPLL_VCO_ENABLE;
  762. /* Disable the panel fitter if it was on our pipe */
  763. if (intel_panel_fitter_pipe(dev) == pipe)
  764. I915_WRITE(PFIT_CONTROL, 0);
  765. DRM_DEBUG("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  766. drm_mode_debug_printmodeline(mode);
  767. if (dpll & DPLL_VCO_ENABLE) {
  768. I915_WRITE(fp_reg, fp);
  769. I915_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE);
  770. I915_READ(dpll_reg);
  771. udelay(150);
  772. }
  773. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  774. * This is an exception to the general rule that mode_set doesn't turn
  775. * things on.
  776. */
  777. if (is_lvds) {
  778. u32 lvds = I915_READ(LVDS);
  779. lvds |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP | LVDS_PIPEB_SELECT;
  780. /* Set the B0-B3 data pairs corresponding to whether we're going to
  781. * set the DPLLs for dual-channel mode or not.
  782. */
  783. if (clock.p2 == 7)
  784. lvds |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  785. else
  786. lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  787. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  788. * appropriately here, but we need to look more thoroughly into how
  789. * panels behave in the two modes.
  790. */
  791. I915_WRITE(LVDS, lvds);
  792. I915_READ(LVDS);
  793. }
  794. I915_WRITE(fp_reg, fp);
  795. I915_WRITE(dpll_reg, dpll);
  796. I915_READ(dpll_reg);
  797. /* Wait for the clocks to stabilize. */
  798. udelay(150);
  799. if (IS_I965G(dev)) {
  800. int sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  801. I915_WRITE(dpll_md_reg, (0 << DPLL_MD_UDI_DIVIDER_SHIFT) |
  802. ((sdvo_pixel_multiply - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT));
  803. } else {
  804. /* write it again -- the BIOS does, after all */
  805. I915_WRITE(dpll_reg, dpll);
  806. }
  807. I915_READ(dpll_reg);
  808. /* Wait for the clocks to stabilize. */
  809. udelay(150);
  810. I915_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) |
  811. ((adjusted_mode->crtc_htotal - 1) << 16));
  812. I915_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) |
  813. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  814. I915_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) |
  815. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  816. I915_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) |
  817. ((adjusted_mode->crtc_vtotal - 1) << 16));
  818. I915_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) |
  819. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  820. I915_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) |
  821. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  822. /* pipesrc and dspsize control the size that is scaled from, which should
  823. * always be the user's requested size.
  824. */
  825. I915_WRITE(dspsize_reg, ((mode->vdisplay - 1) << 16) | (mode->hdisplay - 1));
  826. I915_WRITE(dsppos_reg, 0);
  827. I915_WRITE(pipesrc_reg, ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  828. I915_WRITE(pipeconf_reg, pipeconf);
  829. I915_READ(pipeconf_reg);
  830. intel_wait_for_vblank(dev);
  831. I915_WRITE(dspcntr_reg, dspcntr);
  832. /* Flush the plane changes */
  833. intel_pipe_set_base(crtc, x, y, old_fb);
  834. drm_vblank_post_modeset(dev, pipe);
  835. }
  836. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  837. void intel_crtc_load_lut(struct drm_crtc *crtc)
  838. {
  839. struct drm_device *dev = crtc->dev;
  840. struct drm_i915_private *dev_priv = dev->dev_private;
  841. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  842. int palreg = (intel_crtc->pipe == 0) ? PALETTE_A : PALETTE_B;
  843. int i;
  844. /* The clocks have to be on to load the palette. */
  845. if (!crtc->enabled)
  846. return;
  847. for (i = 0; i < 256; i++) {
  848. I915_WRITE(palreg + 4 * i,
  849. (intel_crtc->lut_r[i] << 16) |
  850. (intel_crtc->lut_g[i] << 8) |
  851. intel_crtc->lut_b[i]);
  852. }
  853. }
  854. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  855. struct drm_file *file_priv,
  856. uint32_t handle,
  857. uint32_t width, uint32_t height)
  858. {
  859. struct drm_device *dev = crtc->dev;
  860. struct drm_i915_private *dev_priv = dev->dev_private;
  861. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  862. struct drm_gem_object *bo;
  863. struct drm_i915_gem_object *obj_priv;
  864. int pipe = intel_crtc->pipe;
  865. uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR;
  866. uint32_t base = (pipe == 0) ? CURABASE : CURBBASE;
  867. uint32_t temp;
  868. size_t addr;
  869. int ret;
  870. DRM_DEBUG("\n");
  871. /* if we want to turn off the cursor ignore width and height */
  872. if (!handle) {
  873. DRM_DEBUG("cursor off\n");
  874. temp = CURSOR_MODE_DISABLE;
  875. addr = 0;
  876. bo = NULL;
  877. goto finish;
  878. }
  879. /* Currently we only support 64x64 cursors */
  880. if (width != 64 || height != 64) {
  881. DRM_ERROR("we currently only support 64x64 cursors\n");
  882. return -EINVAL;
  883. }
  884. bo = drm_gem_object_lookup(dev, file_priv, handle);
  885. if (!bo)
  886. return -ENOENT;
  887. obj_priv = bo->driver_private;
  888. if (bo->size < width * height * 4) {
  889. DRM_ERROR("buffer is to small\n");
  890. drm_gem_object_unreference(bo);
  891. return -ENOMEM;
  892. }
  893. /* we only need to pin inside GTT if cursor is non-phy */
  894. if (!dev_priv->cursor_needs_physical) {
  895. ret = i915_gem_object_pin(bo, PAGE_SIZE);
  896. if (ret) {
  897. DRM_ERROR("failed to pin cursor bo\n");
  898. drm_gem_object_unreference(bo);
  899. return ret;
  900. }
  901. addr = obj_priv->gtt_offset;
  902. } else {
  903. ret = i915_gem_attach_phys_object(dev, bo, (pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1);
  904. if (ret) {
  905. DRM_ERROR("failed to attach phys object\n");
  906. drm_gem_object_unreference(bo);
  907. return ret;
  908. }
  909. addr = obj_priv->phys_obj->handle->busaddr;
  910. }
  911. temp = 0;
  912. /* set the pipe for the cursor */
  913. temp |= (pipe << 28);
  914. temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  915. finish:
  916. I915_WRITE(control, temp);
  917. I915_WRITE(base, addr);
  918. if (intel_crtc->cursor_bo) {
  919. if (dev_priv->cursor_needs_physical) {
  920. if (intel_crtc->cursor_bo != bo)
  921. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  922. } else
  923. i915_gem_object_unpin(intel_crtc->cursor_bo);
  924. drm_gem_object_unreference(intel_crtc->cursor_bo);
  925. }
  926. intel_crtc->cursor_addr = addr;
  927. intel_crtc->cursor_bo = bo;
  928. return 0;
  929. }
  930. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  931. {
  932. struct drm_device *dev = crtc->dev;
  933. struct drm_i915_private *dev_priv = dev->dev_private;
  934. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  935. int pipe = intel_crtc->pipe;
  936. uint32_t temp = 0;
  937. uint32_t adder;
  938. if (x < 0) {
  939. temp |= (CURSOR_POS_SIGN << CURSOR_X_SHIFT);
  940. x = -x;
  941. }
  942. if (y < 0) {
  943. temp |= (CURSOR_POS_SIGN << CURSOR_Y_SHIFT);
  944. y = -y;
  945. }
  946. temp |= ((x & CURSOR_POS_MASK) << CURSOR_X_SHIFT);
  947. temp |= ((y & CURSOR_POS_MASK) << CURSOR_Y_SHIFT);
  948. adder = intel_crtc->cursor_addr;
  949. I915_WRITE((pipe == 0) ? CURAPOS : CURBPOS, temp);
  950. I915_WRITE((pipe == 0) ? CURABASE : CURBBASE, adder);
  951. return 0;
  952. }
  953. /** Sets the color ramps on behalf of RandR */
  954. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  955. u16 blue, int regno)
  956. {
  957. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  958. intel_crtc->lut_r[regno] = red >> 8;
  959. intel_crtc->lut_g[regno] = green >> 8;
  960. intel_crtc->lut_b[regno] = blue >> 8;
  961. }
  962. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  963. u16 *blue, uint32_t size)
  964. {
  965. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  966. int i;
  967. if (size != 256)
  968. return;
  969. for (i = 0; i < 256; i++) {
  970. intel_crtc->lut_r[i] = red[i] >> 8;
  971. intel_crtc->lut_g[i] = green[i] >> 8;
  972. intel_crtc->lut_b[i] = blue[i] >> 8;
  973. }
  974. intel_crtc_load_lut(crtc);
  975. }
  976. /**
  977. * Get a pipe with a simple mode set on it for doing load-based monitor
  978. * detection.
  979. *
  980. * It will be up to the load-detect code to adjust the pipe as appropriate for
  981. * its requirements. The pipe will be connected to no other outputs.
  982. *
  983. * Currently this code will only succeed if there is a pipe with no outputs
  984. * configured for it. In the future, it could choose to temporarily disable
  985. * some outputs to free up a pipe for its use.
  986. *
  987. * \return crtc, or NULL if no pipes are available.
  988. */
  989. /* VESA 640x480x72Hz mode to set on the pipe */
  990. static struct drm_display_mode load_detect_mode = {
  991. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  992. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  993. };
  994. struct drm_crtc *intel_get_load_detect_pipe(struct intel_output *intel_output,
  995. struct drm_display_mode *mode,
  996. int *dpms_mode)
  997. {
  998. struct intel_crtc *intel_crtc;
  999. struct drm_crtc *possible_crtc;
  1000. struct drm_crtc *supported_crtc =NULL;
  1001. struct drm_encoder *encoder = &intel_output->enc;
  1002. struct drm_crtc *crtc = NULL;
  1003. struct drm_device *dev = encoder->dev;
  1004. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  1005. struct drm_crtc_helper_funcs *crtc_funcs;
  1006. int i = -1;
  1007. /*
  1008. * Algorithm gets a little messy:
  1009. * - if the connector already has an assigned crtc, use it (but make
  1010. * sure it's on first)
  1011. * - try to find the first unused crtc that can drive this connector,
  1012. * and use that if we find one
  1013. * - if there are no unused crtcs available, try to use the first
  1014. * one we found that supports the connector
  1015. */
  1016. /* See if we already have a CRTC for this connector */
  1017. if (encoder->crtc) {
  1018. crtc = encoder->crtc;
  1019. /* Make sure the crtc and connector are running */
  1020. intel_crtc = to_intel_crtc(crtc);
  1021. *dpms_mode = intel_crtc->dpms_mode;
  1022. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  1023. crtc_funcs = crtc->helper_private;
  1024. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  1025. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  1026. }
  1027. return crtc;
  1028. }
  1029. /* Find an unused one (if possible) */
  1030. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  1031. i++;
  1032. if (!(encoder->possible_crtcs & (1 << i)))
  1033. continue;
  1034. if (!possible_crtc->enabled) {
  1035. crtc = possible_crtc;
  1036. break;
  1037. }
  1038. if (!supported_crtc)
  1039. supported_crtc = possible_crtc;
  1040. }
  1041. /*
  1042. * If we didn't find an unused CRTC, don't use any.
  1043. */
  1044. if (!crtc) {
  1045. return NULL;
  1046. }
  1047. encoder->crtc = crtc;
  1048. intel_output->load_detect_temp = true;
  1049. intel_crtc = to_intel_crtc(crtc);
  1050. *dpms_mode = intel_crtc->dpms_mode;
  1051. if (!crtc->enabled) {
  1052. if (!mode)
  1053. mode = &load_detect_mode;
  1054. drm_crtc_helper_set_mode(crtc, mode, 0, 0, crtc->fb);
  1055. } else {
  1056. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  1057. crtc_funcs = crtc->helper_private;
  1058. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  1059. }
  1060. /* Add this connector to the crtc */
  1061. encoder_funcs->mode_set(encoder, &crtc->mode, &crtc->mode);
  1062. encoder_funcs->commit(encoder);
  1063. }
  1064. /* let the connector get through one full cycle before testing */
  1065. intel_wait_for_vblank(dev);
  1066. return crtc;
  1067. }
  1068. void intel_release_load_detect_pipe(struct intel_output *intel_output, int dpms_mode)
  1069. {
  1070. struct drm_encoder *encoder = &intel_output->enc;
  1071. struct drm_device *dev = encoder->dev;
  1072. struct drm_crtc *crtc = encoder->crtc;
  1073. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  1074. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  1075. if (intel_output->load_detect_temp) {
  1076. encoder->crtc = NULL;
  1077. intel_output->load_detect_temp = false;
  1078. crtc->enabled = drm_helper_crtc_in_use(crtc);
  1079. drm_helper_disable_unused_functions(dev);
  1080. }
  1081. /* Switch crtc and output back off if necessary */
  1082. if (crtc->enabled && dpms_mode != DRM_MODE_DPMS_ON) {
  1083. if (encoder->crtc == crtc)
  1084. encoder_funcs->dpms(encoder, dpms_mode);
  1085. crtc_funcs->dpms(crtc, dpms_mode);
  1086. }
  1087. }
  1088. /* Returns the clock of the currently programmed mode of the given pipe. */
  1089. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  1090. {
  1091. struct drm_i915_private *dev_priv = dev->dev_private;
  1092. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1093. int pipe = intel_crtc->pipe;
  1094. u32 dpll = I915_READ((pipe == 0) ? DPLL_A : DPLL_B);
  1095. u32 fp;
  1096. intel_clock_t clock;
  1097. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  1098. fp = I915_READ((pipe == 0) ? FPA0 : FPB0);
  1099. else
  1100. fp = I915_READ((pipe == 0) ? FPA1 : FPB1);
  1101. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  1102. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  1103. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  1104. if (IS_I9XX(dev)) {
  1105. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  1106. DPLL_FPA01_P1_POST_DIV_SHIFT);
  1107. switch (dpll & DPLL_MODE_MASK) {
  1108. case DPLLB_MODE_DAC_SERIAL:
  1109. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  1110. 5 : 10;
  1111. break;
  1112. case DPLLB_MODE_LVDS:
  1113. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  1114. 7 : 14;
  1115. break;
  1116. default:
  1117. DRM_DEBUG("Unknown DPLL mode %08x in programmed "
  1118. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  1119. return 0;
  1120. }
  1121. /* XXX: Handle the 100Mhz refclk */
  1122. i9xx_clock(96000, &clock);
  1123. } else {
  1124. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  1125. if (is_lvds) {
  1126. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  1127. DPLL_FPA01_P1_POST_DIV_SHIFT);
  1128. clock.p2 = 14;
  1129. if ((dpll & PLL_REF_INPUT_MASK) ==
  1130. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  1131. /* XXX: might not be 66MHz */
  1132. i8xx_clock(66000, &clock);
  1133. } else
  1134. i8xx_clock(48000, &clock);
  1135. } else {
  1136. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  1137. clock.p1 = 2;
  1138. else {
  1139. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  1140. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  1141. }
  1142. if (dpll & PLL_P2_DIVIDE_BY_4)
  1143. clock.p2 = 4;
  1144. else
  1145. clock.p2 = 2;
  1146. i8xx_clock(48000, &clock);
  1147. }
  1148. }
  1149. /* XXX: It would be nice to validate the clocks, but we can't reuse
  1150. * i830PllIsValid() because it relies on the xf86_config connector
  1151. * configuration being accurate, which it isn't necessarily.
  1152. */
  1153. return clock.dot;
  1154. }
  1155. /** Returns the currently programmed mode of the given pipe. */
  1156. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  1157. struct drm_crtc *crtc)
  1158. {
  1159. struct drm_i915_private *dev_priv = dev->dev_private;
  1160. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1161. int pipe = intel_crtc->pipe;
  1162. struct drm_display_mode *mode;
  1163. int htot = I915_READ((pipe == 0) ? HTOTAL_A : HTOTAL_B);
  1164. int hsync = I915_READ((pipe == 0) ? HSYNC_A : HSYNC_B);
  1165. int vtot = I915_READ((pipe == 0) ? VTOTAL_A : VTOTAL_B);
  1166. int vsync = I915_READ((pipe == 0) ? VSYNC_A : VSYNC_B);
  1167. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  1168. if (!mode)
  1169. return NULL;
  1170. mode->clock = intel_crtc_clock_get(dev, crtc);
  1171. mode->hdisplay = (htot & 0xffff) + 1;
  1172. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  1173. mode->hsync_start = (hsync & 0xffff) + 1;
  1174. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  1175. mode->vdisplay = (vtot & 0xffff) + 1;
  1176. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  1177. mode->vsync_start = (vsync & 0xffff) + 1;
  1178. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  1179. drm_mode_set_name(mode);
  1180. drm_mode_set_crtcinfo(mode, 0);
  1181. return mode;
  1182. }
  1183. static void intel_crtc_destroy(struct drm_crtc *crtc)
  1184. {
  1185. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1186. drm_crtc_cleanup(crtc);
  1187. kfree(intel_crtc);
  1188. }
  1189. static const struct drm_crtc_helper_funcs intel_helper_funcs = {
  1190. .dpms = intel_crtc_dpms,
  1191. .mode_fixup = intel_crtc_mode_fixup,
  1192. .mode_set = intel_crtc_mode_set,
  1193. .mode_set_base = intel_pipe_set_base,
  1194. .prepare = intel_crtc_prepare,
  1195. .commit = intel_crtc_commit,
  1196. };
  1197. static const struct drm_crtc_funcs intel_crtc_funcs = {
  1198. .cursor_set = intel_crtc_cursor_set,
  1199. .cursor_move = intel_crtc_cursor_move,
  1200. .gamma_set = intel_crtc_gamma_set,
  1201. .set_config = drm_crtc_helper_set_config,
  1202. .destroy = intel_crtc_destroy,
  1203. };
  1204. static void intel_crtc_init(struct drm_device *dev, int pipe)
  1205. {
  1206. struct intel_crtc *intel_crtc;
  1207. int i;
  1208. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  1209. if (intel_crtc == NULL)
  1210. return;
  1211. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  1212. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  1213. intel_crtc->pipe = pipe;
  1214. for (i = 0; i < 256; i++) {
  1215. intel_crtc->lut_r[i] = i;
  1216. intel_crtc->lut_g[i] = i;
  1217. intel_crtc->lut_b[i] = i;
  1218. }
  1219. intel_crtc->cursor_addr = 0;
  1220. intel_crtc->dpms_mode = DRM_MODE_DPMS_OFF;
  1221. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  1222. intel_crtc->mode_set.crtc = &intel_crtc->base;
  1223. intel_crtc->mode_set.connectors = (struct drm_connector **)(intel_crtc + 1);
  1224. intel_crtc->mode_set.num_connectors = 0;
  1225. if (i915_fbpercrtc) {
  1226. }
  1227. }
  1228. struct drm_crtc *intel_get_crtc_from_pipe(struct drm_device *dev, int pipe)
  1229. {
  1230. struct drm_crtc *crtc = NULL;
  1231. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1232. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1233. if (intel_crtc->pipe == pipe)
  1234. break;
  1235. }
  1236. return crtc;
  1237. }
  1238. static int intel_connector_clones(struct drm_device *dev, int type_mask)
  1239. {
  1240. int index_mask = 0;
  1241. struct drm_connector *connector;
  1242. int entry = 0;
  1243. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1244. struct intel_output *intel_output = to_intel_output(connector);
  1245. if (type_mask & (1 << intel_output->type))
  1246. index_mask |= (1 << entry);
  1247. entry++;
  1248. }
  1249. return index_mask;
  1250. }
  1251. static void intel_setup_outputs(struct drm_device *dev)
  1252. {
  1253. struct drm_connector *connector;
  1254. intel_crt_init(dev);
  1255. /* Set up integrated LVDS */
  1256. if (IS_MOBILE(dev) && !IS_I830(dev))
  1257. intel_lvds_init(dev);
  1258. if (IS_I9XX(dev)) {
  1259. int found;
  1260. found = intel_sdvo_init(dev, SDVOB);
  1261. if (!found && SUPPORTS_INTEGRATED_HDMI(dev))
  1262. intel_hdmi_init(dev, SDVOB);
  1263. found = intel_sdvo_init(dev, SDVOC);
  1264. if (!found && SUPPORTS_INTEGRATED_HDMI(dev))
  1265. intel_hdmi_init(dev, SDVOC);
  1266. } else
  1267. intel_dvo_init(dev);
  1268. if (IS_I9XX(dev) && IS_MOBILE(dev))
  1269. intel_tv_init(dev);
  1270. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1271. struct intel_output *intel_output = to_intel_output(connector);
  1272. struct drm_encoder *encoder = &intel_output->enc;
  1273. int crtc_mask = 0, clone_mask = 0;
  1274. /* valid crtcs */
  1275. switch(intel_output->type) {
  1276. case INTEL_OUTPUT_HDMI:
  1277. crtc_mask = ((1 << 0)|
  1278. (1 << 1));
  1279. clone_mask = ((1 << INTEL_OUTPUT_HDMI));
  1280. break;
  1281. case INTEL_OUTPUT_DVO:
  1282. case INTEL_OUTPUT_SDVO:
  1283. crtc_mask = ((1 << 0)|
  1284. (1 << 1));
  1285. clone_mask = ((1 << INTEL_OUTPUT_ANALOG) |
  1286. (1 << INTEL_OUTPUT_DVO) |
  1287. (1 << INTEL_OUTPUT_SDVO));
  1288. break;
  1289. case INTEL_OUTPUT_ANALOG:
  1290. crtc_mask = ((1 << 0)|
  1291. (1 << 1));
  1292. clone_mask = ((1 << INTEL_OUTPUT_ANALOG) |
  1293. (1 << INTEL_OUTPUT_DVO) |
  1294. (1 << INTEL_OUTPUT_SDVO));
  1295. break;
  1296. case INTEL_OUTPUT_LVDS:
  1297. crtc_mask = (1 << 1);
  1298. clone_mask = (1 << INTEL_OUTPUT_LVDS);
  1299. break;
  1300. case INTEL_OUTPUT_TVOUT:
  1301. crtc_mask = ((1 << 0) |
  1302. (1 << 1));
  1303. clone_mask = (1 << INTEL_OUTPUT_TVOUT);
  1304. break;
  1305. }
  1306. encoder->possible_crtcs = crtc_mask;
  1307. encoder->possible_clones = intel_connector_clones(dev, clone_mask);
  1308. }
  1309. }
  1310. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  1311. {
  1312. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1313. struct drm_device *dev = fb->dev;
  1314. if (fb->fbdev)
  1315. intelfb_remove(dev, fb);
  1316. drm_framebuffer_cleanup(fb);
  1317. mutex_lock(&dev->struct_mutex);
  1318. drm_gem_object_unreference(intel_fb->obj);
  1319. mutex_unlock(&dev->struct_mutex);
  1320. kfree(intel_fb);
  1321. }
  1322. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  1323. struct drm_file *file_priv,
  1324. unsigned int *handle)
  1325. {
  1326. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1327. struct drm_gem_object *object = intel_fb->obj;
  1328. return drm_gem_handle_create(file_priv, object, handle);
  1329. }
  1330. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  1331. .destroy = intel_user_framebuffer_destroy,
  1332. .create_handle = intel_user_framebuffer_create_handle,
  1333. };
  1334. int intel_framebuffer_create(struct drm_device *dev,
  1335. struct drm_mode_fb_cmd *mode_cmd,
  1336. struct drm_framebuffer **fb,
  1337. struct drm_gem_object *obj)
  1338. {
  1339. struct intel_framebuffer *intel_fb;
  1340. int ret;
  1341. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  1342. if (!intel_fb)
  1343. return -ENOMEM;
  1344. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  1345. if (ret) {
  1346. DRM_ERROR("framebuffer init failed %d\n", ret);
  1347. return ret;
  1348. }
  1349. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  1350. intel_fb->obj = obj;
  1351. *fb = &intel_fb->base;
  1352. return 0;
  1353. }
  1354. static struct drm_framebuffer *
  1355. intel_user_framebuffer_create(struct drm_device *dev,
  1356. struct drm_file *filp,
  1357. struct drm_mode_fb_cmd *mode_cmd)
  1358. {
  1359. struct drm_gem_object *obj;
  1360. struct drm_framebuffer *fb;
  1361. int ret;
  1362. obj = drm_gem_object_lookup(dev, filp, mode_cmd->handle);
  1363. if (!obj)
  1364. return NULL;
  1365. ret = intel_framebuffer_create(dev, mode_cmd, &fb, obj);
  1366. if (ret) {
  1367. drm_gem_object_unreference(obj);
  1368. return NULL;
  1369. }
  1370. return fb;
  1371. }
  1372. static const struct drm_mode_config_funcs intel_mode_funcs = {
  1373. .fb_create = intel_user_framebuffer_create,
  1374. .fb_changed = intelfb_probe,
  1375. };
  1376. void intel_modeset_init(struct drm_device *dev)
  1377. {
  1378. int num_pipe;
  1379. int i;
  1380. drm_mode_config_init(dev);
  1381. dev->mode_config.min_width = 0;
  1382. dev->mode_config.min_height = 0;
  1383. dev->mode_config.funcs = (void *)&intel_mode_funcs;
  1384. if (IS_I965G(dev)) {
  1385. dev->mode_config.max_width = 8192;
  1386. dev->mode_config.max_height = 8192;
  1387. } else {
  1388. dev->mode_config.max_width = 2048;
  1389. dev->mode_config.max_height = 2048;
  1390. }
  1391. /* set memory base */
  1392. if (IS_I9XX(dev))
  1393. dev->mode_config.fb_base = pci_resource_start(dev->pdev, 2);
  1394. else
  1395. dev->mode_config.fb_base = pci_resource_start(dev->pdev, 0);
  1396. if (IS_MOBILE(dev) || IS_I9XX(dev))
  1397. num_pipe = 2;
  1398. else
  1399. num_pipe = 1;
  1400. DRM_DEBUG("%d display pipe%s available.\n",
  1401. num_pipe, num_pipe > 1 ? "s" : "");
  1402. for (i = 0; i < num_pipe; i++) {
  1403. intel_crtc_init(dev, i);
  1404. }
  1405. intel_setup_outputs(dev);
  1406. }
  1407. void intel_modeset_cleanup(struct drm_device *dev)
  1408. {
  1409. drm_mode_config_cleanup(dev);
  1410. }
  1411. /* current intel driver doesn't take advantage of encoders
  1412. always give back the encoder for the connector
  1413. */
  1414. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  1415. {
  1416. struct intel_output *intel_output = to_intel_output(connector);
  1417. return &intel_output->enc;
  1418. }