1 From 23e6a2c2d33050255c76a499ea080e5279d6edfc Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Thu, 30 May 2019 13:56:15 +0100
4 Subject: [PATCH] drm/vc4: fkms to query the VPU for HDMI clock limits
6 The VPU has configured clocks for 4k (or not) via config.txt,
7 and will limit the choice of video modes based on that.
8 Make fkms query it for these limits too to avoid selecting modes
9 that can not be handled by the current clock setup.
11 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
13 drivers/gpu/drm/vc4/vc4_drv.h | 1 +
14 drivers/gpu/drm/vc4/vc4_firmware_kms.c | 48 ++++++++++++++++++++++
15 include/soc/bcm2835/raspberrypi-firmware.h | 1 +
16 3 files changed, 50 insertions(+)
18 --- a/drivers/gpu/drm/vc4/vc4_drv.h
19 +++ b/drivers/gpu/drm/vc4/vc4_drv.h
20 @@ -77,6 +77,7 @@ struct vc4_dev {
24 + struct vc4_fkms *fkms;
26 struct vc4_hang_state *hang_state;
28 --- a/drivers/gpu/drm/vc4/vc4_firmware_kms.c
29 +++ b/drivers/gpu/drm/vc4/vc4_firmware_kms.c
31 #include "vc_image_types.h"
32 #include <soc/bcm2835/raspberrypi-firmware.h>
34 +struct get_display_cfg {
35 + u32 max_pixel_clock[2]; //Max pixel clock for each display
39 + struct get_display_cfg cfg;
42 #define PLANES_PER_CRTC 3
45 @@ -794,6 +802,11 @@ static void vc4_crtc_enable(struct drm_c
46 static enum drm_mode_status
47 vc4_crtc_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode *mode)
49 + struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
50 + struct drm_device *dev = crtc->dev;
51 + struct vc4_dev *vc4 = to_vc4_dev(dev);
52 + struct vc4_fkms *fkms = vc4->fkms;
54 /* Do not allow doublescan modes from user space */
55 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
56 DRM_DEBUG_KMS("[CRTC:%d] Doublescan mode rejected.\n",
57 @@ -801,6 +814,22 @@ vc4_crtc_mode_valid(struct drm_crtc *crt
58 return MODE_NO_DBLESCAN;
61 + /* Limit the pixel clock based on the HDMI clock limits from the
64 + switch (vc4_crtc->display_number) {
66 + if (fkms->cfg.max_pixel_clock[0] &&
67 + mode->clock > fkms->cfg.max_pixel_clock[0])
68 + return MODE_CLOCK_HIGH;
71 + if (fkms->cfg.max_pixel_clock[1] &&
72 + mode->clock > fkms->cfg.max_pixel_clock[1])
73 + return MODE_CLOCK_HIGH;
77 /* Limit the pixel clock until we can get dynamic HDMI 2.0 scrambling
80 @@ -1301,11 +1330,16 @@ static int vc4_fkms_bind(struct device *
81 struct device_node *firmware_node;
82 struct vc4_crtc **crtc_list;
83 u32 num_displays, display_num;
84 + struct vc4_fkms *fkms;
88 vc4->firmware_kms = true;
90 + fkms = devm_kzalloc(dev, sizeof(*fkms), GFP_KERNEL);
94 /* firmware kms doesn't have precise a scanoutpos implementation, so
95 * we can't do the precise vblank timestamp mode.
97 @@ -1334,6 +1368,18 @@ static int vc4_fkms_bind(struct device *
101 + ret = rpi_firmware_property(vc4->firmware,
102 + RPI_FIRMWARE_GET_DISPLAY_CFG,
103 + &fkms->cfg, sizeof(fkms->cfg));
107 + /* The firmware works in Hz. This will be compared against kHz, so div
108 + * 1000 now rather than multiple times later.
110 + fkms->cfg.max_pixel_clock[0] /= 1000;
111 + fkms->cfg.max_pixel_clock[1] /= 1000;
113 /* Allocate a list, with space for a NULL on the end */
114 crtc_list = devm_kzalloc(dev, sizeof(crtc_list) * (num_displays + 1),
116 @@ -1375,6 +1421,8 @@ static int vc4_fkms_bind(struct device *
117 DRM_WARN("No displays found. Consider forcing hotplug if HDMI is attached\n");
122 platform_set_drvdata(pdev, crtc_list);
125 --- a/include/soc/bcm2835/raspberrypi-firmware.h
126 +++ b/include/soc/bcm2835/raspberrypi-firmware.h
127 @@ -153,6 +153,7 @@ enum rpi_firmware_property_tag {
128 RPI_FIRMWARE_SET_PLANE = 0x00048015,
129 RPI_FIRMWARE_GET_DISPLAY_TIMING = 0x00040017,
130 RPI_FIRMWARE_SET_TIMING = 0x00048017,
131 + RPI_FIRMWARE_GET_DISPLAY_CFG = 0x00040018,
133 RPI_FIRMWARE_GET_COMMAND_LINE = 0x00050001,
134 RPI_FIRMWARE_GET_DMA_CHANNELS = 0x00060001,