1 From f9f480b04f1dc280bd4411477f5ee7336361367b Mon Sep 17 00:00:00 2001
2 From: Dom Cobley <popcornmix@gmail.com>
3 Date: Tue, 24 Oct 2023 16:20:42 +0100
4 Subject: [PATCH] drm/vc4: crtc: Support odd horizontal timings on BCM2712
6 BCM2711 runs pixelvalve at two pixels per clock cycle which results
7 in an unfortunate limitation that odd horizontal timings are not
8 possible. This is apparent on the standard DMT mode of 1366x768@60
9 which cannot be driven with correct timing.
11 BCM2712 defaults to the same behaviour, but has a mode to support
12 odd timings. While internally it still runs at two pixels per clock,
13 setting the PV_VCONTROL_ODD_TIMING bit makes it appear externally
14 to behave as it is one pixel per clock.
16 Switching to this mode fixes 1366x768@60 mode, and other custom
17 resultions with odd horizontal timings.
19 Signed-off-by: Dom Cobley <popcornmix@gmail.com>
21 drivers/gpu/drm/vc4/vc4_crtc.c | 12 ++++--------
22 drivers/gpu/drm/vc4/vc4_hdmi.c | 4 ++--
23 drivers/gpu/drm/vc4/vc4_regs.h | 1 +
24 3 files changed, 7 insertions(+), 10 deletions(-)
26 --- a/drivers/gpu/drm/vc4/vc4_crtc.c
27 +++ b/drivers/gpu/drm/vc4/vc4_crtc.c
28 @@ -398,12 +398,6 @@ static void vc4_crtc_config_pv(struct dr
30 vc4_crtc_pixelvalve_reset(crtc);
33 - * NOTE: The BCM2712 has a H_OTE (Horizontal Odd Timing Enable)
34 - * bit that, when set, will allow to specify the timings in
35 - * pixels instead of cycles, thus allowing to specify odd
39 VC4_SET_FIELD((mode->htotal - mode->hsync_end) * pixel_rep / ppc,
41 @@ -448,6 +442,7 @@ static void vc4_crtc_config_pv(struct dr
43 CRTC_WRITE(PV_V_CONTROL,
44 PV_VCONTROL_CONTINUOUS |
45 + (vc4->gen >= VC4_GEN_6 ? PV_VCONTROL_ODD_TIMING : 0) |
46 (is_dsi ? PV_VCONTROL_DSI : 0) |
47 PV_VCONTROL_INTERLACE |
49 @@ -459,6 +454,7 @@ static void vc4_crtc_config_pv(struct dr
51 CRTC_WRITE(PV_V_CONTROL,
52 PV_VCONTROL_CONTINUOUS |
53 + (vc4->gen >= VC4_GEN_6 ? PV_VCONTROL_ODD_TIMING : 0) |
54 (is_dsi ? PV_VCONTROL_DSI : 0));
55 CRTC_WRITE(PV_VSYNCD_EVEN, 0);
57 @@ -1334,7 +1330,7 @@ const struct vc4_pv_data bcm2712_pv0_dat
61 - .pixels_per_clock = 2,
62 + .pixels_per_clock = 1,
64 [0] = VC4_ENCODER_TYPE_HDMI0,
66 @@ -1347,7 +1343,7 @@ const struct vc4_pv_data bcm2712_pv1_dat
70 - .pixels_per_clock = 2,
71 + .pixels_per_clock = 1,
73 [0] = VC4_ENCODER_TYPE_HDMI1,
75 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
76 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
77 @@ -3958,7 +3958,7 @@ static const struct vc4_hdmi_variant bcm
81 - .unsupported_odd_h_timings = true,
82 + .unsupported_odd_h_timings = false,
83 .external_irq_controller = true,
85 .init_resources = vc5_hdmi_init_resources,
86 @@ -3985,7 +3985,7 @@ static const struct vc4_hdmi_variant bcm
90 - .unsupported_odd_h_timings = true,
91 + .unsupported_odd_h_timings = false,
92 .external_irq_controller = true,
94 .init_resources = vc5_hdmi_init_resources,
95 --- a/drivers/gpu/drm/vc4/vc4_regs.h
96 +++ b/drivers/gpu/drm/vc4/vc4_regs.h
98 # define PV_CONTROL_EN BIT(0)
100 #define PV_V_CONTROL 0x04
101 +# define PV_VCONTROL_ODD_TIMING BIT(29)
102 # define PV_VCONTROL_ODD_DELAY_MASK VC4_MASK(22, 6)
103 # define PV_VCONTROL_ODD_DELAY_SHIFT 6
104 # define PV_VCONTROL_ODD_FIRST BIT(5)