28 #include <linux/i2c.h>
29 #include <linux/slab.h>
38 #define _wait_for(COND, MS, W) ({ \
39 unsigned long timeout__ = jiffies + msecs_to_jiffies(MS); \
42 if (time_after(jiffies, timeout__)) { \
46 if (W && !in_dbg_master()) msleep(W); \
51 #define wait_for(COND, MS) _wait_for(COND, MS, 1)
53 #define DP_LINK_STATUS_SIZE 6
54 #define DP_LINK_CHECK_TIMEOUT (10 * 1000)
56 #define DP_LINK_CONFIGURATION_SIZE 9
58 #define CDV_FAST_LINK_TRAIN 1
94 static struct ddi_regoff ddi_DP_train_table[] = {
95 {.PreEmph1 = 0x812c, .PreEmph2 = 0x8124, .VSwing1 = 0x8154,
96 .VSwing2 = 0x8148, .VSwing3 = 0x814C, .VSwing4 = 0x8150,
98 {.PreEmph1 = 0x822c, .PreEmph2 = 0x8224, .VSwing1 = 0x8254,
99 .VSwing2 = 0x8248, .VSwing3 = 0x824C, .VSwing4 = 0x8250,
103 static uint32_t dp_vswing_premph_table[] = {
130 int max_lane_count = 4;
134 switch (max_lane_count) {
135 case 1:
case 2:
case 4:
141 return max_lane_count;
150 switch (max_link_bw) {
173 return (pixel_clock * bpp + 7) / 8;
177 cdv_intel_dp_max_data_rate(
int max_link_clock,
int max_lanes)
179 return (max_link_clock * max_lanes * 19) / 20;
189 DRM_DEBUG_KMS(
"Skip VDD on because of panel on\n");
235 DRM_DEBUG_KMS(
"Error in Powering up eDP panel, status %x\n",
REG_READ(
PP_STATUS));
261 pp &= ~POWER_TARGET_ON;
269 DRM_DEBUG_KMS(
"Error in turning off Panel\n");
273 DRM_DEBUG_KMS(
"Over\n");
296 static void cdv_intel_edp_backlight_off (
struct psb_intel_encoder *intel_encoder)
318 int max_link_clock = cdv_intel_dp_link_clock(cdv_intel_dp_max_link_bw(encoder));
319 int max_lanes = cdv_intel_dp_max_lane_count(encoder);
331 if (!is_edp(encoder) &&
332 (cdv_intel_dp_link_required(mode->
clock, dev_priv->
edp.bpp)
333 > cdv_intel_dp_max_data_rate(max_link_clock, max_lanes)))
336 if (is_edp(encoder)) {
337 if (cdv_intel_dp_link_required(mode->
clock, 24)
338 > cdv_intel_dp_max_data_rate(max_link_clock, max_lanes))
342 if (mode->
clock < 10000)
356 for (i = 0; i < src_bytes; i++)
367 for (i = 0; i < dst_bytes; i++)
368 dst[i] = src >> ((3-i) * 8);
379 uint32_t ch_ctl = output_reg + 0x10;
393 aux_clock_divider = 200 / 2;
400 DRM_ERROR(
"dp_aux_ch not started status 0x%08x\n",
406 for (
try = 0;
try < 5;
try++) {
408 for (i = 0; i < send_bytes; i += 4)
410 pack_aux(send + i, send_bytes - i));
414 DP_AUX_CH_CTL_SEND_BUSY |
424 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
440 DRM_ERROR(
"dp_aux_ch not done status 0x%08x\n", status);
448 DRM_ERROR(
"dp_aux_ch receive error status 0x%08x\n", status);
455 DRM_DEBUG_KMS(
"dp_aux_ch timeout status 0x%08x\n", status);
462 if (recv_bytes > recv_size)
463 recv_bytes = recv_size;
465 for (i = 0; i < recv_bytes; i += 4)
467 recv +
i, recv_bytes -
i);
485 msg[1] = address >> 8;
486 msg[2] = address & 0xff;
487 msg[3] = send_bytes - 1;
488 memcpy(&msg[4], send, send_bytes);
489 msg_bytes = send_bytes + 4;
491 ret = cdv_intel_dp_aux_ch(encoder, msg, msg_bytes, &ack, 1);
509 return cdv_intel_dp_aux_native_write(encoder, address, &byte, 1);
525 msg[1] = address >> 8;
526 msg[2] = address & 0xff;
527 msg[3] = recv_bytes - 1;
530 reply_bytes = recv_bytes + 1;
533 ret = cdv_intel_dp_aux_ch(encoder, msg, msg_bytes,
541 memcpy(recv, reply + 1, ret - 1);
577 msg[1] = address >> 8;
598 for (retry = 0; retry < 5; retry++) {
599 ret = cdv_intel_dp_aux_ch(encoder,
603 DRM_DEBUG_KMS(
"aux_ch failed %d\n", ret);
607 switch (reply[0] & AUX_NATIVE_REPLY_MASK) {
614 DRM_DEBUG_KMS(
"aux_ch native nack\n");
620 DRM_ERROR(
"aux_ch invalid native reply 0x%02x\n",
627 if (mode == MODE_I2C_READ) {
628 *read_byte = reply[1];
630 return reply_bytes - 1;
632 DRM_DEBUG_KMS(
"aux_i2c nack\n");
635 DRM_DEBUG_KMS(
"aux_i2c defer\n");
639 DRM_ERROR(
"aux_i2c invalid reply 0x%02x\n", reply[0]);
644 DRM_ERROR(
"too many retries, giving up\n");
654 DRM_DEBUG_KMS(
"i2c_init %s\n", name);
656 intel_dp->
algo.running =
false;
657 intel_dp->
algo.address = 0;
658 intel_dp->
algo.aux_ch = cdv_intel_dp_i2c_aux_ch;
664 intel_dp->
adapter.name[
sizeof(intel_dp->
adapter.name) - 1] =
'\0';
666 intel_dp->
adapter.dev.parent = &connector->
base.kdev;
669 cdv_intel_edp_panel_vdd_on(encoder);
672 cdv_intel_edp_panel_vdd_off(encoder);
703 int max_lane_count = cdv_intel_dp_max_lane_count(intel_encoder);
704 int max_clock = cdv_intel_dp_max_link_bw(intel_encoder) ==
DP_LINK_BW_2_7 ? 1 : 0;
706 int refclock = mode->
clock;
712 bpp = dev_priv->
edp.bpp;
715 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
716 for (clock = max_clock; clock >= 0; clock--) {
717 int link_avail = cdv_intel_dp_max_data_rate(cdv_intel_dp_link_clock(bws[clock]), lane_count);
719 if (cdv_intel_dp_link_required(refclock, bpp) <= link_avail) {
722 adjusted_mode->
clock = cdv_intel_dp_link_clock(intel_dp->
link_bw);
723 DRM_DEBUG_KMS(
"Display port link bw %02x lane "
724 "count %d clock %d\n",
726 adjusted_mode->
clock);
731 if (is_edp(intel_encoder)) {
734 intel_dp->
link_bw = bws[max_clock];
735 adjusted_mode->
clock = cdv_intel_dp_link_clock(intel_dp->
link_bw);
736 DRM_DEBUG_KMS(
"Force picking display port link bw %02x lane "
737 "count %d clock %d\n",
739 adjusted_mode->
clock);
764 value = m * (0x800000);
771 cdv_intel_dp_compute_m_n(
int bpp,
778 m_n->
gmch_m = (pixel_clock * bpp + 7) >> 3;
779 m_n->
gmch_n = link_clock * nlanes;
795 int lane_count = 4, bpp = 24;
806 if (encoder->
crtc != crtc)
814 }
else if (is_edp(intel_encoder)) {
816 bpp = dev_priv->
edp.bpp;
826 cdv_intel_dp_compute_m_n(bpp, lane_count,
887 if (intel_crtc->
pipe == 1)
891 DRM_DEBUG_KMS(
"DP expected reg is %x\n", intel_dp->
DP);
892 if (is_edp(intel_encoder)) {
894 cdv_intel_edp_panel_on(intel_encoder);
920 ret = cdv_intel_dp_aux_native_write_1(encoder,
DP_SET_POWER,
923 DRM_DEBUG_DRIVER(
"failed to write sink power state\n");
929 for (i = 0; i < 3; i++) {
930 ret = cdv_intel_dp_aux_native_write_1(encoder,
940 static void cdv_intel_dp_prepare(
struct drm_encoder *encoder)
943 int edp = is_edp(intel_encoder);
946 cdv_intel_edp_backlight_off(intel_encoder);
947 cdv_intel_edp_panel_off(intel_encoder);
948 cdv_intel_edp_panel_vdd_on(intel_encoder);
952 cdv_intel_dp_link_down(intel_encoder);
954 cdv_intel_edp_panel_vdd_off(intel_encoder);
957 static void cdv_intel_dp_commit(
struct drm_encoder *encoder)
960 int edp = is_edp(intel_encoder);
963 cdv_intel_edp_panel_on(intel_encoder);
964 cdv_intel_dp_start_link_train(intel_encoder);
965 cdv_intel_dp_complete_link_train(intel_encoder);
967 cdv_intel_edp_backlight_on(intel_encoder);
971 cdv_intel_dp_dpms(
struct drm_encoder *encoder,
int mode)
977 int edp = is_edp(intel_encoder);
981 cdv_intel_edp_backlight_off(intel_encoder);
982 cdv_intel_edp_panel_vdd_on(intel_encoder);
984 cdv_intel_dp_sink_dpms(intel_encoder, mode);
985 cdv_intel_dp_link_down(intel_encoder);
987 cdv_intel_edp_panel_vdd_off(intel_encoder);
988 cdv_intel_edp_panel_off(intel_encoder);
992 cdv_intel_edp_panel_on(intel_encoder);
993 cdv_intel_dp_sink_dpms(intel_encoder, mode);
995 cdv_intel_dp_start_link_train(intel_encoder);
996 cdv_intel_dp_complete_link_train(intel_encoder);
999 cdv_intel_edp_backlight_on(intel_encoder);
1009 uint8_t *recv,
int recv_bytes)
1017 for (i = 0; i < 3; i++) {
1018 ret = cdv_intel_dp_aux_native_read(encoder, address, recv,
1020 if (ret == recv_bytes)
1036 return cdv_intel_dp_aux_native_read_retry(encoder,
1054 int s = ((lane & 1) ?
1067 int s = ((lane & 1) ?
1077 static char *voltage_names[] = {
1078 "0.4V",
"0.6V",
"0.8V",
"1.2V"
1080 static char *pre_emph_names[] = {
1081 "0dB",
"3.5dB",
"6dB",
"9.5dB"
1083 static char *link_train_names[] = {
1084 "pattern 1",
"pattern 2",
"idle",
"off"
1088 #define CDV_DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_1200
1114 for (lane = 0; lane < intel_dp->
lane_count; lane++) {
1116 uint8_t this_p = cdv_intel_get_adjust_request_pre_emphasis(intel_dp->
link_status, lane);
1130 for (lane = 0; lane < 4; lane++)
1140 int s = (lane & 1) * 4;
1143 return (l >> s) & 0xf;
1148 cdv_intel_clock_recovery_ok(
uint8_t link_status[DP_LINK_STATUS_SIZE],
int lane_count)
1154 lane_status = cdv_intel_get_lane_status(
link_status, lane);
1162 #define CHANNEL_EQ_BITS (DP_LANE_CR_DONE|\
1163 DP_LANE_CHANNEL_EQ_DONE|\
1164 DP_LANE_SYMBOL_LOCKED)
1173 lane_align = cdv_intel_dp_link_status(intel_dp->
link_status,
1177 for (lane = 0; lane < intel_dp->
lane_count; lane++) {
1178 lane_status = cdv_intel_get_lane_status(intel_dp->
link_status, lane);
1198 ret = cdv_intel_dp_aux_native_write_1(encoder,
1203 DRM_DEBUG_KMS(
"Failure in setting link pattern %x\n",
1220 ret = cdv_intel_dp_aux_native_write(encoder,
1226 DRM_DEBUG_KMS(
"Failure in setting level %d, lane_cnt= %d\n",
1242 ddi_reg = &ddi_DP_train_table[0];
1244 ddi_reg = &ddi_DP_train_table[1];
1250 if (vswing + premph > 3)
1252 #ifdef CDV_FAST_LINK_TRAIN
1255 DRM_DEBUG_KMS(
"Test2\n");
1268 index = (vswing + premph) * 2;
1269 if (premph == 1 && vswing == 1) {
1292 index = 2 * premph + 1;
1306 bool clock_recovery =
false;
1321 DRM_DEBUG_KMS(
"Link config\n");
1330 clock_recovery =
false;
1332 DRM_DEBUG_KMS(
"Start train\n");
1338 DRM_DEBUG_KMS(
"DP Link Train Set %x, Link_config %x, %x\n",
1344 DRM_DEBUG_KMS(
"Failure in aux-transfer setting pattern 1\n");
1346 cdv_intel_dp_set_vswing_premph(encoder, intel_dp->
train_set[0]);
1352 if (!cdv_intel_dp_get_link_status(encoder))
1355 DRM_DEBUG_KMS(
"DP Link status %x, %x, %x, %x, %x, %x\n",
1360 DRM_DEBUG_KMS(
"PT1 train is done\n");
1361 clock_recovery =
true;
1382 cdv_intel_get_adjust_train(encoder);
1386 if (!clock_recovery) {
1387 DRM_DEBUG_KMS(
"failure in DP patter 1 training, train set %x\n", intel_dp->
train_set[0]);
1398 bool channel_eq =
false;
1399 int tries, cr_tries;
1408 DRM_DEBUG_KMS(
"\n");
1413 DRM_DEBUG_KMS(
"DP Link Train Set %x, Link_config %x, %x\n",
1419 if (!cdv_intel_dp_set_link_train(encoder, reg,
1421 DRM_DEBUG_KMS(
"Failure in aux-transfer setting pattern 2\n");
1426 DRM_ERROR(
"failed to train DP, aborting\n");
1427 cdv_intel_dp_link_down(encoder);
1431 cdv_intel_dp_set_vswing_premph(encoder, intel_dp->
train_set[0]);
1436 if (!cdv_intel_dp_get_link_status(encoder))
1439 DRM_DEBUG_KMS(
"DP Link status %x, %x, %x, %x, %x, %x\n",
1445 cdv_intel_dp_start_link_train(encoder);
1450 if (cdv_intel_channel_eq_ok(encoder)) {
1451 DRM_DEBUG_KMS(
"PT2 train is done\n");
1458 cdv_intel_dp_link_down(encoder);
1459 cdv_intel_dp_start_link_train(encoder);
1466 cdv_intel_get_adjust_train(encoder);
1475 cdv_intel_dp_aux_native_write_1(encoder,
1489 DRM_DEBUG_KMS(
"\n");
1511 if (cdv_intel_dp_aux_native_read(encoder, 0x000, intel_dp->
dpcd,
1518 DRM_DEBUG_KMS(
"DPCD: Rev=%x LN_Rate=%x LN_CNT=%x LN_DOWNSP=%x\n",
1519 intel_dp->
dpcd[0], intel_dp->
dpcd[1],
1520 intel_dp->
dpcd[2], intel_dp->
dpcd[3]);
1537 int edp = is_edp(encoder);
1542 cdv_intel_edp_panel_vdd_on(encoder);
1543 status = cdv_dp_detect(encoder);
1546 cdv_intel_edp_panel_vdd_off(encoder);
1560 cdv_intel_edp_panel_vdd_off(encoder);
1565 static int cdv_intel_dp_get_modes(
struct drm_connector *connector)
1567 struct psb_intel_encoder *intel_encoder = psb_intel_attached_encoder(connector);
1569 struct edid *edid =
NULL;
1571 int edp = is_edp(intel_encoder);
1581 if (is_edp(intel_encoder)) {
1585 cdv_intel_edp_panel_vdd_off(intel_encoder);
1626 bool has_audio =
false;
1627 int edp = is_edp(encoder);
1630 cdv_intel_edp_panel_vdd_on(encoder);
1638 cdv_intel_edp_panel_vdd_off(encoder);
1667 has_audio = cdv_intel_dp_detect_audio(connector);
1689 if (encoder->
base.crtc) {
1703 psb_intel_attached_encoder(connector);
1706 if (is_edp(psb_intel_encoder)) {
1719 static void cdv_intel_dp_encoder_destroy(
struct drm_encoder *encoder)
1725 .dpms = cdv_intel_dp_dpms,
1726 .mode_fixup = cdv_intel_dp_mode_fixup,
1727 .prepare = cdv_intel_dp_prepare,
1728 .mode_set = cdv_intel_dp_mode_set,
1729 .commit = cdv_intel_dp_commit,
1734 .detect = cdv_intel_dp_detect,
1736 .set_property = cdv_intel_dp_set_property,
1737 .destroy = cdv_intel_dp_destroy,
1741 .get_modes = cdv_intel_dp_get_modes,
1742 .mode_valid = cdv_intel_dp_mode_valid,
1747 .destroy = cdv_intel_dp_encoder_destroy,
1751 static void cdv_intel_dp_add_properties(
struct drm_connector *connector)
1758 static bool cdv_intel_dpc_is_edp(
struct drm_device *dev)
1782 static void cdv_disable_intel_clock_gating(
struct drm_device *dev)
1802 struct psb_intel_encoder *psb_intel_encoder;
1807 const char *name =
NULL;
1810 psb_intel_encoder = kzalloc(
sizeof(
struct psb_intel_encoder),
GFP_KERNEL);
1811 if (!psb_intel_encoder)
1813 psb_intel_connector = kzalloc(
sizeof(
struct psb_intel_connector),
GFP_KERNEL);
1814 if (!psb_intel_connector)
1820 if ((output_reg ==
DP_C) && cdv_intel_dpc_is_edp(dev))
1823 connector = &psb_intel_connector->
base;
1824 encoder = &psb_intel_encoder->
base;
1837 psb_intel_encoder->
dev_priv=intel_dp;
1838 intel_dp->
encoder = psb_intel_encoder;
1841 drm_encoder_helper_add(encoder, &cdv_intel_dp_helper_funcs);
1842 drm_connector_helper_add(connector, &cdv_intel_dp_connector_helper_funcs);
1851 switch (output_reg) {
1862 cdv_disable_intel_clock_gating(dev);
1864 cdv_intel_dp_i2c_init(psb_intel_connector, psb_intel_encoder, name);
1866 cdv_intel_dp_add_properties(connector);
1868 if (is_edp(psb_intel_encoder)) {
1871 u32 pp_on, pp_off, pp_div;
1904 DRM_DEBUG_KMS(
"cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
1914 DRM_DEBUG_KMS(
"panel power up delay %d, power down delay %d, power cycle delay %d\n",
1918 DRM_DEBUG_KMS(
"backlight on delay %d, off delay %d\n",
1922 cdv_intel_edp_panel_vdd_on(psb_intel_encoder);
1923 ret = cdv_intel_dp_aux_native_read(psb_intel_encoder,
DP_DPCD_REV,
1925 sizeof(intel_dp->
dpcd));
1926 cdv_intel_edp_panel_vdd_off(psb_intel_encoder);
1929 DRM_INFO(
"failed to retrieve link info, disabling eDP\n");
1930 cdv_intel_dp_encoder_destroy(encoder);
1931 cdv_intel_dp_destroy(connector);
1934 DRM_DEBUG_KMS(
"DPCD: Rev=%x LN_Rate=%x LN_CNT=%x LN_DOWNSP=%x\n",
1935 intel_dp->
dpcd[0], intel_dp->
dpcd[1],
1936 intel_dp->
dpcd[2], intel_dp->
dpcd[3]);
1947 kfree(psb_intel_connector);
1949 kfree(psb_intel_encoder);