Skip to content

Commit 21c213b

Browse files
6by9popcornmix
authored andcommitted
drm/vc4: fkms to query the VPU for HDMI clock limits
The VPU has configured clocks for 4k (or not) via config.txt, and will limit the choice of video modes based on that. Make fkms query it for these limits too to avoid selecting modes that can not be handled by the current clock setup. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
1 parent 9cedea6 commit 21c213b

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎drivers/gpu/drm/vc4/vc4_drv.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ struct vc4_dev {
8181
struct vc4_dsi *dsi1;
8282
struct vc4_vec *vec;
8383
struct vc4_txp *txp;
84+
struct vc4_fkms *fkms;
8485

8586
struct vc4_hang_state *hang_state;
8687

‎drivers/gpu/drm/vc4/vc4_firmware_kms.c‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
#include "vc_image_types.h"
3333
#include <soc/bcm2835/raspberrypi-firmware.h>
3434

35+
struct get_display_cfg {
36+
u32 max_pixel_clock[2]; //Max pixel clock for each display
37+
};
38+
39+
struct vc4_fkms {
40+
struct get_display_cfg cfg;
41+
};
42+
3543
#define PLANES_PER_CRTC 3
3644

3745
struct set_plane {
@@ -795,13 +803,34 @@ static void vc4_crtc_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_st
795803
static enum drm_mode_status
796804
vc4_crtc_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode *mode)
797805
{
806+
struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
807+
struct drm_device *dev = crtc->dev;
808+
struct vc4_dev *vc4 = to_vc4_dev(dev);
809+
struct vc4_fkms *fkms = vc4->fkms;
810+
798811
/* Do not allow doublescan modes from user space */
799812
if (mode->flags & DRM_MODE_FLAG_DBLSCAN) {
800813
DRM_DEBUG_KMS("[CRTC:%d] Doublescan mode rejected.\n",
801814
crtc->base.id);
802815
return MODE_NO_DBLESCAN;
803816
}
804817

818+
/* Limit the pixel clock based on the HDMI clock limits from the
819+
* firmware
820+
*/
821+
switch (vc4_crtc->display_number) {
822+
case 2: /* HDMI0 */
823+
if (fkms->cfg.max_pixel_clock[0] &&
824+
mode->clock > fkms->cfg.max_pixel_clock[0])
825+
return MODE_CLOCK_HIGH;
826+
break;
827+
case 7: /* HDMI1 */
828+
if (fkms->cfg.max_pixel_clock[1] &&
829+
mode->clock > fkms->cfg.max_pixel_clock[1])
830+
return MODE_CLOCK_HIGH;
831+
break;
832+
}
833+
805834
/* Limit the pixel clock until we can get dynamic HDMI 2.0 scrambling
806835
* working.
807836
*/
@@ -1295,11 +1324,16 @@ static int vc4_fkms_bind(struct device *dev, struct device *master, void *data)
12951324
struct device_node *firmware_node;
12961325
struct vc4_crtc **crtc_list;
12971326
u32 num_displays, display_num;
1327+
struct vc4_fkms *fkms;
12981328
int ret;
12991329
u32 display_id;
13001330

13011331
vc4->firmware_kms = true;
13021332

1333+
fkms = devm_kzalloc(dev, sizeof(*fkms), GFP_KERNEL);
1334+
if (!fkms)
1335+
return -ENOMEM;
1336+
13031337
/* firmware kms doesn't have precise a scanoutpos implementation, so
13041338
* we can't do the precise vblank timestamp mode.
13051339
*/
@@ -1328,6 +1362,18 @@ static int vc4_fkms_bind(struct device *dev, struct device *master, void *data)
13281362
ret = 0;
13291363
}
13301364

1365+
ret = rpi_firmware_property(vc4->firmware,
1366+
RPI_FIRMWARE_GET_DISPLAY_CFG,
1367+
&fkms->cfg, sizeof(fkms->cfg));
1368+
1369+
if (ret)
1370+
return -EINVAL;
1371+
/* The firmware works in Hz. This will be compared against kHz, so div
1372+
* 1000 now rather than multiple times later.
1373+
*/
1374+
fkms->cfg.max_pixel_clock[0] /= 1000;
1375+
fkms->cfg.max_pixel_clock[1] /= 1000;
1376+
13311377
/* Allocate a list, with space for a NULL on the end */
13321378
crtc_list = devm_kzalloc(dev, sizeof(crtc_list) * (num_displays + 1),
13331379
GFP_KERNEL);
@@ -1369,6 +1415,8 @@ static int vc4_fkms_bind(struct device *dev, struct device *master, void *data)
13691415
DRM_WARN("No displays found. Consider forcing hotplug if HDMI is attached\n");
13701416
}
13711417

1418+
vc4->fkms = fkms;
1419+
13721420
platform_set_drvdata(pdev, crtc_list);
13731421

13741422
return 0;

‎include/soc/bcm2835/raspberrypi-firmware.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ enum rpi_firmware_property_tag {
152152
RPI_FIRMWARE_SET_PLANE = 0x00048015,
153153
RPI_FIRMWARE_GET_DISPLAY_TIMING = 0x00040017,
154154
RPI_FIRMWARE_SET_TIMING = 0x00048017,
155+
RPI_FIRMWARE_GET_DISPLAY_CFG = 0x00040018,
155156

156157
RPI_FIRMWARE_GET_COMMAND_LINE = 0x00050001,
157158
RPI_FIRMWARE_GET_DMA_CHANNELS = 0x00060001,

0 commit comments

Comments
 (0)