drm/vc4: dsi: Embed DRM structures into the private structure
authorMaxime Ripard <maxime@cerno.tech>
Wed, 11 May 2022 09:03:23 +0000 (11:03 +0200)
committerMaxime Ripard <maxime@cerno.tech>
Wed, 7 Sep 2022 08:53:03 +0000 (10:53 +0200)
The VC4 DSI driver private structure contains only a pointer to the
encoder it implements. This makes the overall structure somewhat
inconsistent with the rest of the driver, and complicates its
initialisation without any apparent gain.

Let's embed the drm_encoder structure (through the vc4_encoder one) into
struct vc4_dsi to fix both issues.

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
drivers/gpu/drm/vc4/vc4_dsi.c

index 59c4af2..69b4cf7 100644 (file)
@@ -549,10 +549,11 @@ struct vc4_dsi_variant {
 
 /* General DSI hardware state. */
 struct vc4_dsi {
+       struct vc4_encoder encoder;
+       struct mipi_dsi_host dsi_host;
+
        struct platform_device *pdev;
 
-       struct mipi_dsi_host dsi_host;
-       struct drm_encoder *encoder;
        struct drm_bridge *out_bridge;
        struct drm_bridge bridge;
 
@@ -600,6 +601,12 @@ struct vc4_dsi {
 
 #define host_to_dsi(host) container_of(host, struct vc4_dsi, dsi_host)
 
+static inline struct vc4_dsi *
+to_vc4_dsi(struct drm_encoder *encoder)
+{
+       return container_of(encoder, struct vc4_dsi, encoder.base);
+}
+
 static inline void
 dsi_dma_workaround_write(struct vc4_dsi *dsi, u32 offset, u32 val)
 {
@@ -644,18 +651,6 @@ dsi_dma_workaround_write(struct vc4_dsi *dsi, u32 offset, u32 val)
        DSI_WRITE(dsi->variant->port ? DSI1_##offset : DSI0_##offset, val)
 #define DSI_PORT_BIT(bit) (dsi->variant->port ? DSI1_##bit : DSI0_##bit)
 
-/* VC4 DSI encoder KMS struct */
-struct vc4_dsi_encoder {
-       struct vc4_encoder base;
-       struct vc4_dsi *dsi;
-};
-
-static inline struct vc4_dsi_encoder *
-to_vc4_dsi_encoder(struct drm_encoder *encoder)
-{
-       return container_of(encoder, struct vc4_dsi_encoder, base.base);
-}
-
 static inline struct vc4_dsi *
 bridge_to_vc4_dsi(struct drm_bridge *bridge)
 {
@@ -1610,8 +1605,8 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
        struct platform_device *pdev = to_platform_device(dev);
        struct drm_device *drm = dev_get_drvdata(master);
        struct vc4_dsi *dsi = dev_get_drvdata(dev);
-       struct vc4_dsi_encoder *vc4_dsi_encoder;
        const struct of_device_id *match;
+       struct drm_encoder *encoder = &dsi->encoder.base;
        int ret;
 
        match = of_match_device(vc4_dsi_dt_match, dev);
@@ -1619,16 +1614,8 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
                return -ENODEV;
 
        dsi->variant = match->data;
-
-       vc4_dsi_encoder = devm_kzalloc(dev, sizeof(*vc4_dsi_encoder),
-                                      GFP_KERNEL);
-       if (!vc4_dsi_encoder)
-               return -ENOMEM;
-
-       vc4_dsi_encoder->base.type = dsi->variant->port ?
-                       VC4_ENCODER_TYPE_DSI1 : VC4_ENCODER_TYPE_DSI0;
-       vc4_dsi_encoder->dsi = dsi;
-       dsi->encoder = &vc4_dsi_encoder->base.base;
+       dsi->encoder.type = dsi->variant->port ?
+               VC4_ENCODER_TYPE_DSI1 : VC4_ENCODER_TYPE_DSI0;
 
        dsi->regs = vc4_ioremap_regs(pdev, 0);
        if (IS_ERR(dsi->regs))
@@ -1747,9 +1734,9 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
        if (ret)
                return ret;
 
-       drm_simple_encoder_init(drm, dsi->encoder, DRM_MODE_ENCODER_DSI);
+       drm_simple_encoder_init(drm, encoder, DRM_MODE_ENCODER_DSI);
 
-       ret = drm_bridge_attach(dsi->encoder, &dsi->bridge, NULL, 0);
+       ret = drm_bridge_attach(encoder, &dsi->bridge, NULL, 0);
        if (ret) {
                dev_err(dev, "bridge attach failed: %d\n", ret);
                return ret;
@@ -1766,10 +1753,11 @@ static void vc4_dsi_unbind(struct device *dev, struct device *master,
                           void *data)
 {
        struct vc4_dsi *dsi = dev_get_drvdata(dev);
+       struct drm_encoder *encoder = &dsi->encoder.base;
 
        pm_runtime_disable(dev);
 
-       drm_encoder_cleanup(dsi->encoder);
+       drm_encoder_cleanup(encoder);
 }
 
 static const struct component_ops vc4_dsi_ops = {