Skip to content

Commit 0d85a73

Browse files
6by9popcornmix
authored andcommitted
drm: vc4: Probe DPI/DSI timings from the firmware
For DPI and DSI displays query the firmware as to the configuration and add it as the only mode for DRM. In theory we can add plumbing for setting the DPI/DSI mode from KMS, but this is not being added at present as the support frameworks aren't present in the firmware. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
1 parent de9dca7 commit 0d85a73

2 files changed

Lines changed: 49 additions & 16 deletions

File tree

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

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ static inline struct vc4_crtc *to_vc4_crtc(struct drm_crtc *crtc)
248248
struct vc4_fkms_encoder {
249249
struct drm_encoder base;
250250
bool hdmi_monitor;
251-
bool rgb_range_selectable;
252251
};
253252

254253
static inline struct vc4_fkms_encoder *
@@ -283,7 +282,7 @@ static u32 vc4_get_display_type(u32 display_number)
283282
/* The firmware display (DispmanX) IDs map to specific types in
284283
* a fixed manner.
285284
*/
286-
DRM_MODE_ENCODER_DSI, /* MAIN_LCD */
285+
DRM_MODE_ENCODER_DSI, /* MAIN_LCD - DSI or DPI */
287286
DRM_MODE_ENCODER_DSI, /* AUX_LCD */
288287
DRM_MODE_ENCODER_TMDS, /* HDMI0 */
289288
DRM_MODE_ENCODER_TVDAC, /* VEC */
@@ -365,7 +364,6 @@ static void vc4_plane_atomic_update(struct drm_plane *plane,
365364
vc4_get_vc_image_fmt(drm_fmt->format);
366365
struct vc4_fkms_plane *vc4_plane = to_vc4_fkms_plane(plane);
367366
struct mailbox_set_plane *mb = &vc4_plane->mb;
368-
struct vc4_crtc *vc4_crtc = to_vc4_crtc(state->crtc);
369367
int num_planes = fb->format->num_planes;
370368
struct drm_display_mode *mode = &state->crtc->mode;
371369
unsigned int rotation = SUPPORTED_ROTATIONS;
@@ -987,19 +985,16 @@ static int vc4_fkms_connector_get_modes(struct drm_connector *connector)
987985

988986
vc4_encoder->hdmi_monitor = drm_detect_hdmi_monitor(edid);
989987

990-
if (edid && edid->input & DRM_EDID_INPUT_DIGITAL) {
991-
vc4_encoder->rgb_range_selectable =
992-
drm_rgb_quant_range_selectable(edid);
993-
}
994-
995988
drm_connector_update_edid_property(connector, edid);
996989
ret = drm_add_edid_modes(connector, edid);
997990
kfree(edid);
998991

999992
return ret;
1000993
}
1001994

1002-
/* FIXME: Read LCD mode from the firmware. This is the DSI panel resolution. */
995+
/* This is the DSI panel resolution. Use this as a default should the firmware
996+
* not respond to our request for the timings.
997+
*/
1003998
static const struct drm_display_mode lcd_mode = {
1004999
DRM_MODE("800x480", DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
10051000
25979400 / 1000,
@@ -1010,15 +1005,52 @@ static const struct drm_display_mode lcd_mode = {
10101005

10111006
static int vc4_fkms_lcd_connector_get_modes(struct drm_connector *connector)
10121007
{
1013-
//struct vc4_fkms_connector *fkms_connector =
1014-
// to_vc4_fkms_connector(connector);
1015-
//struct drm_encoder *encoder = fkms_connector->encoder;
1016-
//struct vc4_fkms_encoder *vc4_encoder = to_vc4_fkms_encoder(encoder);
1008+
struct vc4_fkms_connector *fkms_connector =
1009+
to_vc4_fkms_connector(connector);
1010+
struct vc4_dev *vc4 = fkms_connector->vc4_dev;
10171011
struct drm_display_mode *mode;
1018-
//int ret = 0;
1012+
struct mailbox_set_mode mb = {
1013+
.tag1 = { RPI_FIRMWARE_GET_DISPLAY_TIMING,
1014+
sizeof(struct set_timings), 0},
1015+
.timings = { .display = fkms_connector->display_number },
1016+
};
1017+
struct drm_display_mode fw_mode;
1018+
int ret = 0;
1019+
1020+
ret = rpi_firmware_property_list(vc4->firmware, &mb, sizeof(mb));
1021+
if (!ret) {
1022+
/* Equivalent to DRM_MODE macro. */
1023+
memset(&fw_mode, 0, sizeof(fw_mode));
1024+
strncpy(fw_mode.name, "LCD_MODE", sizeof(fw_mode.name));
1025+
fw_mode.status = 0;
1026+
fw_mode.type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
1027+
fw_mode.clock = mb.timings.clock;
1028+
fw_mode.hdisplay = mb.timings.hdisplay;
1029+
fw_mode.hsync_start = mb.timings.hsync_start;
1030+
fw_mode.hsync_end = mb.timings.hsync_end;
1031+
fw_mode.htotal = mb.timings.htotal;
1032+
fw_mode.hskew = 0;
1033+
fw_mode.vdisplay = mb.timings.vdisplay;
1034+
fw_mode.vsync_start = mb.timings.vsync_start;
1035+
fw_mode.vsync_end = mb.timings.vsync_end;
1036+
fw_mode.vtotal = mb.timings.vtotal;
1037+
fw_mode.vscan = mb.timings.vscan;
1038+
if (mb.timings.flags & TIMINGS_FLAGS_H_SYNC_POS)
1039+
fw_mode.flags |= DRM_MODE_FLAG_PHSYNC;
1040+
else
1041+
fw_mode.flags |= DRM_MODE_FLAG_NHSYNC;
1042+
if (mb.timings.flags & TIMINGS_FLAGS_V_SYNC_POS)
1043+
fw_mode.flags |= DRM_MODE_FLAG_PVSYNC;
1044+
else
1045+
fw_mode.flags |= DRM_MODE_FLAG_NVSYNC;
1046+
1047+
mode = drm_mode_duplicate(connector->dev,
1048+
&fw_mode);
1049+
} else {
1050+
mode = drm_mode_duplicate(connector->dev,
1051+
&lcd_mode);
1052+
}
10191053

1020-
mode = drm_mode_duplicate(connector->dev,
1021-
&lcd_mode);
10221054
if (!mode) {
10231055
DRM_ERROR("Failed to create a new display mode\n");
10241056
return -ENOMEM;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ enum rpi_firmware_property_tag {
150150
RPI_FIRMWARE_VCHIQ_INIT = 0x00048010,
151151

152152
RPI_FIRMWARE_SET_PLANE = 0x00048015,
153+
RPI_FIRMWARE_GET_DISPLAY_TIMING = 0x00040017,
153154
RPI_FIRMWARE_SET_TIMING = 0x00048017,
154155

155156
RPI_FIRMWARE_GET_COMMAND_LINE = 0x00050001,

0 commit comments

Comments
 (0)