[PATCH v2 18/21] drm/imx: parallel-display: use drm managed resources
Philipp Zabel
p.zabel at pengutronix.de
Fri Sep 11 13:38:52 UTC 2020
Move device tree parsing into probe(). Use drmm_kzalloc() to align
encoder memory lifetime with the drm device, and use
drmm_add_action_or_reset() to make sure drm_encoder_cleanup() is
called before the memory is freed.
Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
Acked-by: Daniel Vetter <daniel.vetter at ffwll.ch>
---
Changes since v1:
- Split some changes into previous patches, rebased.
---
drivers/gpu/drm/imx/parallel-display.c | 76 ++++++++++++++++----------
1 file changed, 47 insertions(+), 29 deletions(-)
diff --git a/drivers/gpu/drm/imx/parallel-display.c b/drivers/gpu/drm/imx/parallel-display.c
index 42b44dbf45f5..2b2160387cbf 100644
--- a/drivers/gpu/drm/imx/parallel-display.c
+++ b/drivers/gpu/drm/imx/parallel-display.c
@@ -15,6 +15,7 @@
#include <drm/drm_atomic_helper.h>
#include <drm/drm_bridge.h>
#include <drm/drm_fb_helper.h>
+#include <drm/drm_managed.h>
#include <drm/drm_of.h>
#include <drm/drm_panel.h>
#include <drm/drm_probe_helper.h>
@@ -22,10 +23,14 @@
#include "imx-drm.h"
-struct imx_parallel_display {
+struct imx_parallel_display_encoder {
struct drm_connector connector;
struct drm_encoder encoder;
struct drm_bridge bridge;
+ struct imx_parallel_display *pd;
+};
+
+struct imx_parallel_display {
struct device *dev;
void *edid;
u32 bus_format;
@@ -37,12 +42,12 @@ struct imx_parallel_display {
static inline struct imx_parallel_display *con_to_imxpd(struct drm_connector *c)
{
- return container_of(c, struct imx_parallel_display, connector);
+ return container_of(c, struct imx_parallel_display_encoder, connector)->pd;
}
static inline struct imx_parallel_display *bridge_to_imxpd(struct drm_bridge *b)
{
- return container_of(b, struct imx_parallel_display, bridge);
+ return container_of(b, struct imx_parallel_display_encoder, bridge)->pd;
}
static int imx_pd_connector_get_modes(struct drm_connector *connector)
@@ -253,17 +258,39 @@ static const struct drm_bridge_funcs imx_pd_bridge_funcs = {
.atomic_get_output_bus_fmts = imx_pd_bridge_atomic_get_output_bus_fmts,
};
-static int imx_pd_register(struct drm_device *drm,
- struct imx_parallel_display *imxpd)
+static void imx_pd_encoder_cleanup(struct drm_device *drm, void *ptr)
+{
+ struct drm_encoder *encoder = ptr;
+
+ drm_encoder_cleanup(encoder);
+}
+
+static int imx_pd_bind(struct device *dev, struct device *master, void *data)
{
- struct drm_connector *connector = &imxpd->connector;
- struct drm_encoder *encoder = &imxpd->encoder;
- struct drm_bridge *bridge = &imxpd->bridge;
+ struct drm_device *drm = data;
+ struct imx_parallel_display *imxpd = dev_get_drvdata(dev);
+ struct imx_parallel_display_encoder *imxpd_encoder;
+ struct drm_connector *connector;
+ struct drm_encoder *encoder;
+ struct drm_bridge *bridge;
int ret;
- memset(connector, 0, sizeof(*connector));
- memset(encoder, 0, sizeof(*encoder));
- memset(bridge, 0, sizeof(*bridge));
+ imxpd_encoder = drmm_kzalloc(drm, sizeof(*imxpd_encoder), GFP_KERNEL);
+ if (!imxpd_encoder)
+ return -ENOMEM;
+
+ imxpd_encoder->pd = imxpd;
+ connector = &imxpd_encoder->connector;
+ encoder = &imxpd_encoder->encoder;
+ bridge = &imxpd_encoder->bridge;
+
+ ret = drm_simple_encoder_init(drm, encoder, DRM_MODE_ENCODER_NONE);
+ if (ret)
+ return ret;
+
+ ret = drmm_add_action_or_reset(drm, imx_pd_encoder_cleanup, encoder);
+ if (ret)
+ return ret;
ret = imx_drm_encoder_parse_of(drm, encoder, imxpd->dev->of_node);
if (ret)
@@ -276,18 +303,9 @@ static int imx_pd_register(struct drm_device *drm,
*/
connector->dpms = DRM_MODE_DPMS_OFF;
- drm_simple_encoder_init(drm, encoder, DRM_MODE_ENCODER_NONE);
-
bridge->funcs = &imx_pd_bridge_funcs;
drm_bridge_attach(encoder, bridge, NULL, 0);
- if (!imxpd->next_bridge) {
- drm_connector_helper_add(connector,
- &imx_pd_connector_helper_funcs);
- drm_connector_init(drm, connector, &imx_pd_connector_funcs,
- DRM_MODE_CONNECTOR_DPI);
- }
-
if (imxpd->next_bridge) {
ret = drm_bridge_attach(encoder, imxpd->next_bridge, bridge, 0);
if (ret < 0) {
@@ -296,20 +314,17 @@ static int imx_pd_register(struct drm_device *drm,
return ret;
}
} else {
+ drm_connector_helper_add(connector,
+ &imx_pd_connector_helper_funcs);
+ drm_connector_init(drm, connector, &imx_pd_connector_funcs,
+ DRM_MODE_CONNECTOR_DPI);
+
drm_connector_attach_encoder(connector, encoder);
}
return 0;
}
-static int imx_pd_bind(struct device *dev, struct device *master, void *data)
-{
- struct drm_device *drm = data;
- struct imx_parallel_display *imxpd = dev_get_drvdata(dev);
-
- return imx_pd_register(drm, imxpd);
-}
-
static const struct component_ops imx_pd_ops = {
.bind = imx_pd_bind,
};
--
2.20.1
More information about the dri-devel
mailing list