Replace simple-display helpers with regular atomic helpers. Store the
pipeline elements in struct st7735r_device and initialize them as part
of probing the device. Use mipi-dbi's existing helpers and initializer
macros where possible.

Effectively open-codes the modesetting code in the initializer helpers
of mipi-dbi and simple-display. St7735r requires a custom helper for
CRTC enablement, and non-freeing cleanup of the pipeline.

Signed-off-by: Thomas Zimmermann <[email protected]>
---
 drivers/gpu/drm/sitronix/st7735r.c | 115 ++++++++++++++++++++++++++---
 1 file changed, 106 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/sitronix/st7735r.c 
b/drivers/gpu/drm/sitronix/st7735r.c
index e70c46df0299..9003ed82e5b4 100644
--- a/drivers/gpu/drm/sitronix/st7735r.c
+++ b/drivers/gpu/drm/sitronix/st7735r.c
@@ -55,6 +55,11 @@ struct st7735r_cfg {
 struct st7735r_device {
        struct mipi_dbi_dev dbidev;     /* Must be first for .release() */
        const struct st7735r_cfg *cfg;
+
+       struct drm_plane plane;
+       struct drm_crtc crtc;
+       struct drm_encoder encoder;
+       struct drm_connector connector;
 };
 
 static struct st7735r_device *to_st7735r_device(struct drm_device *drm)
@@ -62,17 +67,34 @@ static struct st7735r_device *to_st7735r_device(struct 
drm_device *drm)
        return container_of(drm_to_mipi_dbi_dev(drm), struct st7735r_device, 
dbidev);
 }
 
-static void st7735r_pipe_enable(struct drm_simple_display_pipe *pipe,
-                               struct drm_crtc_state *crtc_state,
-                               struct drm_plane_state *plane_state)
+static const u32 st7735r_plane_formats[] = {
+       DRM_MIPI_DBI_PLANE_FORMATS,
+};
+
+static const u64 st7735r_plane_format_modifiers[] = {
+       DRM_MIPI_DBI_PLANE_FORMAT_MODIFIERS,
+};
+
+static const struct drm_plane_helper_funcs st7735r_plane_helper_funcs = {
+       DRM_MIPI_DBI_PLANE_HELPER_FUNCS,
+};
+
+static const struct drm_plane_funcs st7735r_plane_funcs = {
+       DRM_MIPI_DBI_PLANE_FUNCS,
+       .destroy = drm_plane_cleanup,
+};
+
+static void st7735r_crtc_helper_atomic_enable(struct drm_crtc *crtc,
+                                             struct drm_atomic_state *state)
 {
-       struct st7735r_device *st7735r = to_st7735r_device(pipe->crtc.dev);
+       struct drm_device *drm = crtc->dev;
+       struct st7735r_device *st7735r = to_st7735r_device(drm);
        struct mipi_dbi_dev *dbidev = &st7735r->dbidev;
        struct mipi_dbi *dbi = &dbidev->dbi;
        int ret, idx;
        u8 addr_mode;
 
-       if (!drm_dev_enter(pipe->crtc.dev, &idx))
+       if (!drm_dev_enter(drm, &idx))
                return;
 
        DRM_DEBUG_KMS("\n");
@@ -138,8 +160,35 @@ static void st7735r_pipe_enable(struct 
drm_simple_display_pipe *pipe,
        drm_dev_exit(idx);
 }
 
-static const struct drm_simple_display_pipe_funcs st7735r_pipe_funcs = {
-       DRM_MIPI_DBI_SIMPLE_DISPLAY_PIPE_FUNCS(st7735r_pipe_enable),
+static const struct drm_crtc_helper_funcs st7735r_crtc_helper_funcs = {
+       DRM_MIPI_DBI_CRTC_HELPER_FUNCS,
+       .atomic_enable = st7735r_crtc_helper_atomic_enable,
+};
+
+static const struct drm_crtc_funcs st7735r_crtc_funcs = {
+       DRM_MIPI_DBI_CRTC_FUNCS,
+       .destroy = drm_crtc_cleanup,
+};
+
+static const struct drm_encoder_funcs st7735r_encoder_funcs = {
+       .destroy = drm_encoder_cleanup,
+};
+
+static const struct drm_connector_helper_funcs st7735r_connector_helper_funcs 
= {
+       DRM_MIPI_DBI_CONNECTOR_HELPER_FUNCS,
+};
+
+static const struct drm_connector_funcs st7735r_connector_funcs = {
+       DRM_MIPI_DBI_CONNECTOR_FUNCS,
+       .destroy = drm_connector_cleanup,
+};
+
+static const struct drm_mode_config_helper_funcs 
st7735r_mode_config_helper_funcs = {
+       DRM_MIPI_DBI_MODE_CONFIG_HELPER_FUNCS,
+};
+
+static const struct drm_mode_config_funcs st7735r_mode_config_funcs = {
+       DRM_MIPI_DBI_MODE_CONFIG_FUNCS,
 };
 
 static const struct st7735r_cfg jd_t18003_t01_cfg = {
@@ -192,6 +241,10 @@ static int st7735r_probe(struct spi_device *spi)
        struct drm_device *drm;
        struct mipi_dbi *dbi;
        struct gpio_desc *dc;
+       struct drm_plane *plane;
+       struct drm_crtc *crtc;
+       struct drm_encoder *encoder;
+       struct drm_connector *connector;
        u32 rotation = 0;
        int ret;
 
@@ -233,8 +286,52 @@ static int st7735r_probe(struct spi_device *spi)
        dbidev->left_offset = cfg->left_offset;
        dbidev->top_offset = cfg->top_offset;
 
-       ret = mipi_dbi_dev_init(dbidev, &st7735r_pipe_funcs, &cfg->mode,
-                               rotation);
+       ret = drm_mipi_dbi_dev_init(dbidev, &cfg->mode, 
st7735r_plane_formats[0], rotation, 0);
+       if (ret)
+               return ret;
+
+       ret = drmm_mode_config_init(drm);
+       if (ret)
+               return ret;
+
+       drm->mode_config.min_width = dbidev->mode.hdisplay;
+       drm->mode_config.max_width = dbidev->mode.hdisplay;
+       drm->mode_config.min_height = dbidev->mode.vdisplay;
+       drm->mode_config.max_height = dbidev->mode.vdisplay;
+       drm->mode_config.funcs = &st7735r_mode_config_funcs;
+       drm->mode_config.preferred_depth = 16;
+       drm->mode_config.helper_private = &st7735r_mode_config_helper_funcs;
+
+       plane = &st7735r->plane;
+       ret = drm_universal_plane_init(drm, plane, 0, &st7735r_plane_funcs,
+                                      st7735r_plane_formats, 
ARRAY_SIZE(st7735r_plane_formats),
+                                      st7735r_plane_format_modifiers,
+                                      DRM_PLANE_TYPE_PRIMARY, NULL);
+       if (ret)
+               return ret;
+       drm_plane_helper_add(plane, &st7735r_plane_helper_funcs);
+       drm_plane_enable_fb_damage_clips(plane);
+
+       crtc = &st7735r->crtc;
+       ret = drm_crtc_init_with_planes(drm, crtc, plane, NULL, 
&st7735r_crtc_funcs, NULL);
+       if (ret)
+               return ret;
+       drm_crtc_helper_add(crtc, &st7735r_crtc_helper_funcs);
+
+       encoder = &st7735r->encoder;
+       ret = drm_encoder_init(drm, encoder, &st7735r_encoder_funcs, 
DRM_MODE_ENCODER_NONE, NULL);
+       if (ret)
+               return ret;
+       encoder->possible_crtcs = drm_crtc_mask(crtc);
+
+       connector = &st7735r->connector;
+       ret = drm_connector_init(drm, connector, &st7735r_connector_funcs,
+                                DRM_MODE_CONNECTOR_SPI);
+       if (ret)
+               return ret;
+       drm_connector_helper_add(&dbidev->connector, 
&st7735r_connector_helper_funcs);
+
+       ret = drm_connector_attach_encoder(connector, encoder);
        if (ret)
                return ret;
 
-- 
2.52.0

Reply via email to