Skip to content

Commit 8c9cd61

Browse files
committed
drm: apple: Set swap timestamps to sane values for Adaptive Sync
Setting these timestamps to a dummy value worked fine for enabling a fixed 120 Hz mode on the MacBook Pros, however doing so causes Adaptive Sync displays to simply switch between full and minimum refresh rates. Setting these timestamps based on the swap pacing seems to fix this, and makes the display's refresh rate match the incoming swap rate. Note that the names and values are best-guess only. These seem to work fine for driving VRR displays, but may still be incorrect. Signed-off-by: James Calligeros <[email protected]>
1 parent 0233553 commit 8c9cd61

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

drivers/gpu/drm/apple/iomfb_template.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,15 @@ int DCP_FW_NAME(iomfb_modeset)(struct apple_dcp *dcp,
12991299
return 0;
13001300
}
13011301

1302+
/*
1303+
* DCP timestamps are expressed in system timer ticks. Approximate
1304+
* this by converting from ktime nanoseconds to 24 MHz ticks.
1305+
*/
1306+
static u64 ns_to_mach(u64 ns)
1307+
{
1308+
return ns * 3 / 125;
1309+
}
1310+
13021311
void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, struct drm_atomic_state *state)
13031312
{
13041313
struct drm_plane *plane;
@@ -1415,12 +1424,14 @@ void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, stru
14151424

14161425
if (has_surface && dcp->use_timestamps) {
14171426
/*
1418-
* Fake timstamps to get 120hz refresh rate. It looks
1419-
* like the actual value does not matter, as long as it is non zero.
1427+
* TODO: ascertain with certainty what these timestamps
1428+
* are. They are something to do with presentation timing,
1429+
* but that is all we know for sure. These values seem to
1430+
* work well with VRR.
14201431
*/
1421-
req->swap.ts1 = 120;
1422-
req->swap.ts2 = 120;
1423-
req->swap.ts3 = 120;
1432+
req->swap.unk_pres_ts1 = ns_to_mach(ktime_get_ns());
1433+
req->swap.unk_pres_ts2 = ns_to_mach(ktime_to_ns(dcp->swap_start));
1434+
req->swap.unk_pres_ts3 = req->swap.unk_pres_ts1;
14241435
}
14251436

14261437
/* These fields should be set together */

drivers/gpu/drm/apple/iomfb_template.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
#include "version_utils.h"
1919

2020
struct DCP_FW_NAME(dcp_swap) {
21-
u64 ts1;
22-
u64 ts2;
21+
u64 unk_pres_ts1;
22+
u64 unk_pres_ts2;
2323

2424
u64 unk_10;
2525
u64 unk_18;
2626
u64 ts64_unk;
2727
u64 unk_28;
28-
u64 ts3;
28+
u64 unk_pres_ts3;
2929
u64 unk_38;
3030

3131
u64 flags1;

0 commit comments

Comments
 (0)