[PATCH v10 05/12] drm: renesas: rz-du: Split the mode setting initialization

From: Tommaso Merciai

Date: Fri Nov 13 2026 - 12:51:08 EST


rzg2l_du_modeset_init() initializes the mode configuration of the DRM
device and creates the KMS objects of the DU instance. On RZ/G3E two
instances share a DRM device, so the mode configuration is initialized
once while each instance creates its own KMS objects.

In preparation for supporting RZ/G3E SoC, split them into
rzg2l_du_modeset_init_drm(), rzg2l_du_modeset_init_du() and
rzg2l_du_modeset_init_finish(), the latter completing the DRM device
once all instances have created their KMS objects, and call them from
the probe function.
As it is no longer tied to an instance, take from the DRM device and
the encoders what used to be taken from the instance.

No functional change intended.

Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@xxxxxxxxxxxxxx>
---
v9->v10:
- Dropped rzg2l_du_modeset_init(), call the helpers from probe.
- Updated commit body accordingly.

v8->v9:
- New patch.

drivers/gpu/drm/renesas/rz-du/rzg2l_du_drv.c | 32 ++++++++++------
drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.c | 39 +++++++++++++-------
drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.h | 4 +-
3 files changed, 49 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_drv.c b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_drv.c
index 57197356143f..d3cccbdf9012 100644
--- a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_drv.c
+++ b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_drv.c
@@ -223,17 +223,17 @@ static int rzg2l_du_probe(struct platform_device *pdev)
return ret;

/* DRM/KMS objects */
- ret = rzg2l_du_modeset_init(rcdu);
- if (ret < 0) {
- /*
- * Don't use dev_err_probe(), as it would overwrite the probe
- * deferral reason recorded in rzg2l_du_modeset_init().
- */
- if (ret != -EPROBE_DEFER)
- dev_err(&pdev->dev,
- "failed to initialize DRM/KMS (%d)\n", ret);
+ ret = rzg2l_du_modeset_init_drm(&rzgdrm->ddev);
+ if (ret < 0)
goto error;
- }
+
+ ret = rzg2l_du_modeset_init_du(rcdu);
+ if (ret < 0)
+ goto error;
+
+ ret = rzg2l_du_modeset_init_finish(&rzgdrm->ddev);
+ if (ret < 0)
+ goto error_fini;

/*
* Register the DRM device with the core and the connectors with
@@ -241,7 +241,7 @@ static int rzg2l_du_probe(struct platform_device *pdev)
*/
ret = drm_dev_register(&rzgdrm->ddev, 0);
if (ret)
- goto error;
+ goto error_fini;

drm_info(&rzgdrm->ddev, "Device %s probed\n", dev_name(&pdev->dev));

@@ -249,8 +249,16 @@ static int rzg2l_du_probe(struct platform_device *pdev)

return 0;

-error:
+error_fini:
drm_kms_helper_poll_fini(&rzgdrm->ddev);
+error:
+ /*
+ * Don't use dev_err_probe(), as it would overwrite the probe deferral
+ * reason recorded while initializing the DRM/KMS objects.
+ */
+ if (ret != -EPROBE_DEFER)
+ dev_err(&pdev->dev, "failed to initialize DRM/KMS (%d)\n", ret);
+
return ret;
}

diff --git a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.c b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.c
index 6eb1865f43b4..73cb3199f90f 100644
--- a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.c
+++ b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.c
@@ -400,11 +400,8 @@ static int rzg2l_du_vsps_init(struct rzg2l_du_device *rcdu)
return ret;
}

-int rzg2l_du_modeset_init(struct rzg2l_du_device *rcdu)
+int rzg2l_du_modeset_init_drm(struct drm_device *dev)
{
- struct drm_device *dev = rcdu->ddev;
- struct drm_encoder *encoder;
- unsigned int num_encoders;
int ret;

ret = drmm_mode_config_init(dev);
@@ -424,15 +421,14 @@ int rzg2l_du_modeset_init(struct rzg2l_du_device *rcdu)
dev->mode_config.max_width = 1920;
dev->mode_config.max_height = 1920;

- rcdu->num_crtcs = hweight8(rcdu->info->channels_mask);
+ return 0;
+}

- /*
- * Initialize vertical blanking interrupts handling. Start with vblank
- * disabled for all CRTCs.
- */
- ret = drm_vblank_init(dev, rcdu->num_crtcs);
- if (ret < 0)
- return ret;
+int rzg2l_du_modeset_init_du(struct rzg2l_du_device *rcdu)
+{
+ int ret;
+
+ rcdu->num_crtcs = hweight8(rcdu->info->channels_mask);

/* Initialize the compositors. */
ret = rzg2l_du_vsps_init(rcdu);
@@ -455,6 +451,23 @@ int rzg2l_du_modeset_init(struct rzg2l_du_device *rcdu)
return -EINVAL;
}

+ return 0;
+}
+
+int rzg2l_du_modeset_init_finish(struct drm_device *dev)
+{
+ struct drm_encoder *encoder;
+ unsigned int num_encoders;
+ int ret;
+
+ /*
+ * Initialize vertical blanking interrupts handling. Start with vblank
+ * disabled for all CRTCs.
+ */
+ ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
+ if (ret < 0)
+ return ret;
+
num_encoders = dev->mode_config.num_encoder;

/*
@@ -465,7 +478,7 @@ int rzg2l_du_modeset_init(struct rzg2l_du_device *rcdu)
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
struct rzg2l_du_encoder *renc = to_rzg2l_encoder(encoder);
const struct rzg2l_du_output_routing *route =
- &rcdu->info->routes[renc->output];
+ &renc->dev->info->routes[renc->output];

encoder->possible_crtcs = route->possible_outputs;
encoder->possible_clones = (1 << num_encoders) - 1;
diff --git a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.h b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.h
index e2c599f115c6..98627a6de4c4 100644
--- a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.h
+++ b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.h
@@ -29,7 +29,9 @@ struct rzg2l_du_format_info {

const struct rzg2l_du_format_info *rzg2l_du_format_info(u32 fourcc);

-int rzg2l_du_modeset_init(struct rzg2l_du_device *rcdu);
+int rzg2l_du_modeset_init_drm(struct drm_device *dev);
+int rzg2l_du_modeset_init_du(struct rzg2l_du_device *rcdu);
+int rzg2l_du_modeset_init_finish(struct drm_device *dev);

int rzg2l_du_dumb_create(struct drm_file *file, struct drm_device *dev,
struct drm_mode_create_dumb *args);
--
2.54.0