21 #include <linux/i2c.h>
55 #define INTEL_P2_NUM 2
71 #define CDV_LIMIT_SINGLE_LVDS_96 0
72 #define CDV_LIMIT_SINGLE_LVDS_100 1
73 #define CDV_LIMIT_DAC_HDMI_27 2
74 #define CDV_LIMIT_DAC_HDMI_96 3
75 #define CDV_LIMIT_DP_27 4
76 #define CDV_LIMIT_DP_100 5
80 .dot = {.min = 20000, .max = 115500},
81 .vco = {.min = 1800000, .max = 3600000},
82 .n = {.min = 2, .max = 6},
83 .m = {.min = 60, .max = 160},
84 .m1 = {.min = 0, .max = 0},
85 .m2 = {.min = 58, .max = 158},
86 .p = {.min = 28, .max = 140},
87 .p1 = {.min = 2, .max = 10},
88 .p2 = {.dot_limit = 200000,
89 .p2_slow = 14, .p2_fast = 14},
90 .find_pll = cdv_intel_find_best_PLL,
93 .dot = {.min = 20000, .max = 115500},
94 .vco = {.min = 1800000, .max = 3600000},
95 .n = {.min = 2, .max = 6},
96 .m = {.min = 60, .max = 160},
97 .m1 = {.min = 0, .max = 0},
98 .m2 = {.min = 58, .max = 158},
99 .p = {.min = 28, .max = 140},
100 .p1 = {.min = 2, .max = 10},
104 .p2 = {.dot_limit = 200000, .p2_slow = 14, .p2_fast = 14},
105 .find_pll = cdv_intel_find_best_PLL,
108 .dot = {.min = 20000, .max = 400000},
109 .vco = {.min = 1809000, .max = 3564000},
110 .n = {.min = 1, .max = 1},
111 .m = {.min = 67, .max = 132},
112 .m1 = {.min = 0, .max = 0},
113 .m2 = {.min = 65, .max = 130},
114 .p = {.min = 5, .max = 90},
115 .p1 = {.min = 1, .max = 9},
116 .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 5},
117 .find_pll = cdv_intel_find_best_PLL,
120 .dot = {.min = 20000, .max = 400000},
121 .vco = {.min = 1800000, .max = 3600000},
122 .n = {.min = 2, .max = 6},
123 .m = {.min = 60, .max = 160},
124 .m1 = {.min = 0, .max = 0},
125 .m2 = {.min = 58, .max = 158},
126 .p = {.min = 5, .max = 100},
127 .p1 = {.min = 1, .max = 10},
128 .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 5},
129 .find_pll = cdv_intel_find_best_PLL,
132 .dot = {.min = 160000, .max = 272000},
133 .vco = {.min = 1809000, .max = 3564000},
134 .n = {.min = 1, .max = 1},
135 .m = {.min = 67, .max = 132},
136 .m1 = {.min = 0, .max = 0},
137 .m2 = {.min = 65, .max = 130},
138 .p = {.min = 5, .max = 90},
139 .p1 = {.min = 1, .max = 9},
140 .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 10},
141 .find_pll = cdv_intel_find_dp_pll,
144 .dot = {.min = 160000, .max = 272000},
145 .vco = {.min = 1800000, .max = 3600000},
146 .n = {.min = 2, .max = 6},
147 .m = {.min = 60, .max = 164},
148 .m1 = {.min = 0, .max = 0},
149 .m2 = {.min = 58, .max = 162},
150 .p = {.min = 5, .max = 100},
151 .p1 = {.min = 1, .max = 10},
152 .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 10},
153 .find_pll = cdv_intel_find_dp_pll,
157 #define _wait_for(COND, MS, W) ({ \
158 unsigned long timeout__ = jiffies + msecs_to_jiffies(MS); \
161 if (time_after(jiffies, timeout__)) { \
162 ret__ = -ETIMEDOUT; \
165 if (W && !in_dbg_master()) \
171 #define wait_for(COND, MS) _wait_for(COND, MS, 1)
180 DRM_ERROR(
"timeout waiting for SB to idle before read\n");
192 DRM_ERROR(
"timeout waiting for SB to idle after read\n");
204 static bool dpio_debug =
true;
209 DRM_DEBUG_KMS(
"0x%08x: 0x%08x (before)\n", reg, temp);
210 DRM_DEBUG_KMS(
"0x%08x: 0x%08x\n", reg, val);
215 DRM_ERROR(
"timeout waiting for SB to idle before write\n");
228 DRM_ERROR(
"timeout waiting for SB to idle after write\n");
234 DRM_DEBUG_KMS(
"0x%08x: 0x%08x (after)\n", reg, temp);
267 u32 lane_reg, lane_value;
276 ref_value = 0x68A701;
301 if (pipe == 1 && !is_lvds && !(ddi_select &
DP_MASK)) {
302 DRM_DEBUG_KMS(
"use DPLLA for pipe B\n");
305 DRM_DEBUG_KMS(
"use their DPLL for pipe A/B\n");
334 if (clock->
vco < 2250000) {
337 }
else if (clock->
vco < 2750000) {
340 }
else if (clock->
vco < 3300000) {
371 DRM_ERROR(
"Bad P2 clock: %d\n", clock->
p2);
411 static bool cdv_intel_pipe_has_type(
struct drm_crtc *crtc,
int type)
420 psb_intel_attached_encoder(l_entry);
421 if (psb_intel_encoder->
type == type)
457 static void cdv_intel_clock(
struct drm_device *dev,
460 clock->
m = clock->
m2 + 2;
461 clock->
p = clock->
p1 * clock->
p2;
462 clock->
vco = (refclk * clock->
m) / clock->
n;
463 clock->
dot = clock->
vco / clock->
p;
467 #define INTELPllInvalid(s) { ; return false; }
468 static bool cdv_intel_PLL_is_valid(
struct drm_crtc *crtc,
472 if (clock->
p1 < limit->
p1.min || limit->
p1.max < clock->
p1)
474 if (clock->
p < limit->p.min || limit->p.max < clock->
p)
477 if (clock->
vco < limit->vco.min || limit->vco.max < clock->
vco)
483 if (clock->
dot < limit->dot.min || limit->dot.max < clock->
dot)
508 clock.
p2 = limit->
p2.p2_fast;
510 clock.
p2 = limit->
p2.p2_slow;
512 if (target < limit->
p2.dot_limit)
513 clock.
p2 = limit->
p2.p2_slow;
515 clock.
p2 = limit->
p2.p2_fast;
518 memset(best_clock, 0,
sizeof(*best_clock));
522 for (clock.
n = limit->n.min; clock.
n <= limit->n.max; clock.
n++) {
523 for (clock.
m2 = limit->m2.min; clock.
m2 <= limit->m2.max;
525 for (clock.
p1 = limit->
p1.min;
526 clock.
p1 <= limit->
p1.max;
530 cdv_intel_clock(dev, refclk, &clock);
532 if (!cdv_intel_PLL_is_valid(crtc,
536 this_err =
abs(clock.
dot - target);
537 if (this_err < err) {
553 if (refclk == 27000) {
554 if (target < 200000) {
567 }
else if (refclk == 100000) {
568 if (target < 200000) {
583 clock.
m = clock.
m2 + 2;
584 clock.
p = clock.
p1 * clock.
p2;
585 clock.
vco = (refclk * clock.
m) / clock.
n;
586 clock.
dot = clock.
vco / clock.
p;
591 static int cdv_intel_pipe_set_base(
struct drm_crtc *crtc,
598 int pipe = psb_intel_crtc->
pipe;
609 dev_err(dev->dev,
"No FB bound\n");
610 goto psb_intel_pipe_cleaner;
618 goto psb_intel_pipe_set_base_exit;
619 start = psbfb->
gtt->offset;
620 offset = y * crtc->
fb->pitches[0] + x * (crtc->
fb->bits_per_pixel / 8);
627 switch (crtc->
fb->bits_per_pixel) {
632 if (crtc->
fb->depth == 15)
642 dev_err(dev->dev,
"Unknown color depth\n");
644 goto psb_intel_pipe_set_base_exit;
649 "Writing base %08lX %08lX %d %d\n", start, offset, x, y);
656 psb_intel_pipe_cleaner:
661 psb_intel_pipe_set_base_exit:
666 #define FIFO_PIPEA (1 << 0)
667 #define FIFO_PIPEB (1 << 1)
669 static bool cdv_intel_pipe_enabled(
struct drm_device *dev,
int pipe)
673 struct psb_intel_crtc *psb_intel_crtc =
NULL;
683 static bool cdv_intel_single_pipe_active (
struct drm_device *dev)
687 if (cdv_intel_pipe_enabled(dev, 0))
690 if (cdv_intel_pipe_enabled(dev, 1))
694 DRM_DEBUG_KMS(
"pipe enabled %x\n", pipe_enabled);
708 if (psb_intel_crtc->
pipe != 1)
713 psb_intel_attached_encoder(connector);
716 || connector->
encoder->crtc != crtc)
726 static void cdv_intel_disable_self_refresh (
struct drm_device *dev)
734 cdv_intel_wait_for_vblank(dev);
742 cdv_intel_wait_for_vblank(dev);
747 static void cdv_intel_update_watermark (
struct drm_device *dev,
struct drm_crtc *crtc)
750 if (cdv_intel_single_pipe_active(dev)) {
771 if (is_pipeb_lvds(dev, crtc)) {
783 cdv_intel_wait_for_vblank(dev);
788 cdv_intel_wait_for_vblank(dev);
800 cdv_intel_wait_for_vblank(dev);
802 cdv_intel_disable_self_refresh(dev);
808 static void cdv_intel_crtc_load_lut(
struct drm_crtc *crtc)
820 switch (psb_intel_crtc->
pipe) {
830 dev_err(dev->dev,
"Illegal Pipe Number.\n");
835 for (i = 0; i < 256; i++) {
837 ((psb_intel_crtc->
lut_r[i] +
838 psb_intel_crtc->
lut_adj[i]) << 16) |
839 ((psb_intel_crtc->
lut_g[i] +
840 psb_intel_crtc->
lut_adj[i]) << 8) |
841 (psb_intel_crtc->
lut_b[i] +
846 for (i = 0; i < 256; i++) {
847 dev_priv->
regs.pipe[0].palette[
i] =
848 ((psb_intel_crtc->
lut_r[
i] +
849 psb_intel_crtc->
lut_adj[
i]) << 16) |
850 ((psb_intel_crtc->
lut_g[
i] +
852 (psb_intel_crtc->
lut_b[
i] +
865 static void cdv_intel_crtc_dpms(
struct drm_crtc *crtc,
int mode)
870 int pipe = psb_intel_crtc->
pipe;
877 cdv_intel_disable_self_refresh(dev);
883 if (psb_intel_crtc->
active)
886 psb_intel_crtc->
active =
true;
910 temp | DISPLAY_PLANE_ENABLE);
928 cdv_intel_crtc_load_lut(crtc);
935 if (!psb_intel_crtc->
active)
938 psb_intel_crtc->
active =
false;
951 cdv_intel_wait_for_vblank(dev);
955 if ((temp & PIPEACONF_ENABLE) != 0) {
961 cdv_intel_wait_for_vblank(dev);
967 if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
969 temp & ~DISPLAY_PLANE_ENABLE);
976 if ((temp & DPLL_VCO_ENABLE) != 0) {
985 cdv_intel_update_watermark(dev, crtc);
990 static void cdv_intel_crtc_prepare(
struct drm_crtc *crtc)
996 static void cdv_intel_crtc_commit(
struct drm_crtc *crtc)
1002 static bool cdv_intel_crtc_mode_fixup(
struct drm_crtc *crtc,
1014 static int cdv_intel_panel_fitter_pipe(
struct drm_device *dev)
1023 return (pfit_control >> 29) & 0x3;
1026 static int cdv_intel_crtc_mode_set(
struct drm_crtc *crtc,
1035 int pipe = psb_intel_crtc->
pipe;
1039 u32 dpll = 0, dspcntr, pipeconf;
1041 bool is_crt =
false, is_lvds =
false, is_tv =
false;
1042 bool is_hdmi =
false, is_dp =
false;
1047 bool is_edp =
false;
1050 struct psb_intel_encoder *psb_intel_encoder =
1051 psb_intel_attached_encoder(connector);
1054 || connector->
encoder->crtc != crtc)
1058 switch (psb_intel_encoder->
type) {
1078 DRM_ERROR(
"invalid output type.\n");
1089 if (is_dp || is_edp) {
1106 DRM_DEBUG_KMS(
"Use SSC reference clock %d Mhz\n", dev_priv->
lvds_ssc_freq);
1111 limit = cdv_intel_limit(crtc, refclk);
1113 ok = limit->
find_pll(limit, crtc, adjusted_mode->
clock, refclk,
1116 dev_err(dev->dev,
"Couldn't find PLL settings for mode!\n");
1128 if (is_dp || is_edp) {
1149 switch (dev_priv->
edp.bpp) {
1163 }
else if (is_lvds) {
1186 cdv_dpll_set_clock_cdv(dev, crtc, &clock, is_lvds, ddi_select);
1222 if (cdv_intel_panel_fitter_pipe(dev) == pipe)
1225 DRM_DEBUG_KMS(
"Mode for pipe %c:\n", pipe == 0 ?
'A' :
'B');
1235 dev_err(dev->dev,
"Failed to get DPLL lock\n");
1240 int sdvo_pixel_multiply = adjusted_mode->
clock / mode->
clock;
1267 cdv_intel_wait_for_vblank(dev);
1278 cdv_intel_wait_for_vblank(dev);
1287 static void cdv_intel_crtc_save(
struct drm_crtc *crtc)
1298 dev_dbg(dev->dev,
"No CRTC state found\n");
1322 DRM_DEBUG(
"(%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x)\n",
1342 for (i = 0; i < 256; ++
i)
1349 static void cdv_intel_crtc_restore(
struct drm_crtc *crtc)
1360 dev_dbg(dev->dev,
"No crtc state\n");
1365 "current:(%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x)\n",
1385 "saved: (%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x)\n",
1405 if (crtc_state->
saveDPLL & DPLL_VCO_ENABLE) {
1407 crtc_state->
saveDPLL & ~DPLL_VCO_ENABLE);
1409 DRM_DEBUG(
"write dpll: %x\n",
1439 cdv_intel_wait_for_vblank(dev);
1444 cdv_intel_wait_for_vblank(dev);
1447 for (i = 0; i < 256; ++
i)
1451 static int cdv_intel_crtc_cursor_set(
struct drm_crtc *crtc,
1452 struct drm_file *file_priv,
1458 int pipe = psb_intel_crtc->
pipe;
1464 struct drm_gem_object *obj;
1483 drm_gem_object_unreference(psb_intel_crtc->
cursor_obj);
1491 if (width != 64 || height != 64) {
1492 dev_dbg(dev->dev,
"we currently only support 64x64 cursors\n");
1500 if (obj->size < width * height * 4) {
1501 dev_dbg(dev->dev,
"buffer is to small\n");
1510 dev_err(dev->dev,
"Can not pin down handle 0x%x\n", handle);
1520 temp |= (pipe << 28);
1534 drm_gem_object_unreference(psb_intel_crtc->
cursor_obj);
1540 static int cdv_intel_crtc_cursor_move(
struct drm_crtc *crtc,
int x,
int y)
1544 int pipe = psb_intel_crtc->
pipe;
1571 static void cdv_intel_crtc_gamma_set(
struct drm_crtc *crtc,
u16 *
red,
1576 int end = (start + size > 256) ? 256 : start + size;
1578 for (i = start; i <
end; i++) {
1579 psb_intel_crtc->
lut_r[
i] = red[
i] >> 8;
1580 psb_intel_crtc->
lut_g[
i] = green[
i] >> 8;
1581 psb_intel_crtc->
lut_b[
i] = blue[
i] >> 8;
1584 cdv_intel_crtc_load_lut(crtc);
1587 static int cdv_crtc_set_config(
struct drm_mode_set *
set)
1611 clock->
m = 5 * (clock->
m1 + 2) + (clock->
m2 + 2);
1612 clock->
p = clock->
p1 * clock->
p2;
1613 clock->
vco = refclk * clock->
m / (clock->
n + 2);
1614 clock->
dot = clock->
vco / clock->
p;
1618 static int cdv_intel_crtc_clock_get(
struct drm_device *dev,
1623 int pipe = psb_intel_crtc->
pipe;
1641 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
1646 is_lvds = (pipe == 1) &&
1647 (dev_priv->
regs.psb.saveLVDS & LVDS_PORT_EN);
1659 if (clock.
p1 == 0) {
1661 dev_err(dev->dev,
"PLL %d\n", dpll);
1668 i8xx_clock(66000, &clock);
1670 i8xx_clock(48000, &clock);
1685 i8xx_clock(48000, &clock);
1701 int pipe = psb_intel_crtc->
pipe;
1728 mode->
clock = cdv_intel_crtc_clock_get(dev, crtc);
1729 mode->
hdisplay = (htot & 0xffff) + 1;
1730 mode->
htotal = ((htot & 0xffff0000) >> 16) + 1;
1732 mode->
hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
1733 mode->
vdisplay = (vtot & 0xffff) + 1;
1734 mode->
vtotal = ((vtot & 0xffff0000) >> 16) + 1;
1736 mode->
vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
1744 static void cdv_intel_crtc_destroy(
struct drm_crtc *crtc)
1750 kfree(psb_intel_crtc);
1754 .dpms = cdv_intel_crtc_dpms,
1755 .mode_fixup = cdv_intel_crtc_mode_fixup,
1756 .mode_set = cdv_intel_crtc_mode_set,
1757 .mode_set_base = cdv_intel_pipe_set_base,
1758 .prepare = cdv_intel_crtc_prepare,
1759 .commit = cdv_intel_crtc_commit,
1763 .save = cdv_intel_crtc_save,
1764 .restore = cdv_intel_crtc_restore,
1765 .cursor_set = cdv_intel_crtc_cursor_set,
1766 .cursor_move = cdv_intel_crtc_cursor_move,
1767 .gamma_set = cdv_intel_crtc_gamma_set,
1768 .set_config = cdv_crtc_set_config,
1769 .destroy = cdv_intel_crtc_destroy,