21 #include <linux/i2c.h>
49 #define COUNT_MAX 0x10000000
63 DRM_ERROR(
"Illegal Pipe Number.\n");
72 for (count = 0; count <
COUNT_MAX; count++) {
91 DRM_ERROR(
"Illegal Pipe Number.\n");
100 for (count = 0; count <
COUNT_MAX; count++) {
107 static void psb_intel_crtc_prepare(
struct drm_crtc *
crtc)
113 static void psb_intel_crtc_commit(
struct drm_crtc *crtc)
119 static bool psb_intel_crtc_mode_fixup(
struct drm_crtc *crtc,
130 static int psb_intel_panel_fitter_pipe(
struct drm_device *
dev)
141 return (pfit_control >> 29) & 0x3;
177 DRM_ERROR(
"Unknown color depth\n");
182 static int mdfld__intel_pipe_set_base(
struct drm_crtc *crtc,
int x,
int y,
197 dev_dbg(dev->dev,
"pipe = 0x%x.\n", pipe);
201 dev_dbg(dev->dev,
"No FB bound\n");
205 ret = check_fb(crtc->
fb);
210 DRM_ERROR(
"Illegal Pipe Number.\n");
217 start = psbfb->
gtt->offset;
218 offset = y * crtc->
fb->pitches[0] + x * (crtc->
fb->bits_per_pixel / 8);
224 switch (crtc->
fb->bits_per_pixel) {
229 if (crtc->
fb->depth == 15)
241 dev_dbg(dev->dev,
"Writing base %08lX %08lX %d %d\n",
242 start, offset, x, y);
263 dev_dbg(dev->dev,
"pipe = %d\n", pipe);
274 temp & ~DISPLAY_PLANE_ENABLE);
285 temp &= ~PIPEACONF_ENABLE;
298 & PIPEACONF_ENABLE)) || pipe == 1) {
323 static void mdfld_crtc_dpms(
struct drm_crtc *crtc,
int mode)
328 int pipe = psb_intel_crtc->
pipe;
334 dev_dbg(dev->dev,
"mode = %d, pipe = %d\n", mode, pipe);
356 temp &= ~MDFLD_PWR_GATE_EN;
375 while ((pipe != 2) && (timeout < 20000) &&
386 temp | DISPLAY_PLANE_ENABLE);
402 if (pipe == 0 || pipe == 2) {
408 dev_dbg(dev->dev,
"STUCK!!!!");
412 temp & ~DISPLAY_PLANE_ENABLE);
418 temp &= ~PIPEACONF_ENABLE;
428 temp | DISPLAY_PLANE_ENABLE);
460 if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
462 temp & ~DISPLAY_PLANE_ENABLE);
470 if ((temp & PIPEACONF_ENABLE) != 0) {
471 temp &= ~PIPEACONF_ENABLE;
481 if (temp & DPLL_VCO_ENABLE) {
499 #define MDFLD_LIMT_DPLL_19 0
500 #define MDFLD_LIMT_DPLL_25 1
501 #define MDFLD_LIMT_DPLL_83 2
502 #define MDFLD_LIMT_DPLL_100 3
503 #define MDFLD_LIMT_DSIPLL_19 4
504 #define MDFLD_LIMT_DSIPLL_25 5
505 #define MDFLD_LIMT_DSIPLL_83 6
506 #define MDFLD_LIMT_DSIPLL_100 7
508 #define MDFLD_DOT_MIN 19750
509 #define MDFLD_DOT_MAX 120000
510 #define MDFLD_DPLL_M_MIN_19 113
511 #define MDFLD_DPLL_M_MAX_19 155
512 #define MDFLD_DPLL_P1_MIN_19 2
513 #define MDFLD_DPLL_P1_MAX_19 10
514 #define MDFLD_DPLL_M_MIN_25 101
515 #define MDFLD_DPLL_M_MAX_25 130
516 #define MDFLD_DPLL_P1_MIN_25 2
517 #define MDFLD_DPLL_P1_MAX_25 10
518 #define MDFLD_DPLL_M_MIN_83 64
519 #define MDFLD_DPLL_M_MAX_83 64
520 #define MDFLD_DPLL_P1_MIN_83 2
521 #define MDFLD_DPLL_P1_MAX_83 2
522 #define MDFLD_DPLL_M_MIN_100 64
523 #define MDFLD_DPLL_M_MAX_100 64
524 #define MDFLD_DPLL_P1_MIN_100 2
525 #define MDFLD_DPLL_P1_MAX_100 2
526 #define MDFLD_DSIPLL_M_MIN_19 131
527 #define MDFLD_DSIPLL_M_MAX_19 175
528 #define MDFLD_DSIPLL_P1_MIN_19 3
529 #define MDFLD_DSIPLL_P1_MAX_19 8
530 #define MDFLD_DSIPLL_M_MIN_25 97
531 #define MDFLD_DSIPLL_M_MAX_25 140
532 #define MDFLD_DSIPLL_P1_MIN_25 3
533 #define MDFLD_DSIPLL_P1_MAX_25 9
534 #define MDFLD_DSIPLL_M_MIN_83 33
535 #define MDFLD_DSIPLL_M_MAX_83 92
536 #define MDFLD_DSIPLL_P1_MIN_83 2
537 #define MDFLD_DSIPLL_P1_MAX_83 3
538 #define MDFLD_DSIPLL_M_MIN_100 97
539 #define MDFLD_DSIPLL_M_MAX_100 140
540 #define MDFLD_DSIPLL_P1_MIN_100 3
541 #define MDFLD_DSIPLL_P1_MAX_100 9
586 #define MDFLD_M_MIN 21
587 #define MDFLD_M_MAX 180
588 static const u32 mdfld_m_converts[] = {
590 224, 368, 440, 220, 366, 439, 219, 365, 182, 347,
591 173, 342, 171, 85, 298, 149, 74, 37, 18, 265,
592 388, 194, 353, 432, 216, 108, 310, 155, 333, 166,
593 83, 41, 276, 138, 325, 162, 337, 168, 340, 170,
594 341, 426, 469, 234, 373, 442, 221, 110, 311, 411,
595 461, 486, 243, 377, 188, 350, 175, 343, 427, 213,
596 106, 53, 282, 397, 354, 227, 113, 56, 284, 142,
597 71, 35, 273, 136, 324, 418, 465, 488, 500, 506,
598 253, 126, 63, 287, 399, 455, 483, 241, 376, 444,
599 478, 495, 503, 251, 381, 446, 479, 239, 375, 443,
600 477, 238, 119, 315, 157, 78, 295, 147, 329, 420,
601 210, 105, 308, 154, 77, 38, 275, 137, 68, 290,
602 145, 328, 164, 82, 297, 404, 458, 485, 498, 249,
603 380, 190, 351, 431, 471, 235, 117, 314, 413, 206,
604 103, 51, 25, 12, 262, 387, 193, 96, 48, 280,
605 396, 198, 99, 305, 152, 76, 294, 403, 457, 228,
641 dev_dbg(dev->dev,
"mdfld_limit Wrong display type.\n");
650 clock->
dot = (refclk * clock->
m) / clock->
p1;
665 memset(best_clock, 0,
sizeof(*best_clock));
672 mdfld_clock(refclk, &
clock);
675 if (this_err < err) {
684 static int mdfld_crtc_mode_set(
struct drm_crtc *crtc,
693 int pipe = psb_intel_crtc->
pipe;
696 int clk_n = 0, clk_p2 = 0, clk_byte = 1,
clk = 0, m_conv = 0,
700 u32 dpll = 0,
fp = 0;
701 bool is_mipi =
false, is_mipi2 =
false, is_hdmi =
false;
710 dev_dbg(dev->dev,
"pipe = 0x%x\n", pipe);
716 android_hdmi_crtc_mode_set(crtc, mode, adjusted_mode,
718 goto mrst_crtc_mode_set_exit;
722 ret = check_fb(crtc->
fb);
726 dev_dbg(dev->dev,
"adjusted_hdisplay = %d\n",
728 dev_dbg(dev->dev,
"adjusted_vdisplay = %d\n",
730 dev_dbg(dev->dev,
"adjusted_hsync_start = %d\n",
732 dev_dbg(dev->dev,
"adjusted_hsync_end = %d\n",
734 dev_dbg(dev->dev,
"adjusted_htotal = %d\n",
736 dev_dbg(dev->dev,
"adjusted_vsync_start = %d\n",
738 dev_dbg(dev->dev,
"adjusted_vsync_end = %d\n",
740 dev_dbg(dev->dev,
"adjusted_vtotal = %d\n",
742 dev_dbg(dev->dev,
"adjusted_clock = %d\n",
743 adjusted_mode->
clock);
744 dev_dbg(dev->dev,
"hdisplay = %d\n",
746 dev_dbg(dev->dev,
"vdisplay = %d\n",
766 if (encoder->
crtc != crtc)
769 psb_intel_encoder = psb_intel_attached_encoder(connector);
771 switch (psb_intel_encoder->
type) {
788 if (psb_intel_panel_fitter_pipe(dev) == pipe)
822 if (psb_intel_encoder)
824 dev->mode_config.scaling_mode_property, &scalingType);
831 int offsetX = 0, offsetY = 0;
885 goto mrst_crtc_mode_set_exit;
892 if (is_mipi || is_mipi2)
893 clk_n = 1, clk_p2 = 8;
895 clk_n = 1, clk_p2 = 10;
899 if (is_mipi || is_mipi2)
900 clk_n = 1, clk_p2 = 8;
902 clk_n = 1, clk_p2 = 10;
907 if (is_mipi || is_mipi2)
908 clk_n = 4, clk_p2 = 8;
910 clk_n = 4, clk_p2 = 10;
915 if (is_mipi || is_mipi2)
916 clk_n = 4, clk_p2 = 8;
918 clk_n = 4, clk_p2 = 10;
922 clk_byte = dev_priv->
bpp / 8;
924 clk_byte = dev_priv->
bpp2 / 8;
926 clk_tmp =
clk * clk_n * clk_p2 * clk_byte;
928 dev_dbg(dev->dev,
"clk = %d, clk_n = %d, clk_p2 = %d.\n",
930 dev_dbg(dev->dev,
"adjusted_mode->clock = %d, clk_tmp = %d.\n",
931 adjusted_mode->
clock, clk_tmp);
933 ok = mdfldFindBestPLL(crtc, clk_tmp, refclk, &
clock);
937 (
"mdfldFindBestPLL fail in mdfld_crtc_mode_set.\n");
941 dev_dbg(dev->dev,
"dot clock = %d,"
942 "m = %d, p1 = %d, m_conv = %d.\n",
949 if (dpll & DPLL_VCO_ENABLE) {
950 dpll &= ~DPLL_VCO_ENABLE;
968 if (dpll & MDFLD_PWR_GATE_EN) {
969 dpll &= ~MDFLD_PWR_GATE_EN;
987 fp = (clk_n / 2) << 16;
991 dpll |= (1 << (
clock.p1 - 2)) << 17;
1021 while (timeout < 20000 &&
1028 goto mrst_crtc_mode_set_exit;
1030 dev_dbg(dev->dev,
"is_mipi = 0x%x\n", is_mipi);
1039 mrst_crtc_mode_set_exit:
1047 .dpms = mdfld_crtc_dpms,
1048 .mode_fixup = psb_intel_crtc_mode_fixup,
1049 .mode_set = mdfld_crtc_mode_set,
1050 .mode_set_base = mdfld__intel_pipe_set_base,
1051 .prepare = psb_intel_crtc_prepare,
1052 .commit = psb_intel_crtc_commit,