1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright © 2006-2007 Intel Corporation
6 * Eric Anholt <eric@anholt.net>
9 #include <linux/delay.h>
10 #include <linux/i2c.h>
11 #include <linux/pm_runtime.h>
13 #include <drm/drm_crtc.h>
14 #include <drm/drm_fourcc.h>
16 #include "framebuffer.h"
17 #include "gma_display.h"
18 #include "mdfld_dsi_output.h"
19 #include "mdfld_output.h"
20 #include "psb_intel_reg.h"
22 /* Hardcoded currently */
23 static int ksel = KSEL_CRYSTAL_19;
25 struct psb_intel_range_t {
30 struct psb_intel_range_t dot, m, p1;
40 #define COUNT_MAX 0x10000000
42 void mdfldWaitForPipeDisable(struct drm_device *dev, int pipe)
44 struct drm_psb_private *dev_priv = dev->dev_private;
45 const struct psb_offset *map = &dev_priv->regmap[pipe];
54 DRM_ERROR("Illegal Pipe Number.\n");
59 gma_wait_for_vblank(dev);
62 /* Wait for for the pipe disable to take effect. */
63 for (count = 0; count < COUNT_MAX; count++) {
64 temp = REG_READ(map->conf);
65 if ((temp & PIPEACONF_PIPE_STATE) == 0)
70 void mdfldWaitForPipeEnable(struct drm_device *dev, int pipe)
72 struct drm_psb_private *dev_priv = dev->dev_private;
73 const struct psb_offset *map = &dev_priv->regmap[pipe];
82 DRM_ERROR("Illegal Pipe Number.\n");
87 gma_wait_for_vblank(dev);
90 /* Wait for for the pipe enable to take effect. */
91 for (count = 0; count < COUNT_MAX; count++) {
92 temp = REG_READ(map->conf);
93 if (temp & PIPEACONF_PIPE_STATE)
99 * Return the pipe currently connected to the panel fitter,
100 * or -1 if the panel fitter is not present or not in use
102 static int psb_intel_panel_fitter_pipe(struct drm_device *dev)
106 pfit_control = REG_READ(PFIT_CONTROL);
108 /* See if the panel fitter is in use */
109 if ((pfit_control & PFIT_ENABLE) == 0)
112 /* 965 can place panel fitter on either pipe */
113 return (pfit_control >> 29) & 0x3;
116 static struct drm_device globle_dev;
118 void mdfld__intel_plane_set_alpha(int enable)
120 struct drm_device *dev = &globle_dev;
121 int dspcntr_reg = DSPACNTR;
124 dspcntr = REG_READ(dspcntr_reg);
127 dspcntr &= ~DISPPLANE_32BPP_NO_ALPHA;
128 dspcntr |= DISPPLANE_32BPP;
130 dspcntr &= ~DISPPLANE_32BPP;
131 dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
134 REG_WRITE(dspcntr_reg, dspcntr);
137 static int check_fb(struct drm_framebuffer *fb)
142 switch (fb->format->cpp[0] * 8) {
149 DRM_ERROR("Unknown color depth\n");
154 static int mdfld__intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
155 struct drm_framebuffer *old_fb)
157 struct drm_device *dev = crtc->dev;
158 struct drm_psb_private *dev_priv = dev->dev_private;
159 struct drm_framebuffer *fb = crtc->primary->fb;
160 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
161 int pipe = gma_crtc->pipe;
162 const struct psb_offset *map = &dev_priv->regmap[pipe];
163 unsigned long start, offset;
167 memcpy(&globle_dev, dev, sizeof(struct drm_device));
169 dev_dbg(dev->dev, "pipe = 0x%x.\n", pipe);
173 dev_dbg(dev->dev, "No FB bound\n");
182 DRM_ERROR("Illegal Pipe Number.\n");
186 if (!gma_power_begin(dev, true))
189 start = to_gtt_range(fb->obj[0])->offset;
190 offset = y * fb->pitches[0] + x * fb->format->cpp[0];
192 REG_WRITE(map->stride, fb->pitches[0]);
193 dspcntr = REG_READ(map->cntr);
194 dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
196 switch (fb->format->cpp[0] * 8) {
198 dspcntr |= DISPPLANE_8BPP;
201 if (fb->format->depth == 15)
202 dspcntr |= DISPPLANE_15_16BPP;
204 dspcntr |= DISPPLANE_16BPP;
208 dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
211 REG_WRITE(map->cntr, dspcntr);
213 dev_dbg(dev->dev, "Writing base %08lX %08lX %d %d\n",
214 start, offset, x, y);
215 REG_WRITE(map->linoff, offset);
216 REG_READ(map->linoff);
217 REG_WRITE(map->surf, start);
226 * Disable the pipe, plane and pll.
229 void mdfld_disable_crtc(struct drm_device *dev, int pipe)
231 struct drm_psb_private *dev_priv = dev->dev_private;
232 const struct psb_offset *map = &dev_priv->regmap[pipe];
235 dev_dbg(dev->dev, "pipe = %d\n", pipe);
239 mdfld_dsi_gen_fifo_ready(dev, MIPI_GEN_FIFO_STAT_REG(pipe),
240 HS_CTRL_FIFO_EMPTY | HS_DATA_FIFO_EMPTY);
242 /* Disable display plane */
243 temp = REG_READ(map->cntr);
244 if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
246 temp & ~DISPLAY_PLANE_ENABLE);
247 /* Flush the plane changes */
248 REG_WRITE(map->base, REG_READ(map->base));
252 /* FIXME_JLIU7 MDFLD_PO revisit */
254 /* Next, disable display pipes */
255 temp = REG_READ(map->conf);
256 if ((temp & PIPEACONF_ENABLE) != 0) {
257 temp &= ~PIPEACONF_ENABLE;
258 temp |= PIPECONF_PLANE_OFF | PIPECONF_CURSOR_OFF;
259 REG_WRITE(map->conf, temp);
262 /* Wait for for the pipe disable to take effect. */
263 mdfldWaitForPipeDisable(dev, pipe);
266 temp = REG_READ(map->dpll);
267 if (temp & DPLL_VCO_ENABLE) {
269 !((REG_READ(PIPEACONF) | REG_READ(PIPECCONF))
270 & PIPEACONF_ENABLE)) || pipe == 1) {
271 temp &= ~(DPLL_VCO_ENABLE);
272 REG_WRITE(map->dpll, temp);
274 /* Wait for the clocks to turn off. */
275 /* FIXME_MDFLD PO may need more delay */
278 if (!(temp & MDFLD_PWR_GATE_EN)) {
279 /* gating power of DPLL */
280 REG_WRITE(map->dpll, temp | MDFLD_PWR_GATE_EN);
281 /* FIXME_MDFLD PO - change 500 to 1 after PO */
290 * Sets the power management mode of the pipe and plane.
292 * This code should probably grow support for turning the cursor off and back
293 * on appropriately at the same time as we're turning the pipe off/on.
295 static void mdfld_crtc_dpms(struct drm_crtc *crtc, int mode)
297 struct drm_device *dev = crtc->dev;
298 struct drm_psb_private *dev_priv = dev->dev_private;
299 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
300 int pipe = gma_crtc->pipe;
301 const struct psb_offset *map = &dev_priv->regmap[pipe];
302 u32 pipeconf = dev_priv->pipeconf[pipe];
306 dev_dbg(dev->dev, "mode = %d, pipe = %d\n", mode, pipe);
308 /* Note: Old code uses pipe a stat for pipe b but that appears
311 if (!gma_power_begin(dev, true))
314 /* XXX: When our outputs are all unaware of DPMS modes other than off
315 * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
318 case DRM_MODE_DPMS_ON:
319 case DRM_MODE_DPMS_STANDBY:
320 case DRM_MODE_DPMS_SUSPEND:
321 /* Enable the DPLL */
322 temp = REG_READ(map->dpll);
324 if ((temp & DPLL_VCO_ENABLE) == 0) {
325 /* When ungating power of DPLL, needs to wait 0.5us
326 before enable the VCO */
327 if (temp & MDFLD_PWR_GATE_EN) {
328 temp &= ~MDFLD_PWR_GATE_EN;
329 REG_WRITE(map->dpll, temp);
330 /* FIXME_MDFLD PO - change 500 to 1 after PO */
334 REG_WRITE(map->dpll, temp);
336 /* FIXME_MDFLD PO - change 500 to 1 after PO */
339 REG_WRITE(map->dpll, temp | DPLL_VCO_ENABLE);
343 * wait for DSI PLL to lock
344 * NOTE: only need to poll status of pipe 0 and pipe 1,
345 * since both MIPI pipes share the same PLL.
347 while ((pipe != 2) && (timeout < 20000) &&
348 !(REG_READ(map->conf) & PIPECONF_DSIPLL_LOCK)) {
354 /* Enable the plane */
355 temp = REG_READ(map->cntr);
356 if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
358 temp | DISPLAY_PLANE_ENABLE);
359 /* Flush the plane changes */
360 REG_WRITE(map->base, REG_READ(map->base));
363 /* Enable the pipe */
364 temp = REG_READ(map->conf);
365 if ((temp & PIPEACONF_ENABLE) == 0) {
366 REG_WRITE(map->conf, pipeconf);
368 /* Wait for for the pipe enable to take effect. */
369 mdfldWaitForPipeEnable(dev, pipe);
372 /*workaround for sighting 3741701 Random X blank display*/
373 /*perform w/a in video mode only on pipe A or C*/
374 if (pipe == 0 || pipe == 2) {
375 REG_WRITE(map->status, REG_READ(map->status));
377 if (PIPE_VBLANK_STATUS & REG_READ(map->status))
378 dev_dbg(dev->dev, "OK");
380 dev_dbg(dev->dev, "STUCK!!!!");
381 /*shutdown controller*/
382 temp = REG_READ(map->cntr);
384 temp & ~DISPLAY_PLANE_ENABLE);
385 REG_WRITE(map->base, REG_READ(map->base));
386 /*mdfld_dsi_dpi_shut_down(dev, pipe);*/
387 REG_WRITE(0xb048, 1);
389 temp = REG_READ(map->conf);
390 temp &= ~PIPEACONF_ENABLE;
391 REG_WRITE(map->conf, temp);
392 msleep(100); /*wait for pipe disable*/
393 REG_WRITE(MIPI_DEVICE_READY_REG(pipe), 0);
395 REG_WRITE(0xb004, REG_READ(0xb004));
396 /* try to bring the controller back up again*/
397 REG_WRITE(MIPI_DEVICE_READY_REG(pipe), 1);
398 temp = REG_READ(map->cntr);
400 temp | DISPLAY_PLANE_ENABLE);
401 REG_WRITE(map->base, REG_READ(map->base));
402 /*mdfld_dsi_dpi_turn_on(dev, pipe);*/
403 REG_WRITE(0xb048, 2);
405 temp = REG_READ(map->conf);
406 temp |= PIPEACONF_ENABLE;
407 REG_WRITE(map->conf, temp);
411 gma_crtc_load_lut(crtc);
413 /* Give the overlay scaler a chance to enable
414 if it's on this pipe */
415 /* psb_intel_crtc_dpms_video(crtc, true); TODO */
418 case DRM_MODE_DPMS_OFF:
419 /* Give the overlay scaler a chance to disable
420 * if it's on this pipe */
421 /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */
423 mdfld_dsi_gen_fifo_ready(dev,
424 MIPI_GEN_FIFO_STAT_REG(pipe),
425 HS_CTRL_FIFO_EMPTY | HS_DATA_FIFO_EMPTY);
427 /* Disable the VGA plane that we never use */
428 REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
430 /* Disable display plane */
431 temp = REG_READ(map->cntr);
432 if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
434 temp & ~DISPLAY_PLANE_ENABLE);
435 /* Flush the plane changes */
436 REG_WRITE(map->base, REG_READ(map->base));
440 /* Next, disable display pipes */
441 temp = REG_READ(map->conf);
442 if ((temp & PIPEACONF_ENABLE) != 0) {
443 temp &= ~PIPEACONF_ENABLE;
444 temp |= PIPECONF_PLANE_OFF | PIPECONF_CURSOR_OFF;
445 REG_WRITE(map->conf, temp);
448 /* Wait for for the pipe disable to take effect. */
449 mdfldWaitForPipeDisable(dev, pipe);
452 temp = REG_READ(map->dpll);
453 if (temp & DPLL_VCO_ENABLE) {
454 if ((pipe != 1 && !((REG_READ(PIPEACONF)
455 | REG_READ(PIPECCONF)) & PIPEACONF_ENABLE))
457 temp &= ~(DPLL_VCO_ENABLE);
458 REG_WRITE(map->dpll, temp);
460 /* Wait for the clocks to turn off. */
461 /* FIXME_MDFLD PO may need more delay */
471 #define MDFLD_LIMT_DPLL_19 0
472 #define MDFLD_LIMT_DPLL_25 1
473 #define MDFLD_LIMT_DPLL_83 2
474 #define MDFLD_LIMT_DPLL_100 3
475 #define MDFLD_LIMT_DSIPLL_19 4
476 #define MDFLD_LIMT_DSIPLL_25 5
477 #define MDFLD_LIMT_DSIPLL_83 6
478 #define MDFLD_LIMT_DSIPLL_100 7
480 #define MDFLD_DOT_MIN 19750
481 #define MDFLD_DOT_MAX 120000
482 #define MDFLD_DPLL_M_MIN_19 113
483 #define MDFLD_DPLL_M_MAX_19 155
484 #define MDFLD_DPLL_P1_MIN_19 2
485 #define MDFLD_DPLL_P1_MAX_19 10
486 #define MDFLD_DPLL_M_MIN_25 101
487 #define MDFLD_DPLL_M_MAX_25 130
488 #define MDFLD_DPLL_P1_MIN_25 2
489 #define MDFLD_DPLL_P1_MAX_25 10
490 #define MDFLD_DPLL_M_MIN_83 64
491 #define MDFLD_DPLL_M_MAX_83 64
492 #define MDFLD_DPLL_P1_MIN_83 2
493 #define MDFLD_DPLL_P1_MAX_83 2
494 #define MDFLD_DPLL_M_MIN_100 64
495 #define MDFLD_DPLL_M_MAX_100 64
496 #define MDFLD_DPLL_P1_MIN_100 2
497 #define MDFLD_DPLL_P1_MAX_100 2
498 #define MDFLD_DSIPLL_M_MIN_19 131
499 #define MDFLD_DSIPLL_M_MAX_19 175
500 #define MDFLD_DSIPLL_P1_MIN_19 3
501 #define MDFLD_DSIPLL_P1_MAX_19 8
502 #define MDFLD_DSIPLL_M_MIN_25 97
503 #define MDFLD_DSIPLL_M_MAX_25 140
504 #define MDFLD_DSIPLL_P1_MIN_25 3
505 #define MDFLD_DSIPLL_P1_MAX_25 9
506 #define MDFLD_DSIPLL_M_MIN_83 33
507 #define MDFLD_DSIPLL_M_MAX_83 92
508 #define MDFLD_DSIPLL_P1_MIN_83 2
509 #define MDFLD_DSIPLL_P1_MAX_83 3
510 #define MDFLD_DSIPLL_M_MIN_100 97
511 #define MDFLD_DSIPLL_M_MAX_100 140
512 #define MDFLD_DSIPLL_P1_MIN_100 3
513 #define MDFLD_DSIPLL_P1_MAX_100 9
515 static const struct mrst_limit_t mdfld_limits[] = {
516 { /* MDFLD_LIMT_DPLL_19 */
517 .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
518 .m = {.min = MDFLD_DPLL_M_MIN_19, .max = MDFLD_DPLL_M_MAX_19},
519 .p1 = {.min = MDFLD_DPLL_P1_MIN_19, .max = MDFLD_DPLL_P1_MAX_19},
521 { /* MDFLD_LIMT_DPLL_25 */
522 .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
523 .m = {.min = MDFLD_DPLL_M_MIN_25, .max = MDFLD_DPLL_M_MAX_25},
524 .p1 = {.min = MDFLD_DPLL_P1_MIN_25, .max = MDFLD_DPLL_P1_MAX_25},
526 { /* MDFLD_LIMT_DPLL_83 */
527 .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
528 .m = {.min = MDFLD_DPLL_M_MIN_83, .max = MDFLD_DPLL_M_MAX_83},
529 .p1 = {.min = MDFLD_DPLL_P1_MIN_83, .max = MDFLD_DPLL_P1_MAX_83},
531 { /* MDFLD_LIMT_DPLL_100 */
532 .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
533 .m = {.min = MDFLD_DPLL_M_MIN_100, .max = MDFLD_DPLL_M_MAX_100},
534 .p1 = {.min = MDFLD_DPLL_P1_MIN_100, .max = MDFLD_DPLL_P1_MAX_100},
536 { /* MDFLD_LIMT_DSIPLL_19 */
537 .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
538 .m = {.min = MDFLD_DSIPLL_M_MIN_19, .max = MDFLD_DSIPLL_M_MAX_19},
539 .p1 = {.min = MDFLD_DSIPLL_P1_MIN_19, .max = MDFLD_DSIPLL_P1_MAX_19},
541 { /* MDFLD_LIMT_DSIPLL_25 */
542 .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
543 .m = {.min = MDFLD_DSIPLL_M_MIN_25, .max = MDFLD_DSIPLL_M_MAX_25},
544 .p1 = {.min = MDFLD_DSIPLL_P1_MIN_25, .max = MDFLD_DSIPLL_P1_MAX_25},
546 { /* MDFLD_LIMT_DSIPLL_83 */
547 .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
548 .m = {.min = MDFLD_DSIPLL_M_MIN_83, .max = MDFLD_DSIPLL_M_MAX_83},
549 .p1 = {.min = MDFLD_DSIPLL_P1_MIN_83, .max = MDFLD_DSIPLL_P1_MAX_83},
551 { /* MDFLD_LIMT_DSIPLL_100 */
552 .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX},
553 .m = {.min = MDFLD_DSIPLL_M_MIN_100, .max = MDFLD_DSIPLL_M_MAX_100},
554 .p1 = {.min = MDFLD_DSIPLL_P1_MIN_100, .max = MDFLD_DSIPLL_P1_MAX_100},
558 #define MDFLD_M_MIN 21
559 #define MDFLD_M_MAX 180
560 static const u32 mdfld_m_converts[] = {
561 /* M configuration table from 9-bit LFSR table */
562 224, 368, 440, 220, 366, 439, 219, 365, 182, 347, /* 21 - 30 */
563 173, 342, 171, 85, 298, 149, 74, 37, 18, 265, /* 31 - 40 */
564 388, 194, 353, 432, 216, 108, 310, 155, 333, 166, /* 41 - 50 */
565 83, 41, 276, 138, 325, 162, 337, 168, 340, 170, /* 51 - 60 */
566 341, 426, 469, 234, 373, 442, 221, 110, 311, 411, /* 61 - 70 */
567 461, 486, 243, 377, 188, 350, 175, 343, 427, 213, /* 71 - 80 */
568 106, 53, 282, 397, 354, 227, 113, 56, 284, 142, /* 81 - 90 */
569 71, 35, 273, 136, 324, 418, 465, 488, 500, 506, /* 91 - 100 */
570 253, 126, 63, 287, 399, 455, 483, 241, 376, 444, /* 101 - 110 */
571 478, 495, 503, 251, 381, 446, 479, 239, 375, 443, /* 111 - 120 */
572 477, 238, 119, 315, 157, 78, 295, 147, 329, 420, /* 121 - 130 */
573 210, 105, 308, 154, 77, 38, 275, 137, 68, 290, /* 131 - 140 */
574 145, 328, 164, 82, 297, 404, 458, 485, 498, 249, /* 141 - 150 */
575 380, 190, 351, 431, 471, 235, 117, 314, 413, 206, /* 151 - 160 */
576 103, 51, 25, 12, 262, 387, 193, 96, 48, 280, /* 161 - 170 */
577 396, 198, 99, 305, 152, 76, 294, 403, 457, 228, /* 171 - 180 */
580 static const struct mrst_limit_t *mdfld_limit(struct drm_crtc *crtc)
582 const struct mrst_limit_t *limit = NULL;
583 struct drm_device *dev = crtc->dev;
584 struct drm_psb_private *dev_priv = dev->dev_private;
586 if (gma_pipe_has_type(crtc, INTEL_OUTPUT_MIPI)
587 || gma_pipe_has_type(crtc, INTEL_OUTPUT_MIPI2)) {
588 if ((ksel == KSEL_CRYSTAL_19) || (ksel == KSEL_BYPASS_19))
589 limit = &mdfld_limits[MDFLD_LIMT_DSIPLL_19];
590 else if (ksel == KSEL_BYPASS_25)
591 limit = &mdfld_limits[MDFLD_LIMT_DSIPLL_25];
592 else if ((ksel == KSEL_BYPASS_83_100) &&
593 (dev_priv->core_freq == 166))
594 limit = &mdfld_limits[MDFLD_LIMT_DSIPLL_83];
595 else if ((ksel == KSEL_BYPASS_83_100) &&
596 (dev_priv->core_freq == 100 ||
597 dev_priv->core_freq == 200))
598 limit = &mdfld_limits[MDFLD_LIMT_DSIPLL_100];
599 } else if (gma_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) {
600 if ((ksel == KSEL_CRYSTAL_19) || (ksel == KSEL_BYPASS_19))
601 limit = &mdfld_limits[MDFLD_LIMT_DPLL_19];
602 else if (ksel == KSEL_BYPASS_25)
603 limit = &mdfld_limits[MDFLD_LIMT_DPLL_25];
604 else if ((ksel == KSEL_BYPASS_83_100) &&
605 (dev_priv->core_freq == 166))
606 limit = &mdfld_limits[MDFLD_LIMT_DPLL_83];
607 else if ((ksel == KSEL_BYPASS_83_100) &&
608 (dev_priv->core_freq == 100 ||
609 dev_priv->core_freq == 200))
610 limit = &mdfld_limits[MDFLD_LIMT_DPLL_100];
613 dev_dbg(dev->dev, "mdfld_limit Wrong display type.\n");
619 /** Derive the pixel clock for the given refclk and divisors for 8xx chips. */
620 static void mdfld_clock(int refclk, struct mrst_clock_t *clock)
622 clock->dot = (refclk * clock->m) / clock->p1;
626 * Returns a set of divisors for the desired target clock with the given refclk,
627 * or FALSE. Divisor values are the actual divisors for
630 mdfldFindBestPLL(struct drm_crtc *crtc, int target, int refclk,
631 struct mrst_clock_t *best_clock)
633 struct mrst_clock_t clock;
634 const struct mrst_limit_t *limit = mdfld_limit(crtc);
637 memset(best_clock, 0, sizeof(*best_clock));
639 for (clock.m = limit->m.min; clock.m <= limit->m.max; clock.m++) {
640 for (clock.p1 = limit->p1.min; clock.p1 <= limit->p1.max;
644 mdfld_clock(refclk, &clock);
646 this_err = abs(clock.dot - target);
647 if (this_err < err) {
653 return err != target;
656 static int mdfld_crtc_mode_set(struct drm_crtc *crtc,
657 struct drm_display_mode *mode,
658 struct drm_display_mode *adjusted_mode,
660 struct drm_framebuffer *old_fb)
662 struct drm_device *dev = crtc->dev;
663 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
664 struct drm_psb_private *dev_priv = dev->dev_private;
665 int pipe = gma_crtc->pipe;
666 const struct psb_offset *map = &dev_priv->regmap[pipe];
668 int clk_n = 0, clk_p2 = 0, clk_byte = 1, clk = 0, m_conv = 0,
670 struct mrst_clock_t clock;
672 u32 dpll = 0, fp = 0;
673 bool is_mipi = false, is_mipi2 = false, is_hdmi = false;
674 struct drm_mode_config *mode_config = &dev->mode_config;
675 struct gma_encoder *gma_encoder = NULL;
676 uint64_t scalingType = DRM_MODE_SCALE_FULLSCREEN;
677 struct drm_encoder *encoder;
678 struct drm_connector *connector;
682 dev_dbg(dev->dev, "pipe = 0x%x\n", pipe);
686 if (!gma_power_begin(dev, true))
688 android_hdmi_crtc_mode_set(crtc, mode, adjusted_mode,
690 goto mrst_crtc_mode_set_exit;
694 ret = check_fb(crtc->primary->fb);
698 dev_dbg(dev->dev, "adjusted_hdisplay = %d\n",
699 adjusted_mode->hdisplay);
700 dev_dbg(dev->dev, "adjusted_vdisplay = %d\n",
701 adjusted_mode->vdisplay);
702 dev_dbg(dev->dev, "adjusted_hsync_start = %d\n",
703 adjusted_mode->hsync_start);
704 dev_dbg(dev->dev, "adjusted_hsync_end = %d\n",
705 adjusted_mode->hsync_end);
706 dev_dbg(dev->dev, "adjusted_htotal = %d\n",
707 adjusted_mode->htotal);
708 dev_dbg(dev->dev, "adjusted_vsync_start = %d\n",
709 adjusted_mode->vsync_start);
710 dev_dbg(dev->dev, "adjusted_vsync_end = %d\n",
711 adjusted_mode->vsync_end);
712 dev_dbg(dev->dev, "adjusted_vtotal = %d\n",
713 adjusted_mode->vtotal);
714 dev_dbg(dev->dev, "adjusted_clock = %d\n",
715 adjusted_mode->clock);
716 dev_dbg(dev->dev, "hdisplay = %d\n",
718 dev_dbg(dev->dev, "vdisplay = %d\n",
721 if (!gma_power_begin(dev, true))
724 memcpy(&gma_crtc->saved_mode, mode,
725 sizeof(struct drm_display_mode));
726 memcpy(&gma_crtc->saved_adjusted_mode, adjusted_mode,
727 sizeof(struct drm_display_mode));
729 list_for_each_entry(connector, &mode_config->connector_list, head) {
730 encoder = connector->encoder;
734 if (encoder->crtc != crtc)
737 gma_encoder = gma_attached_encoder(connector);
739 switch (gma_encoder->type) {
740 case INTEL_OUTPUT_MIPI:
743 case INTEL_OUTPUT_MIPI2:
746 case INTEL_OUTPUT_HDMI:
752 /* Disable the VGA plane that we never use */
753 REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
755 /* Disable the panel fitter if it was on our pipe */
756 if (psb_intel_panel_fitter_pipe(dev) == pipe)
757 REG_WRITE(PFIT_CONTROL, 0);
759 /* pipesrc and dspsize control the size that is scaled from,
760 * which should always be the user's requested size.
763 /* FIXME: To make HDMI display with 864x480 (TPO), 480x864
764 * (PYR) or 480x854 (TMD), set the sprite width/height and
765 * souce image size registers with the adjusted mode for
770 * The defined sprite rectangle must always be completely
771 * contained within the displayable area of the screen image
774 REG_WRITE(map->size, ((min(mode->crtc_vdisplay, adjusted_mode->crtc_vdisplay) - 1) << 16)
775 | (min(mode->crtc_hdisplay, adjusted_mode->crtc_hdisplay) - 1));
776 /* Set the CRTC with encoder mode. */
777 REG_WRITE(map->src, ((mode->crtc_hdisplay - 1) << 16)
778 | (mode->crtc_vdisplay - 1));
781 ((mode->crtc_vdisplay - 1) << 16) |
782 (mode->crtc_hdisplay - 1));
784 ((mode->crtc_hdisplay - 1) << 16) |
785 (mode->crtc_vdisplay - 1));
788 REG_WRITE(map->pos, 0);
791 drm_object_property_get_value(&connector->base,
792 dev->mode_config.scaling_mode_property, &scalingType);
794 if (scalingType == DRM_MODE_SCALE_NO_SCALE) {
795 /* Medfield doesn't have register support for centering so we
796 * need to mess with the h/vblank and h/vsync start and ends
799 int offsetX = 0, offsetY = 0;
801 offsetX = (adjusted_mode->crtc_hdisplay -
802 mode->crtc_hdisplay) / 2;
803 offsetY = (adjusted_mode->crtc_vdisplay -
804 mode->crtc_vdisplay) / 2;
806 REG_WRITE(map->htotal, (mode->crtc_hdisplay - 1) |
807 ((adjusted_mode->crtc_htotal - 1) << 16));
808 REG_WRITE(map->vtotal, (mode->crtc_vdisplay - 1) |
809 ((adjusted_mode->crtc_vtotal - 1) << 16));
810 REG_WRITE(map->hblank, (adjusted_mode->crtc_hblank_start -
812 ((adjusted_mode->crtc_hblank_end - offsetX - 1) << 16));
813 REG_WRITE(map->hsync, (adjusted_mode->crtc_hsync_start -
815 ((adjusted_mode->crtc_hsync_end - offsetX - 1) << 16));
816 REG_WRITE(map->vblank, (adjusted_mode->crtc_vblank_start -
818 ((adjusted_mode->crtc_vblank_end - offsetY - 1) << 16));
819 REG_WRITE(map->vsync, (adjusted_mode->crtc_vsync_start -
821 ((adjusted_mode->crtc_vsync_end - offsetY - 1) << 16));
823 REG_WRITE(map->htotal, (adjusted_mode->crtc_hdisplay - 1) |
824 ((adjusted_mode->crtc_htotal - 1) << 16));
825 REG_WRITE(map->vtotal, (adjusted_mode->crtc_vdisplay - 1) |
826 ((adjusted_mode->crtc_vtotal - 1) << 16));
827 REG_WRITE(map->hblank, (adjusted_mode->crtc_hblank_start - 1) |
828 ((adjusted_mode->crtc_hblank_end - 1) << 16));
829 REG_WRITE(map->hsync, (adjusted_mode->crtc_hsync_start - 1) |
830 ((adjusted_mode->crtc_hsync_end - 1) << 16));
831 REG_WRITE(map->vblank, (adjusted_mode->crtc_vblank_start - 1) |
832 ((adjusted_mode->crtc_vblank_end - 1) << 16));
833 REG_WRITE(map->vsync, (adjusted_mode->crtc_vsync_start - 1) |
834 ((adjusted_mode->crtc_vsync_end - 1) << 16));
837 /* Flush the plane changes */
839 const struct drm_crtc_helper_funcs *crtc_funcs =
840 crtc->helper_private;
841 crtc_funcs->mode_set_base(crtc, x, y, old_fb);
845 dev_priv->pipeconf[pipe] = PIPEACONF_ENABLE; /* FIXME_JLIU7 REG_READ(pipeconf_reg); */
847 /* Set up the display plane register */
848 dev_priv->dspcntr[pipe] = REG_READ(map->cntr);
849 dev_priv->dspcntr[pipe] |= pipe << DISPPLANE_SEL_PIPE_POS;
850 dev_priv->dspcntr[pipe] |= DISPLAY_PLANE_ENABLE;
853 goto mrst_crtc_mode_set_exit;
854 clk = adjusted_mode->clock;
857 if ((ksel == KSEL_CRYSTAL_19) || (ksel == KSEL_BYPASS_19)) {
860 if (is_mipi || is_mipi2)
861 clk_n = 1, clk_p2 = 8;
863 clk_n = 1, clk_p2 = 10;
864 } else if (ksel == KSEL_BYPASS_25) {
867 if (is_mipi || is_mipi2)
868 clk_n = 1, clk_p2 = 8;
870 clk_n = 1, clk_p2 = 10;
871 } else if ((ksel == KSEL_BYPASS_83_100) &&
872 dev_priv->core_freq == 166) {
875 if (is_mipi || is_mipi2)
876 clk_n = 4, clk_p2 = 8;
878 clk_n = 4, clk_p2 = 10;
879 } else if ((ksel == KSEL_BYPASS_83_100) &&
880 (dev_priv->core_freq == 100 ||
881 dev_priv->core_freq == 200)) {
883 if (is_mipi || is_mipi2)
884 clk_n = 4, clk_p2 = 8;
886 clk_n = 4, clk_p2 = 10;
890 clk_byte = dev_priv->bpp / 8;
892 clk_byte = dev_priv->bpp2 / 8;
894 clk_tmp = clk * clk_n * clk_p2 * clk_byte;
896 dev_dbg(dev->dev, "clk = %d, clk_n = %d, clk_p2 = %d.\n",
898 dev_dbg(dev->dev, "adjusted_mode->clock = %d, clk_tmp = %d.\n",
899 adjusted_mode->clock, clk_tmp);
901 ok = mdfldFindBestPLL(crtc, clk_tmp, refclk, &clock);
905 ("mdfldFindBestPLL fail in mdfld_crtc_mode_set.\n");
907 m_conv = mdfld_m_converts[(clock.m - MDFLD_M_MIN)];
909 dev_dbg(dev->dev, "dot clock = %d,"
910 "m = %d, p1 = %d, m_conv = %d.\n",
915 dpll = REG_READ(map->dpll);
917 if (dpll & DPLL_VCO_ENABLE) {
918 dpll &= ~DPLL_VCO_ENABLE;
919 REG_WRITE(map->dpll, dpll);
922 /* FIXME jliu7 check the DPLL lock bit PIPEACONF[29] */
923 /* FIXME_MDFLD PO - change 500 to 1 after PO */
926 /* reset M1, N1 & P1 */
927 REG_WRITE(map->fp0, 0);
928 dpll &= ~MDFLD_P1_MASK;
929 REG_WRITE(map->dpll, dpll);
930 /* FIXME_MDFLD PO - change 500 to 1 after PO */
934 /* When ungating power of DPLL, needs to wait 0.5us before
936 if (dpll & MDFLD_PWR_GATE_EN) {
937 dpll &= ~MDFLD_PWR_GATE_EN;
938 REG_WRITE(map->dpll, dpll);
939 /* FIXME_MDFLD PO - change 500 to 1 after PO */
944 #if 0 /* FIXME revisit later */
945 if (ksel == KSEL_CRYSTAL_19 || ksel == KSEL_BYPASS_19 ||
946 ksel == KSEL_BYPASS_25)
947 dpll &= ~MDFLD_INPUT_REF_SEL;
948 else if (ksel == KSEL_BYPASS_83_100)
949 dpll |= MDFLD_INPUT_REF_SEL;
950 #endif /* FIXME revisit later */
953 dpll |= MDFLD_VCO_SEL;
955 fp = (clk_n / 2) << 16;
958 /* compute bitmask from p1 value */
959 dpll |= (1 << (clock.p1 - 2)) << 17;
961 #if 0 /* 1080p30 & 720p */
970 #if 0 /*DBI_TPO_480x864*/
973 #endif /* DBI_TPO_480x864 */ /* get from spec. */
979 REG_WRITE(map->fp0, fp);
980 REG_WRITE(map->dpll, dpll);
981 /* FIXME_MDFLD PO - change 500 to 1 after PO */
984 dpll |= DPLL_VCO_ENABLE;
985 REG_WRITE(map->dpll, dpll);
988 /* wait for DSI PLL to lock */
989 while (timeout < 20000 &&
990 !(REG_READ(map->conf) & PIPECONF_DSIPLL_LOCK)) {
996 goto mrst_crtc_mode_set_exit;
998 dev_dbg(dev->dev, "is_mipi = 0x%x\n", is_mipi);
1000 REG_WRITE(map->conf, dev_priv->pipeconf[pipe]);
1001 REG_READ(map->conf);
1003 /* Wait for for the pipe enable to take effect. */
1004 REG_WRITE(map->cntr, dev_priv->dspcntr[pipe]);
1005 gma_wait_for_vblank(dev);
1007 mrst_crtc_mode_set_exit:
1014 const struct drm_crtc_helper_funcs mdfld_helper_funcs = {
1015 .dpms = mdfld_crtc_dpms,
1016 .mode_set = mdfld_crtc_mode_set,
1017 .mode_set_base = mdfld__intel_pipe_set_base,
1018 .prepare = gma_crtc_prepare,
1019 .commit = gma_crtc_commit,