36 #define DP_LINK_CONFIGURATION_SIZE 9
37 #define DP_LINK_STATUS_SIZE 6
38 #define DP_DPCD_SIZE 8
40 static char *voltage_names[] = {
41 "0.4V",
"0.6V",
"0.8V",
"1.2V"
43 static char *pre_emph_names[] = {
44 "0dB",
"3.5dB",
"6dB",
"9.5dB"
55 u8 *recv,
int recv_size,
65 memset(&args, 0,
sizeof(args));
67 base = (
unsigned char *)(rdev->
mode_info.atom_context->scratch + 1);
69 memcpy(base, send, send_bytes);
71 args.
v1.lpAuxRequest = 0 + 4;
72 args.
v1.lpDataOut = 16 + 4;
73 args.
v1.ucDataOutLen = 0;
74 args.
v1.ucChannelID = chan->
rec.i2c_id;
75 args.
v1.ucDelay = delay / 10;
81 *ack = args.
v1.ucReplyStatus;
84 if (args.
v1.ucReplyStatus == 1) {
85 DRM_DEBUG_KMS(
"dp_aux_ch timeout\n");
90 if (args.
v1.ucReplyStatus == 2) {
91 DRM_DEBUG_KMS(
"dp_aux_ch flags not zero\n");
96 if (args.
v1.ucReplyStatus == 3) {
97 DRM_DEBUG_KMS(
"dp_aux_ch error\n");
101 recv_bytes = args.
v1.ucDataOutLen;
102 if (recv_bytes > recv_size)
103 recv_bytes = recv_size;
105 if (recv && recv_size)
106 memcpy(recv, base + 16, recv_bytes);
117 int msg_bytes = send_bytes + 4;
125 msg[1] = address >> 8;
127 msg[3] = (msg_bytes << 4) | (send_bytes - 1);
128 memcpy(&msg[4], send, send_bytes);
130 for (retry = 0; retry < 4; retry++) {
131 ret = radeon_process_aux_ch(dig_connector->
dp_i2c_bus,
132 msg, msg_bytes,
NULL, 0, delay, &ack);
148 static int radeon_dp_aux_native_read(
struct radeon_connector *radeon_connector,
149 u16 address,
u8 *recv,
int recv_bytes,
u8 delay)
159 msg[1] = address >> 8;
161 msg[3] = (msg_bytes << 4) | (recv_bytes - 1);
163 for (retry = 0; retry < 4; retry++) {
164 ret = radeon_process_aux_ch(dig_connector->
dp_i2c_bus,
165 msg, msg_bytes, recv, recv_bytes, delay, &ack);
183 static void radeon_write_dpcd_reg(
struct radeon_connector *radeon_connector,
186 radeon_dp_aux_native_write(radeon_connector, reg, &val, 1, 0);
189 static u8 radeon_read_dpcd_reg(
struct radeon_connector *radeon_connector,
194 radeon_dp_aux_native_read(radeon_connector, reg, &val, 1, 0);
200 u8 write_byte,
u8 *read_byte)
223 msg[1] = address >> 8;
228 msg[3] = msg_bytes << 4;
233 msg[3] = msg_bytes << 4;
241 for (retry = 0; retry < 4; retry++) {
242 ret = radeon_process_aux_ch(auxch,
243 msg, msg_bytes, reply, reply_bytes, 0, &ack);
247 DRM_DEBUG_KMS(
"aux_ch failed %d\n", ret);
251 switch (ack & AUX_NATIVE_REPLY_MASK) {
258 DRM_DEBUG_KMS(
"aux_ch native nack\n");
261 DRM_DEBUG_KMS(
"aux_ch native defer\n");
265 DRM_ERROR(
"aux_ch invalid native reply 0x%02x\n", ack);
271 if (mode == MODE_I2C_READ)
272 *read_byte = reply[0];
275 DRM_DEBUG_KMS(
"aux_i2c nack\n");
278 DRM_DEBUG_KMS(
"aux_i2c defer\n");
282 DRM_ERROR(
"aux_i2c invalid reply 0x%02x\n", ack);
287 DRM_DEBUG_KMS(
"aux i2c too many retries, giving up\n");
302 int s = (lane & 1) * 4;
304 return (l >> s) & 0xf;
307 static bool dp_clock_recovery_ok(
u8 link_status[DP_LINK_STATUS_SIZE],
313 for (lane = 0; lane < lane_count; lane++) {
314 lane_status = dp_get_lane_status(
link_status, lane);
321 static bool dp_channel_eq_ok(
u8 link_status[DP_LINK_STATUS_SIZE],
332 for (lane = 0; lane < lane_count; lane++) {
333 lane_status = dp_get_lane_status(
link_status, lane);
340 static u8 dp_get_adjust_request_voltage(
u8 link_status[DP_LINK_STATUS_SIZE],
345 int s = ((lane & 1) ?
353 static u8 dp_get_adjust_request_pre_emphasis(
u8 link_status[DP_LINK_STATUS_SIZE],
357 int s = ((lane & 1) ?
365 #define DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_1200
366 #define DP_PRE_EMPHASIS_MAX DP_TRAIN_PRE_EMPHASIS_9_5
368 static void dp_get_adjust_train(
u8 link_status[DP_LINK_STATUS_SIZE],
376 for (lane = 0; lane < lane_count; lane++) {
377 u8 this_v = dp_get_adjust_request_voltage(
link_status, lane);
378 u8 this_p = dp_get_adjust_request_pre_emphasis(
link_status, lane);
380 DRM_DEBUG_KMS(
"requested signal parameters: lane %d voltage %s pre_emph %s\n",
397 DRM_DEBUG_KMS(
"using signal parameters: voltage %s pre_emph %s\n",
401 for (lane = 0; lane < 4; lane++)
402 train_set[lane] = v | p;
407 static int convert_bpc_to_bpp(
int bpc)
416 static int dp_get_max_dp_pix_clock(
int link_rate,
420 return (link_rate * lane_num * 8) /
bpp;
436 static u8 dp_get_max_lane_number(
u8 dpcd[DP_DPCD_SIZE])
441 static u8 dp_get_dp_link_rate_coded(
int link_rate)
461 u8 dpcd[DP_DPCD_SIZE],
465 int max_link_rate = dp_get_max_link_rate(dpcd);
466 int max_lane_num = dp_get_max_lane_number(dpcd);
468 int max_dp_pix_clock;
470 for (lane_num = 1; lane_num < max_lane_num; lane_num <<= 1) {
471 max_dp_pix_clock = dp_get_max_dp_pix_clock(max_link_rate, lane_num, bpp);
472 if (pix_clock <= max_dp_pix_clock)
479 static int radeon_dp_get_dp_link_clock(
struct drm_connector *connector,
480 u8 dpcd[DP_DPCD_SIZE],
484 int lane_num, max_pix_clock;
490 lane_num = radeon_dp_get_dp_lane_number(connector, dpcd, pix_clock);
491 max_pix_clock = dp_get_max_dp_pix_clock(162000, lane_num, bpp);
492 if (pix_clock <= max_pix_clock)
494 max_pix_clock = dp_get_max_dp_pix_clock(270000, lane_num, bpp);
495 if (pix_clock <= max_pix_clock)
498 max_pix_clock = dp_get_max_dp_pix_clock(540000, lane_num, bpp);
499 if (pix_clock <= max_pix_clock)
503 return dp_get_max_link_rate(dpcd);
508 u8 ucconfig,
u8 lane_num)
513 memset(&args, 0,
sizeof(args));
534 static void radeon_dp_probe_oui(
struct radeon_connector *radeon_connector)
542 if (radeon_dp_aux_native_read(radeon_connector,
DP_SINK_OUI, buf, 3, 0))
543 DRM_DEBUG_KMS(
"Sink OUI: %02hx%02hx%02hx\n",
544 buf[0], buf[1], buf[2]);
546 if (radeon_dp_aux_native_read(radeon_connector,
DP_BRANCH_OUI, buf, 3, 0))
547 DRM_DEBUG_KMS(
"Branch OUI: %02hx%02hx%02hx\n",
548 buf[0], buf[1], buf[2]);
557 ret = radeon_dp_aux_native_read(radeon_connector,
DP_DPCD_REV, msg, 8, 0);
560 DRM_DEBUG_KMS(
"DPCD: ");
561 for (i = 0; i < 8; i++)
562 DRM_DEBUG_KMS(
"%02x ", msg[i]);
565 radeon_dp_probe_oui(radeon_connector);
569 dig_connector->
dpcd[0] = 0;
614 dig_connector = radeon_connector->
con_priv;
619 radeon_dp_get_dp_link_clock(connector, dig_connector->
dpcd, mode->
clock);
621 radeon_dp_get_dp_lane_number(connector, dig_connector->
dpcd, mode->
clock);
634 dig_connector = radeon_connector->
con_priv;
637 radeon_dp_get_dp_link_clock(connector, dig_connector->
dpcd, mode->
clock);
639 if ((dp_clock == 540000) &&
646 static bool radeon_dp_get_link_status(
struct radeon_connector *radeon_connector,
656 DRM_DEBUG_KMS(
"link status %*ph\n", 6,
link_status);
665 if (!radeon_dp_get_link_status(radeon_connector, link_status))
743 if (dp_info->
dpcd[0] >= 0x11)
748 if (dp_info->
dpcd[3] & 0x1)
768 tmp = dp_get_dp_link_rate_coded(dp_info->
dp_clock);
815 radeon_dp_update_vs_emph(dp_info);
820 clock_recovery =
false;
830 DRM_ERROR(
"displayport link status failed\n");
835 clock_recovery =
true;
844 DRM_ERROR(
"clock recovery reached max voltage\n");
850 if (dp_info->
tries == 5) {
851 DRM_ERROR(
"clock recovery tried 5 times\n");
862 radeon_dp_update_vs_emph(dp_info);
864 if (!clock_recovery) {
865 DRM_ERROR(
"clock recovery failed\n");
868 DRM_DEBUG_KMS(
"clock recovery at voltage %d pre-emphasis %d\n",
895 DRM_ERROR(
"displayport link status failed\n");
905 if (dp_info->
tries > 5) {
906 DRM_ERROR(
"channel eq failed: 5 tries\n");
913 radeon_dp_update_vs_emph(dp_info);
918 DRM_ERROR(
"channel eq failed\n");
921 DRM_DEBUG_KMS(
"channel eq at voltage %d pre-emphasis %d\n",
936 struct radeon_connector *radeon_connector;
949 dig_connector = radeon_connector->
con_priv;
992 if (radeon_dp_link_train_init(&dp_info))
994 if (radeon_dp_link_train_cr(&dp_info))
996 if (radeon_dp_link_train_ce(&dp_info))
999 if (radeon_dp_link_train_finish(&dp_info))