2 * Copyright © 2006-2007 Intel Corporation
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 * Eric Anholt <eric@anholt.net>
21 #include <linux/i2c.h>
22 #include <linux/pm_runtime.h>
25 #include "psb_intel_reg.h"
26 #include "gma_display.h"
27 #include "framebuffer.h"
28 #include "mdfld_output.h"
29 #include "mdfld_dsi_output.h"
31 /* Hardcoded currently */
32 static int ksel
= KSEL_CRYSTAL_19
;
34 struct psb_intel_range_t
{
39 struct psb_intel_range_t dot
, m
, p1
;
49 #define COUNT_MAX 0x10000000
51 void mdfldWaitForPipeDisable(struct drm_device
*dev
, int pipe
)
53 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
54 const struct psb_offset
*map
= &dev_priv
->regmap
[pipe
];
63 DRM_ERROR("Illegal Pipe Number.\n");
68 gma_wait_for_vblank(dev
);
71 /* Wait for for the pipe disable to take effect. */
72 for (count
= 0; count
< COUNT_MAX
; count
++) {
73 temp
= REG_READ(map
->conf
);
74 if ((temp
& PIPEACONF_PIPE_STATE
) == 0)
79 void mdfldWaitForPipeEnable(struct drm_device
*dev
, int pipe
)
81 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
82 const struct psb_offset
*map
= &dev_priv
->regmap
[pipe
];
91 DRM_ERROR("Illegal Pipe Number.\n");
96 gma_wait_for_vblank(dev
);
99 /* Wait for for the pipe enable to take effect. */
100 for (count
= 0; count
< COUNT_MAX
; count
++) {
101 temp
= REG_READ(map
->conf
);
102 if ((temp
& PIPEACONF_PIPE_STATE
) == 1)
108 * Return the pipe currently connected to the panel fitter,
109 * or -1 if the panel fitter is not present or not in use
111 static int psb_intel_panel_fitter_pipe(struct drm_device
*dev
)
115 pfit_control
= REG_READ(PFIT_CONTROL
);
117 /* See if the panel fitter is in use */
118 if ((pfit_control
& PFIT_ENABLE
) == 0)
121 /* 965 can place panel fitter on either pipe */
122 return (pfit_control
>> 29) & 0x3;
125 static struct drm_device globle_dev
;
127 void mdfld__intel_plane_set_alpha(int enable
)
129 struct drm_device
*dev
= &globle_dev
;
130 int dspcntr_reg
= DSPACNTR
;
133 dspcntr
= REG_READ(dspcntr_reg
);
136 dspcntr
&= ~DISPPLANE_32BPP_NO_ALPHA
;
137 dspcntr
|= DISPPLANE_32BPP
;
139 dspcntr
&= ~DISPPLANE_32BPP
;
140 dspcntr
|= DISPPLANE_32BPP_NO_ALPHA
;
143 REG_WRITE(dspcntr_reg
, dspcntr
);
146 static int check_fb(struct drm_framebuffer
*fb
)
151 switch (fb
->bits_per_pixel
) {
158 DRM_ERROR("Unknown color depth\n");
163 static int mdfld__intel_pipe_set_base(struct drm_crtc
*crtc
, int x
, int y
,
164 struct drm_framebuffer
*old_fb
)
166 struct drm_device
*dev
= crtc
->dev
;
167 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
168 struct gma_crtc
*gma_crtc
= to_gma_crtc(crtc
);
169 struct psb_framebuffer
*psbfb
= to_psb_fb(crtc
->primary
->fb
);
170 int pipe
= gma_crtc
->pipe
;
171 const struct psb_offset
*map
= &dev_priv
->regmap
[pipe
];
172 unsigned long start
, offset
;
176 memcpy(&globle_dev
, dev
, sizeof(struct drm_device
));
178 dev_dbg(dev
->dev
, "pipe = 0x%x.\n", pipe
);
181 if (!crtc
->primary
->fb
) {
182 dev_dbg(dev
->dev
, "No FB bound\n");
186 ret
= check_fb(crtc
->primary
->fb
);
191 DRM_ERROR("Illegal Pipe Number.\n");
195 if (!gma_power_begin(dev
, true))
198 start
= psbfb
->gtt
->offset
;
199 offset
= y
* crtc
->primary
->fb
->pitches
[0] + x
* (crtc
->primary
->fb
->bits_per_pixel
/ 8);
201 REG_WRITE(map
->stride
, crtc
->primary
->fb
->pitches
[0]);
202 dspcntr
= REG_READ(map
->cntr
);
203 dspcntr
&= ~DISPPLANE_PIXFORMAT_MASK
;
205 switch (crtc
->primary
->fb
->bits_per_pixel
) {
207 dspcntr
|= DISPPLANE_8BPP
;
210 if (crtc
->primary
->fb
->depth
== 15)
211 dspcntr
|= DISPPLANE_15_16BPP
;
213 dspcntr
|= DISPPLANE_16BPP
;
217 dspcntr
|= DISPPLANE_32BPP_NO_ALPHA
;
220 REG_WRITE(map
->cntr
, dspcntr
);
222 dev_dbg(dev
->dev
, "Writing base %08lX %08lX %d %d\n",
223 start
, offset
, x
, y
);
224 REG_WRITE(map
->linoff
, offset
);
225 REG_READ(map
->linoff
);
226 REG_WRITE(map
->surf
, start
);
235 * Disable the pipe, plane and pll.
238 void mdfld_disable_crtc(struct drm_device
*dev
, int pipe
)
240 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
241 const struct psb_offset
*map
= &dev_priv
->regmap
[pipe
];
244 dev_dbg(dev
->dev
, "pipe = %d\n", pipe
);
248 mdfld_dsi_gen_fifo_ready(dev
, MIPI_GEN_FIFO_STAT_REG(pipe
),
249 HS_CTRL_FIFO_EMPTY
| HS_DATA_FIFO_EMPTY
);
251 /* Disable display plane */
252 temp
= REG_READ(map
->cntr
);
253 if ((temp
& DISPLAY_PLANE_ENABLE
) != 0) {
255 temp
& ~DISPLAY_PLANE_ENABLE
);
256 /* Flush the plane changes */
257 REG_WRITE(map
->base
, REG_READ(map
->base
));
261 /* FIXME_JLIU7 MDFLD_PO revisit */
263 /* Next, disable display pipes */
264 temp
= REG_READ(map
->conf
);
265 if ((temp
& PIPEACONF_ENABLE
) != 0) {
266 temp
&= ~PIPEACONF_ENABLE
;
267 temp
|= PIPECONF_PLANE_OFF
| PIPECONF_CURSOR_OFF
;
268 REG_WRITE(map
->conf
, temp
);
271 /* Wait for for the pipe disable to take effect. */
272 mdfldWaitForPipeDisable(dev
, pipe
);
275 temp
= REG_READ(map
->dpll
);
276 if (temp
& DPLL_VCO_ENABLE
) {
278 !((REG_READ(PIPEACONF
) | REG_READ(PIPECCONF
))
279 & PIPEACONF_ENABLE
)) || pipe
== 1) {
280 temp
&= ~(DPLL_VCO_ENABLE
);
281 REG_WRITE(map
->dpll
, temp
);
283 /* Wait for the clocks to turn off. */
284 /* FIXME_MDFLD PO may need more delay */
287 if (!(temp
& MDFLD_PWR_GATE_EN
)) {
288 /* gating power of DPLL */
289 REG_WRITE(map
->dpll
, temp
| MDFLD_PWR_GATE_EN
);
290 /* FIXME_MDFLD PO - change 500 to 1 after PO */
299 * Sets the power management mode of the pipe and plane.
301 * This code should probably grow support for turning the cursor off and back
302 * on appropriately at the same time as we're turning the pipe off/on.
304 static void mdfld_crtc_dpms(struct drm_crtc
*crtc
, int mode
)
306 struct drm_device
*dev
= crtc
->dev
;
307 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
308 struct gma_crtc
*gma_crtc
= to_gma_crtc(crtc
);
309 int pipe
= gma_crtc
->pipe
;
310 const struct psb_offset
*map
= &dev_priv
->regmap
[pipe
];
311 u32 pipeconf
= dev_priv
->pipeconf
[pipe
];
315 dev_dbg(dev
->dev
, "mode = %d, pipe = %d\n", mode
, pipe
);
317 /* Note: Old code uses pipe a stat for pipe b but that appears
320 if (!gma_power_begin(dev
, true))
323 /* XXX: When our outputs are all unaware of DPMS modes other than off
324 * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
327 case DRM_MODE_DPMS_ON
:
328 case DRM_MODE_DPMS_STANDBY
:
329 case DRM_MODE_DPMS_SUSPEND
:
330 /* Enable the DPLL */
331 temp
= REG_READ(map
->dpll
);
333 if ((temp
& DPLL_VCO_ENABLE
) == 0) {
334 /* When ungating power of DPLL, needs to wait 0.5us
335 before enable the VCO */
336 if (temp
& MDFLD_PWR_GATE_EN
) {
337 temp
&= ~MDFLD_PWR_GATE_EN
;
338 REG_WRITE(map
->dpll
, temp
);
339 /* FIXME_MDFLD PO - change 500 to 1 after PO */
343 REG_WRITE(map
->dpll
, temp
);
345 /* FIXME_MDFLD PO - change 500 to 1 after PO */
348 REG_WRITE(map
->dpll
, temp
| DPLL_VCO_ENABLE
);
352 * wait for DSI PLL to lock
353 * NOTE: only need to poll status of pipe 0 and pipe 1,
354 * since both MIPI pipes share the same PLL.
356 while ((pipe
!= 2) && (timeout
< 20000) &&
357 !(REG_READ(map
->conf
) & PIPECONF_DSIPLL_LOCK
)) {
363 /* Enable the plane */
364 temp
= REG_READ(map
->cntr
);
365 if ((temp
& DISPLAY_PLANE_ENABLE
) == 0) {
367 temp
| DISPLAY_PLANE_ENABLE
);
368 /* Flush the plane changes */
369 REG_WRITE(map
->base
, REG_READ(map
->base
));
372 /* Enable the pipe */
373 temp
= REG_READ(map
->conf
);
374 if ((temp
& PIPEACONF_ENABLE
) == 0) {
375 REG_WRITE(map
->conf
, pipeconf
);
377 /* Wait for for the pipe enable to take effect. */
378 mdfldWaitForPipeEnable(dev
, pipe
);
381 /*workaround for sighting 3741701 Random X blank display*/
382 /*perform w/a in video mode only on pipe A or C*/
383 if (pipe
== 0 || pipe
== 2) {
384 REG_WRITE(map
->status
, REG_READ(map
->status
));
386 if (PIPE_VBLANK_STATUS
& REG_READ(map
->status
))
387 dev_dbg(dev
->dev
, "OK");
389 dev_dbg(dev
->dev
, "STUCK!!!!");
390 /*shutdown controller*/
391 temp
= REG_READ(map
->cntr
);
393 temp
& ~DISPLAY_PLANE_ENABLE
);
394 REG_WRITE(map
->base
, REG_READ(map
->base
));
395 /*mdfld_dsi_dpi_shut_down(dev, pipe);*/
396 REG_WRITE(0xb048, 1);
398 temp
= REG_READ(map
->conf
);
399 temp
&= ~PIPEACONF_ENABLE
;
400 REG_WRITE(map
->conf
, temp
);
401 msleep(100); /*wait for pipe disable*/
402 REG_WRITE(MIPI_DEVICE_READY_REG(pipe
), 0);
404 REG_WRITE(0xb004, REG_READ(0xb004));
405 /* try to bring the controller back up again*/
406 REG_WRITE(MIPI_DEVICE_READY_REG(pipe
), 1);
407 temp
= REG_READ(map
->cntr
);
409 temp
| DISPLAY_PLANE_ENABLE
);
410 REG_WRITE(map
->base
, REG_READ(map
->base
));
411 /*mdfld_dsi_dpi_turn_on(dev, pipe);*/
412 REG_WRITE(0xb048, 2);
414 temp
= REG_READ(map
->conf
);
415 temp
|= PIPEACONF_ENABLE
;
416 REG_WRITE(map
->conf
, temp
);
420 gma_crtc_load_lut(crtc
);
422 /* Give the overlay scaler a chance to enable
423 if it's on this pipe */
424 /* psb_intel_crtc_dpms_video(crtc, true); TODO */
427 case DRM_MODE_DPMS_OFF
:
428 /* Give the overlay scaler a chance to disable
429 * if it's on this pipe */
430 /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */
432 mdfld_dsi_gen_fifo_ready(dev
,
433 MIPI_GEN_FIFO_STAT_REG(pipe
),
434 HS_CTRL_FIFO_EMPTY
| HS_DATA_FIFO_EMPTY
);
436 /* Disable the VGA plane that we never use */
437 REG_WRITE(VGACNTRL
, VGA_DISP_DISABLE
);
439 /* Disable display plane */
440 temp
= REG_READ(map
->cntr
);
441 if ((temp
& DISPLAY_PLANE_ENABLE
) != 0) {
443 temp
& ~DISPLAY_PLANE_ENABLE
);
444 /* Flush the plane changes */
445 REG_WRITE(map
->base
, REG_READ(map
->base
));
449 /* Next, disable display pipes */
450 temp
= REG_READ(map
->conf
);
451 if ((temp
& PIPEACONF_ENABLE
) != 0) {
452 temp
&= ~PIPEACONF_ENABLE
;
453 temp
|= PIPECONF_PLANE_OFF
| PIPECONF_CURSOR_OFF
;
454 REG_WRITE(map
->conf
, temp
);
457 /* Wait for for the pipe disable to take effect. */
458 mdfldWaitForPipeDisable(dev
, pipe
);
461 temp
= REG_READ(map
->dpll
);
462 if (temp
& DPLL_VCO_ENABLE
) {
463 if ((pipe
!= 1 && !((REG_READ(PIPEACONF
)
464 | REG_READ(PIPECCONF
)) & PIPEACONF_ENABLE
))
466 temp
&= ~(DPLL_VCO_ENABLE
);
467 REG_WRITE(map
->dpll
, temp
);
469 /* Wait for the clocks to turn off. */
470 /* FIXME_MDFLD PO may need more delay */
480 #define MDFLD_LIMT_DPLL_19 0
481 #define MDFLD_LIMT_DPLL_25 1
482 #define MDFLD_LIMT_DPLL_83 2
483 #define MDFLD_LIMT_DPLL_100 3
484 #define MDFLD_LIMT_DSIPLL_19 4
485 #define MDFLD_LIMT_DSIPLL_25 5
486 #define MDFLD_LIMT_DSIPLL_83 6
487 #define MDFLD_LIMT_DSIPLL_100 7
489 #define MDFLD_DOT_MIN 19750
490 #define MDFLD_DOT_MAX 120000
491 #define MDFLD_DPLL_M_MIN_19 113
492 #define MDFLD_DPLL_M_MAX_19 155
493 #define MDFLD_DPLL_P1_MIN_19 2
494 #define MDFLD_DPLL_P1_MAX_19 10
495 #define MDFLD_DPLL_M_MIN_25 101
496 #define MDFLD_DPLL_M_MAX_25 130
497 #define MDFLD_DPLL_P1_MIN_25 2
498 #define MDFLD_DPLL_P1_MAX_25 10
499 #define MDFLD_DPLL_M_MIN_83 64
500 #define MDFLD_DPLL_M_MAX_83 64
501 #define MDFLD_DPLL_P1_MIN_83 2
502 #define MDFLD_DPLL_P1_MAX_83 2
503 #define MDFLD_DPLL_M_MIN_100 64
504 #define MDFLD_DPLL_M_MAX_100 64
505 #define MDFLD_DPLL_P1_MIN_100 2
506 #define MDFLD_DPLL_P1_MAX_100 2
507 #define MDFLD_DSIPLL_M_MIN_19 131
508 #define MDFLD_DSIPLL_M_MAX_19 175
509 #define MDFLD_DSIPLL_P1_MIN_19 3
510 #define MDFLD_DSIPLL_P1_MAX_19 8
511 #define MDFLD_DSIPLL_M_MIN_25 97
512 #define MDFLD_DSIPLL_M_MAX_25 140
513 #define MDFLD_DSIPLL_P1_MIN_25 3
514 #define MDFLD_DSIPLL_P1_MAX_25 9
515 #define MDFLD_DSIPLL_M_MIN_83 33
516 #define MDFLD_DSIPLL_M_MAX_83 92
517 #define MDFLD_DSIPLL_P1_MIN_83 2
518 #define MDFLD_DSIPLL_P1_MAX_83 3
519 #define MDFLD_DSIPLL_M_MIN_100 97
520 #define MDFLD_DSIPLL_M_MAX_100 140
521 #define MDFLD_DSIPLL_P1_MIN_100 3
522 #define MDFLD_DSIPLL_P1_MAX_100 9
524 static const struct mrst_limit_t mdfld_limits
[] = {
525 { /* MDFLD_LIMT_DPLL_19 */
526 .dot
= {.min
= MDFLD_DOT_MIN
, .max
= MDFLD_DOT_MAX
},
527 .m
= {.min
= MDFLD_DPLL_M_MIN_19
, .max
= MDFLD_DPLL_M_MAX_19
},
528 .p1
= {.min
= MDFLD_DPLL_P1_MIN_19
, .max
= MDFLD_DPLL_P1_MAX_19
},
530 { /* MDFLD_LIMT_DPLL_25 */
531 .dot
= {.min
= MDFLD_DOT_MIN
, .max
= MDFLD_DOT_MAX
},
532 .m
= {.min
= MDFLD_DPLL_M_MIN_25
, .max
= MDFLD_DPLL_M_MAX_25
},
533 .p1
= {.min
= MDFLD_DPLL_P1_MIN_25
, .max
= MDFLD_DPLL_P1_MAX_25
},
535 { /* MDFLD_LIMT_DPLL_83 */
536 .dot
= {.min
= MDFLD_DOT_MIN
, .max
= MDFLD_DOT_MAX
},
537 .m
= {.min
= MDFLD_DPLL_M_MIN_83
, .max
= MDFLD_DPLL_M_MAX_83
},
538 .p1
= {.min
= MDFLD_DPLL_P1_MIN_83
, .max
= MDFLD_DPLL_P1_MAX_83
},
540 { /* MDFLD_LIMT_DPLL_100 */
541 .dot
= {.min
= MDFLD_DOT_MIN
, .max
= MDFLD_DOT_MAX
},
542 .m
= {.min
= MDFLD_DPLL_M_MIN_100
, .max
= MDFLD_DPLL_M_MAX_100
},
543 .p1
= {.min
= MDFLD_DPLL_P1_MIN_100
, .max
= MDFLD_DPLL_P1_MAX_100
},
545 { /* MDFLD_LIMT_DSIPLL_19 */
546 .dot
= {.min
= MDFLD_DOT_MIN
, .max
= MDFLD_DOT_MAX
},
547 .m
= {.min
= MDFLD_DSIPLL_M_MIN_19
, .max
= MDFLD_DSIPLL_M_MAX_19
},
548 .p1
= {.min
= MDFLD_DSIPLL_P1_MIN_19
, .max
= MDFLD_DSIPLL_P1_MAX_19
},
550 { /* MDFLD_LIMT_DSIPLL_25 */
551 .dot
= {.min
= MDFLD_DOT_MIN
, .max
= MDFLD_DOT_MAX
},
552 .m
= {.min
= MDFLD_DSIPLL_M_MIN_25
, .max
= MDFLD_DSIPLL_M_MAX_25
},
553 .p1
= {.min
= MDFLD_DSIPLL_P1_MIN_25
, .max
= MDFLD_DSIPLL_P1_MAX_25
},
555 { /* MDFLD_LIMT_DSIPLL_83 */
556 .dot
= {.min
= MDFLD_DOT_MIN
, .max
= MDFLD_DOT_MAX
},
557 .m
= {.min
= MDFLD_DSIPLL_M_MIN_83
, .max
= MDFLD_DSIPLL_M_MAX_83
},
558 .p1
= {.min
= MDFLD_DSIPLL_P1_MIN_83
, .max
= MDFLD_DSIPLL_P1_MAX_83
},
560 { /* MDFLD_LIMT_DSIPLL_100 */
561 .dot
= {.min
= MDFLD_DOT_MIN
, .max
= MDFLD_DOT_MAX
},
562 .m
= {.min
= MDFLD_DSIPLL_M_MIN_100
, .max
= MDFLD_DSIPLL_M_MAX_100
},
563 .p1
= {.min
= MDFLD_DSIPLL_P1_MIN_100
, .max
= MDFLD_DSIPLL_P1_MAX_100
},
567 #define MDFLD_M_MIN 21
568 #define MDFLD_M_MAX 180
569 static const u32 mdfld_m_converts
[] = {
570 /* M configuration table from 9-bit LFSR table */
571 224, 368, 440, 220, 366, 439, 219, 365, 182, 347, /* 21 - 30 */
572 173, 342, 171, 85, 298, 149, 74, 37, 18, 265, /* 31 - 40 */
573 388, 194, 353, 432, 216, 108, 310, 155, 333, 166, /* 41 - 50 */
574 83, 41, 276, 138, 325, 162, 337, 168, 340, 170, /* 51 - 60 */
575 341, 426, 469, 234, 373, 442, 221, 110, 311, 411, /* 61 - 70 */
576 461, 486, 243, 377, 188, 350, 175, 343, 427, 213, /* 71 - 80 */
577 106, 53, 282, 397, 354, 227, 113, 56, 284, 142, /* 81 - 90 */
578 71, 35, 273, 136, 324, 418, 465, 488, 500, 506, /* 91 - 100 */
579 253, 126, 63, 287, 399, 455, 483, 241, 376, 444, /* 101 - 110 */
580 478, 495, 503, 251, 381, 446, 479, 239, 375, 443, /* 111 - 120 */
581 477, 238, 119, 315, 157, 78, 295, 147, 329, 420, /* 121 - 130 */
582 210, 105, 308, 154, 77, 38, 275, 137, 68, 290, /* 131 - 140 */
583 145, 328, 164, 82, 297, 404, 458, 485, 498, 249, /* 141 - 150 */
584 380, 190, 351, 431, 471, 235, 117, 314, 413, 206, /* 151 - 160 */
585 103, 51, 25, 12, 262, 387, 193, 96, 48, 280, /* 161 - 170 */
586 396, 198, 99, 305, 152, 76, 294, 403, 457, 228, /* 171 - 180 */
589 static const struct mrst_limit_t
*mdfld_limit(struct drm_crtc
*crtc
)
591 const struct mrst_limit_t
*limit
= NULL
;
592 struct drm_device
*dev
= crtc
->dev
;
593 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
595 if (gma_pipe_has_type(crtc
, INTEL_OUTPUT_MIPI
)
596 || gma_pipe_has_type(crtc
, INTEL_OUTPUT_MIPI2
)) {
597 if ((ksel
== KSEL_CRYSTAL_19
) || (ksel
== KSEL_BYPASS_19
))
598 limit
= &mdfld_limits
[MDFLD_LIMT_DSIPLL_19
];
599 else if (ksel
== KSEL_BYPASS_25
)
600 limit
= &mdfld_limits
[MDFLD_LIMT_DSIPLL_25
];
601 else if ((ksel
== KSEL_BYPASS_83_100
) &&
602 (dev_priv
->core_freq
== 166))
603 limit
= &mdfld_limits
[MDFLD_LIMT_DSIPLL_83
];
604 else if ((ksel
== KSEL_BYPASS_83_100
) &&
605 (dev_priv
->core_freq
== 100 ||
606 dev_priv
->core_freq
== 200))
607 limit
= &mdfld_limits
[MDFLD_LIMT_DSIPLL_100
];
608 } else if (gma_pipe_has_type(crtc
, INTEL_OUTPUT_HDMI
)) {
609 if ((ksel
== KSEL_CRYSTAL_19
) || (ksel
== KSEL_BYPASS_19
))
610 limit
= &mdfld_limits
[MDFLD_LIMT_DPLL_19
];
611 else if (ksel
== KSEL_BYPASS_25
)
612 limit
= &mdfld_limits
[MDFLD_LIMT_DPLL_25
];
613 else if ((ksel
== KSEL_BYPASS_83_100
) &&
614 (dev_priv
->core_freq
== 166))
615 limit
= &mdfld_limits
[MDFLD_LIMT_DPLL_83
];
616 else if ((ksel
== KSEL_BYPASS_83_100
) &&
617 (dev_priv
->core_freq
== 100 ||
618 dev_priv
->core_freq
== 200))
619 limit
= &mdfld_limits
[MDFLD_LIMT_DPLL_100
];
622 dev_dbg(dev
->dev
, "mdfld_limit Wrong display type.\n");
628 /** Derive the pixel clock for the given refclk and divisors for 8xx chips. */
629 static void mdfld_clock(int refclk
, struct mrst_clock_t
*clock
)
631 clock
->dot
= (refclk
* clock
->m
) / clock
->p1
;
635 * Returns a set of divisors for the desired target clock with the given refclk,
636 * or FALSE. Divisor values are the actual divisors for
639 mdfldFindBestPLL(struct drm_crtc
*crtc
, int target
, int refclk
,
640 struct mrst_clock_t
*best_clock
)
642 struct mrst_clock_t clock
;
643 const struct mrst_limit_t
*limit
= mdfld_limit(crtc
);
646 memset(best_clock
, 0, sizeof(*best_clock
));
648 for (clock
.m
= limit
->m
.min
; clock
.m
<= limit
->m
.max
; clock
.m
++) {
649 for (clock
.p1
= limit
->p1
.min
; clock
.p1
<= limit
->p1
.max
;
653 mdfld_clock(refclk
, &clock
);
655 this_err
= abs(clock
.dot
- target
);
656 if (this_err
< err
) {
662 return err
!= target
;
665 static int mdfld_crtc_mode_set(struct drm_crtc
*crtc
,
666 struct drm_display_mode
*mode
,
667 struct drm_display_mode
*adjusted_mode
,
669 struct drm_framebuffer
*old_fb
)
671 struct drm_device
*dev
= crtc
->dev
;
672 struct gma_crtc
*gma_crtc
= to_gma_crtc(crtc
);
673 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
674 int pipe
= gma_crtc
->pipe
;
675 const struct psb_offset
*map
= &dev_priv
->regmap
[pipe
];
677 int clk_n
= 0, clk_p2
= 0, clk_byte
= 1, clk
= 0, m_conv
= 0,
679 struct mrst_clock_t clock
;
681 u32 dpll
= 0, fp
= 0;
682 bool is_mipi
= false, is_mipi2
= false, is_hdmi
= false;
683 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
684 struct gma_encoder
*gma_encoder
= NULL
;
685 uint64_t scalingType
= DRM_MODE_SCALE_FULLSCREEN
;
686 struct drm_encoder
*encoder
;
687 struct drm_connector
*connector
;
691 dev_dbg(dev
->dev
, "pipe = 0x%x\n", pipe
);
695 if (!gma_power_begin(dev
, true))
697 android_hdmi_crtc_mode_set(crtc
, mode
, adjusted_mode
,
699 goto mrst_crtc_mode_set_exit
;
703 ret
= check_fb(crtc
->primary
->fb
);
707 dev_dbg(dev
->dev
, "adjusted_hdisplay = %d\n",
708 adjusted_mode
->hdisplay
);
709 dev_dbg(dev
->dev
, "adjusted_vdisplay = %d\n",
710 adjusted_mode
->vdisplay
);
711 dev_dbg(dev
->dev
, "adjusted_hsync_start = %d\n",
712 adjusted_mode
->hsync_start
);
713 dev_dbg(dev
->dev
, "adjusted_hsync_end = %d\n",
714 adjusted_mode
->hsync_end
);
715 dev_dbg(dev
->dev
, "adjusted_htotal = %d\n",
716 adjusted_mode
->htotal
);
717 dev_dbg(dev
->dev
, "adjusted_vsync_start = %d\n",
718 adjusted_mode
->vsync_start
);
719 dev_dbg(dev
->dev
, "adjusted_vsync_end = %d\n",
720 adjusted_mode
->vsync_end
);
721 dev_dbg(dev
->dev
, "adjusted_vtotal = %d\n",
722 adjusted_mode
->vtotal
);
723 dev_dbg(dev
->dev
, "adjusted_clock = %d\n",
724 adjusted_mode
->clock
);
725 dev_dbg(dev
->dev
, "hdisplay = %d\n",
727 dev_dbg(dev
->dev
, "vdisplay = %d\n",
730 if (!gma_power_begin(dev
, true))
733 memcpy(&gma_crtc
->saved_mode
, mode
,
734 sizeof(struct drm_display_mode
));
735 memcpy(&gma_crtc
->saved_adjusted_mode
, adjusted_mode
,
736 sizeof(struct drm_display_mode
));
738 list_for_each_entry(connector
, &mode_config
->connector_list
, head
) {
742 encoder
= connector
->encoder
;
747 if (encoder
->crtc
!= crtc
)
750 gma_encoder
= gma_attached_encoder(connector
);
752 switch (gma_encoder
->type
) {
753 case INTEL_OUTPUT_MIPI
:
756 case INTEL_OUTPUT_MIPI2
:
759 case INTEL_OUTPUT_HDMI
:
765 /* Disable the VGA plane that we never use */
766 REG_WRITE(VGACNTRL
, VGA_DISP_DISABLE
);
768 /* Disable the panel fitter if it was on our pipe */
769 if (psb_intel_panel_fitter_pipe(dev
) == pipe
)
770 REG_WRITE(PFIT_CONTROL
, 0);
772 /* pipesrc and dspsize control the size that is scaled from,
773 * which should always be the user's requested size.
776 /* FIXME: To make HDMI display with 864x480 (TPO), 480x864
777 * (PYR) or 480x854 (TMD), set the sprite width/height and
778 * souce image size registers with the adjusted mode for
783 * The defined sprite rectangle must always be completely
784 * contained within the displayable area of the screen image
787 REG_WRITE(map
->size
, ((min(mode
->crtc_vdisplay
, adjusted_mode
->crtc_vdisplay
) - 1) << 16)
788 | (min(mode
->crtc_hdisplay
, adjusted_mode
->crtc_hdisplay
) - 1));
789 /* Set the CRTC with encoder mode. */
790 REG_WRITE(map
->src
, ((mode
->crtc_hdisplay
- 1) << 16)
791 | (mode
->crtc_vdisplay
- 1));
794 ((mode
->crtc_vdisplay
- 1) << 16) |
795 (mode
->crtc_hdisplay
- 1));
797 ((mode
->crtc_hdisplay
- 1) << 16) |
798 (mode
->crtc_vdisplay
- 1));
801 REG_WRITE(map
->pos
, 0);
804 drm_object_property_get_value(&connector
->base
,
805 dev
->mode_config
.scaling_mode_property
, &scalingType
);
807 if (scalingType
== DRM_MODE_SCALE_NO_SCALE
) {
808 /* Medfield doesn't have register support for centering so we
809 * need to mess with the h/vblank and h/vsync start and ends
812 int offsetX
= 0, offsetY
= 0;
814 offsetX
= (adjusted_mode
->crtc_hdisplay
-
815 mode
->crtc_hdisplay
) / 2;
816 offsetY
= (adjusted_mode
->crtc_vdisplay
-
817 mode
->crtc_vdisplay
) / 2;
819 REG_WRITE(map
->htotal
, (mode
->crtc_hdisplay
- 1) |
820 ((adjusted_mode
->crtc_htotal
- 1) << 16));
821 REG_WRITE(map
->vtotal
, (mode
->crtc_vdisplay
- 1) |
822 ((adjusted_mode
->crtc_vtotal
- 1) << 16));
823 REG_WRITE(map
->hblank
, (adjusted_mode
->crtc_hblank_start
-
825 ((adjusted_mode
->crtc_hblank_end
- offsetX
- 1) << 16));
826 REG_WRITE(map
->hsync
, (adjusted_mode
->crtc_hsync_start
-
828 ((adjusted_mode
->crtc_hsync_end
- offsetX
- 1) << 16));
829 REG_WRITE(map
->vblank
, (adjusted_mode
->crtc_vblank_start
-
831 ((adjusted_mode
->crtc_vblank_end
- offsetY
- 1) << 16));
832 REG_WRITE(map
->vsync
, (adjusted_mode
->crtc_vsync_start
-
834 ((adjusted_mode
->crtc_vsync_end
- offsetY
- 1) << 16));
836 REG_WRITE(map
->htotal
, (adjusted_mode
->crtc_hdisplay
- 1) |
837 ((adjusted_mode
->crtc_htotal
- 1) << 16));
838 REG_WRITE(map
->vtotal
, (adjusted_mode
->crtc_vdisplay
- 1) |
839 ((adjusted_mode
->crtc_vtotal
- 1) << 16));
840 REG_WRITE(map
->hblank
, (adjusted_mode
->crtc_hblank_start
- 1) |
841 ((adjusted_mode
->crtc_hblank_end
- 1) << 16));
842 REG_WRITE(map
->hsync
, (adjusted_mode
->crtc_hsync_start
- 1) |
843 ((adjusted_mode
->crtc_hsync_end
- 1) << 16));
844 REG_WRITE(map
->vblank
, (adjusted_mode
->crtc_vblank_start
- 1) |
845 ((adjusted_mode
->crtc_vblank_end
- 1) << 16));
846 REG_WRITE(map
->vsync
, (adjusted_mode
->crtc_vsync_start
- 1) |
847 ((adjusted_mode
->crtc_vsync_end
- 1) << 16));
850 /* Flush the plane changes */
852 const struct drm_crtc_helper_funcs
*crtc_funcs
=
853 crtc
->helper_private
;
854 crtc_funcs
->mode_set_base(crtc
, x
, y
, old_fb
);
858 dev_priv
->pipeconf
[pipe
] = PIPEACONF_ENABLE
; /* FIXME_JLIU7 REG_READ(pipeconf_reg); */
860 /* Set up the display plane register */
861 dev_priv
->dspcntr
[pipe
] = REG_READ(map
->cntr
);
862 dev_priv
->dspcntr
[pipe
] |= pipe
<< DISPPLANE_SEL_PIPE_POS
;
863 dev_priv
->dspcntr
[pipe
] |= DISPLAY_PLANE_ENABLE
;
866 goto mrst_crtc_mode_set_exit
;
867 clk
= adjusted_mode
->clock
;
870 if ((ksel
== KSEL_CRYSTAL_19
) || (ksel
== KSEL_BYPASS_19
)) {
873 if (is_mipi
|| is_mipi2
)
874 clk_n
= 1, clk_p2
= 8;
876 clk_n
= 1, clk_p2
= 10;
877 } else if (ksel
== KSEL_BYPASS_25
) {
880 if (is_mipi
|| is_mipi2
)
881 clk_n
= 1, clk_p2
= 8;
883 clk_n
= 1, clk_p2
= 10;
884 } else if ((ksel
== KSEL_BYPASS_83_100
) &&
885 dev_priv
->core_freq
== 166) {
888 if (is_mipi
|| is_mipi2
)
889 clk_n
= 4, clk_p2
= 8;
891 clk_n
= 4, clk_p2
= 10;
892 } else if ((ksel
== KSEL_BYPASS_83_100
) &&
893 (dev_priv
->core_freq
== 100 ||
894 dev_priv
->core_freq
== 200)) {
896 if (is_mipi
|| is_mipi2
)
897 clk_n
= 4, clk_p2
= 8;
899 clk_n
= 4, clk_p2
= 10;
903 clk_byte
= dev_priv
->bpp
/ 8;
905 clk_byte
= dev_priv
->bpp2
/ 8;
907 clk_tmp
= clk
* clk_n
* clk_p2
* clk_byte
;
909 dev_dbg(dev
->dev
, "clk = %d, clk_n = %d, clk_p2 = %d.\n",
911 dev_dbg(dev
->dev
, "adjusted_mode->clock = %d, clk_tmp = %d.\n",
912 adjusted_mode
->clock
, clk_tmp
);
914 ok
= mdfldFindBestPLL(crtc
, clk_tmp
, refclk
, &clock
);
918 ("mdfldFindBestPLL fail in mdfld_crtc_mode_set.\n");
920 m_conv
= mdfld_m_converts
[(clock
.m
- MDFLD_M_MIN
)];
922 dev_dbg(dev
->dev
, "dot clock = %d,"
923 "m = %d, p1 = %d, m_conv = %d.\n",
928 dpll
= REG_READ(map
->dpll
);
930 if (dpll
& DPLL_VCO_ENABLE
) {
931 dpll
&= ~DPLL_VCO_ENABLE
;
932 REG_WRITE(map
->dpll
, dpll
);
935 /* FIXME jliu7 check the DPLL lock bit PIPEACONF[29] */
936 /* FIXME_MDFLD PO - change 500 to 1 after PO */
939 /* reset M1, N1 & P1 */
940 REG_WRITE(map
->fp0
, 0);
941 dpll
&= ~MDFLD_P1_MASK
;
942 REG_WRITE(map
->dpll
, dpll
);
943 /* FIXME_MDFLD PO - change 500 to 1 after PO */
947 /* When ungating power of DPLL, needs to wait 0.5us before
949 if (dpll
& MDFLD_PWR_GATE_EN
) {
950 dpll
&= ~MDFLD_PWR_GATE_EN
;
951 REG_WRITE(map
->dpll
, dpll
);
952 /* FIXME_MDFLD PO - change 500 to 1 after PO */
957 #if 0 /* FIXME revisit later */
958 if (ksel
== KSEL_CRYSTAL_19
|| ksel
== KSEL_BYPASS_19
||
959 ksel
== KSEL_BYPASS_25
)
960 dpll
&= ~MDFLD_INPUT_REF_SEL
;
961 else if (ksel
== KSEL_BYPASS_83_100
)
962 dpll
|= MDFLD_INPUT_REF_SEL
;
963 #endif /* FIXME revisit later */
966 dpll
|= MDFLD_VCO_SEL
;
968 fp
= (clk_n
/ 2) << 16;
971 /* compute bitmask from p1 value */
972 dpll
|= (1 << (clock
.p1
- 2)) << 17;
974 #if 0 /* 1080p30 & 720p */
983 #if 0 /*DBI_TPO_480x864*/
986 #endif /* DBI_TPO_480x864 */ /* get from spec. */
992 REG_WRITE(map
->fp0
, fp
);
993 REG_WRITE(map
->dpll
, dpll
);
994 /* FIXME_MDFLD PO - change 500 to 1 after PO */
997 dpll
|= DPLL_VCO_ENABLE
;
998 REG_WRITE(map
->dpll
, dpll
);
1001 /* wait for DSI PLL to lock */
1002 while (timeout
< 20000 &&
1003 !(REG_READ(map
->conf
) & PIPECONF_DSIPLL_LOCK
)) {
1009 goto mrst_crtc_mode_set_exit
;
1011 dev_dbg(dev
->dev
, "is_mipi = 0x%x\n", is_mipi
);
1013 REG_WRITE(map
->conf
, dev_priv
->pipeconf
[pipe
]);
1014 REG_READ(map
->conf
);
1016 /* Wait for for the pipe enable to take effect. */
1017 REG_WRITE(map
->cntr
, dev_priv
->dspcntr
[pipe
]);
1018 gma_wait_for_vblank(dev
);
1020 mrst_crtc_mode_set_exit
:
1027 const struct drm_crtc_helper_funcs mdfld_helper_funcs
= {
1028 .dpms
= mdfld_crtc_dpms
,
1029 .mode_fixup
= gma_crtc_mode_fixup
,
1030 .mode_set
= mdfld_crtc_mode_set
,
1031 .mode_set_base
= mdfld__intel_pipe_set_base
,
1032 .prepare
= gma_crtc_prepare
,
1033 .commit
= gma_crtc_commit
,