[PATCH v2 02/21] drm: Add a dummy bridge object to drm_encoder
Boris Brezillon
boris.brezillon at collabora.com
Mon Aug 26 15:26:30 UTC 2019
This in one step in the right direction towards drm_encoder/drm_bridge
unification. By doing that we also allow encoder drivers to implement
the ->pre_enable() and ->post_disable() hooks without adding new
methods to drm_encoder_helper_funcs.
Signed-off-by: Boris Brezillon <boris.brezillon at collabora.com>
---
Changes in v2:
* New patch
---
drivers/gpu/drm/drm_atomic_helper.c | 17 +++++++++--------
drivers/gpu/drm/drm_bridge.c | 4 ++--
drivers/gpu/drm/drm_crtc_helper.c | 20 ++++++++++----------
drivers/gpu/drm/drm_encoder.c | 23 ++++++++++++++---------
drivers/gpu/drm/drm_probe_helper.c | 2 +-
drivers/gpu/drm/exynos/exynos_drm_dsi.c | 2 +-
drivers/gpu/drm/msm/edp/edp.c | 2 +-
drivers/gpu/drm/msm/edp/edp_bridge.c | 2 +-
drivers/gpu/drm/msm/hdmi/hdmi.c | 2 +-
drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 4 ++--
drivers/gpu/drm/vc4/vc4_dsi.c | 2 +-
include/drm/drm_encoder.h | 16 ++++++++++++++--
12 files changed, 57 insertions(+), 39 deletions(-)
diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 4706439fb490..3fe60076da05 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -445,8 +445,9 @@ mode_fixup(struct drm_atomic_state *state)
encoder = new_conn_state->best_encoder;
funcs = encoder->helper_private;
- ret = drm_bridge_mode_fixup(encoder->bridge, &new_crtc_state->mode,
- &new_crtc_state->adjusted_mode);
+ ret = drm_bridge_mode_fixup(&encoder->bridge,
+ &new_crtc_state->mode,
+ &new_crtc_state->adjusted_mode);
if (!ret) {
DRM_DEBUG_ATOMIC("Bridge fixup failed\n");
return -EINVAL;
@@ -511,7 +512,7 @@ static enum drm_mode_status mode_valid_path(struct drm_connector *connector,
return ret;
}
- ret = drm_bridge_mode_valid(encoder->bridge, mode);
+ ret = drm_bridge_mode_valid(&encoder->bridge, mode);
if (ret != MODE_OK) {
DRM_DEBUG_ATOMIC("[BRIDGE] mode_valid() failed\n");
return ret;
@@ -1030,7 +1031,7 @@ disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)
* Each encoder has at most one connector (since we always steal
* it away), so we won't call disable hooks twice.
*/
- drm_atomic_bridge_disable(encoder->bridge, old_state);
+ drm_atomic_bridge_disable(&encoder->bridge, old_state);
/* Right function depends upon target state. */
if (funcs) {
@@ -1044,7 +1045,7 @@ disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)
funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
}
- drm_atomic_bridge_post_disable(encoder->bridge, old_state);
+ drm_atomic_bridge_post_disable(&encoder->bridge, old_state);
}
for_each_oldnew_crtc_in_state(old_state, crtc, old_crtc_state, new_crtc_state, i) {
@@ -1225,7 +1226,7 @@ crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state)
funcs->mode_set(encoder, mode, adjusted_mode);
}
- drm_bridge_mode_set(encoder->bridge, mode, adjusted_mode);
+ drm_bridge_mode_set(&encoder->bridge, mode, adjusted_mode);
}
}
@@ -1342,7 +1343,7 @@ void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,
* Each encoder has at most one connector (since we always steal
* it away), so we won't call enable hooks twice.
*/
- drm_atomic_bridge_pre_enable(encoder->bridge, old_state);
+ drm_atomic_bridge_pre_enable(&encoder->bridge, old_state);
if (funcs) {
if (funcs->atomic_enable)
@@ -1353,7 +1354,7 @@ void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,
funcs->commit(encoder);
}
- drm_atomic_bridge_enable(encoder->bridge, old_state);
+ drm_atomic_bridge_enable(&encoder->bridge, old_state);
}
drm_atomic_helper_commit_writebacks(dev, old_state);
diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index cba537c99e43..c5d6b17f6790 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -139,8 +139,8 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
if (previous)
previous->next = bridge;
- else
- encoder->bridge = bridge;
+ else if (bridge != &encoder->bridge)
+ encoder->bridge.next = bridge;
return 0;
}
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index fa3694836c22..c80e33a84605 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -160,14 +160,14 @@ drm_encoder_disable(struct drm_encoder *encoder)
if (!encoder_funcs)
return;
- drm_bridge_disable(encoder->bridge);
+ drm_bridge_disable(&encoder->bridge);
if (encoder_funcs->disable)
(*encoder_funcs->disable)(encoder);
else if (encoder_funcs->dpms)
(*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF);
- drm_bridge_post_disable(encoder->bridge);
+ drm_bridge_post_disable(&encoder->bridge);
}
static void __drm_helper_disable_unused_functions(struct drm_device *dev)
@@ -327,8 +327,8 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
if (!encoder_funcs)
continue;
- ret = drm_bridge_mode_fixup(encoder->bridge,
- mode, adjusted_mode);
+ ret = drm_bridge_mode_fixup(&encoder->bridge, mode,
+ adjusted_mode);
if (!ret) {
DRM_DEBUG_KMS("Bridge fixup failed\n");
goto done;
@@ -365,13 +365,13 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
if (!encoder_funcs)
continue;
- drm_bridge_disable(encoder->bridge);
+ drm_bridge_disable(&encoder->bridge);
/* Disable the encoders as the first thing we do. */
if (encoder_funcs->prepare)
encoder_funcs->prepare(encoder);
- drm_bridge_post_disable(encoder->bridge);
+ drm_bridge_post_disable(&encoder->bridge);
}
drm_crtc_prepare_encoders(dev);
@@ -399,7 +399,7 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
if (encoder_funcs->mode_set)
encoder_funcs->mode_set(encoder, mode, adjusted_mode);
- drm_bridge_mode_set(encoder->bridge, mode, adjusted_mode);
+ drm_bridge_mode_set(&encoder->bridge, mode, adjusted_mode);
}
/* Now enable the clocks, plane, pipe, and connectors that we set up. */
@@ -414,12 +414,12 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
if (!encoder_funcs)
continue;
- drm_bridge_pre_enable(encoder->bridge);
+ drm_bridge_pre_enable(&encoder->bridge);
if (encoder_funcs->commit)
encoder_funcs->commit(encoder);
- drm_bridge_enable(encoder->bridge);
+ drm_bridge_enable(&encoder->bridge);
}
/* Calculate and store various constants which
@@ -818,7 +818,7 @@ static int drm_helper_choose_encoder_dpms(struct drm_encoder *encoder)
/* Helper which handles bridge ordering around encoder dpms */
static void drm_helper_encoder_dpms(struct drm_encoder *encoder, int mode)
{
- struct drm_bridge *bridge = encoder->bridge;
+ struct drm_bridge *bridge = &encoder->bridge;
const struct drm_encoder_helper_funcs *encoder_funcs;
encoder_funcs = encoder->helper_private;
diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
index 80d88a55302e..686053bf41b9 100644
--- a/drivers/gpu/drm/drm_encoder.c
+++ b/drivers/gpu/drm/drm_encoder.c
@@ -91,6 +91,9 @@ void drm_encoder_unregister_all(struct drm_device *dev)
}
}
+static const struct drm_bridge_funcs dummy_bridge_funcs = {
+};
+
/**
* drm_encoder_init - Init a preallocated encoder
* @dev: drm device
@@ -140,6 +143,13 @@ int drm_encoder_init(struct drm_device *dev,
goto out_put;
}
+ if (!encoder->bridge.funcs)
+ encoder->bridge.funcs = &dummy_bridge_funcs;
+
+ ret = drm_bridge_attach(encoder, &encoder->bridge, NULL);
+ if (ret)
+ goto out_put;
+
list_add_tail(&encoder->head, &dev->mode_config.encoder_list);
encoder->index = dev->mode_config.num_encoder++;
@@ -160,21 +170,16 @@ EXPORT_SYMBOL(drm_encoder_init);
void drm_encoder_cleanup(struct drm_encoder *encoder)
{
struct drm_device *dev = encoder->dev;
+ struct drm_bridge *bridge, *next;
/* Note that the encoder_list is considered to be static; should we
* remove the drm_encoder at runtime we would have to decrement all
* the indices on the drm_encoder after us in the encoder_list.
*/
- if (encoder->bridge) {
- struct drm_bridge *bridge = encoder->bridge;
- struct drm_bridge *next;
-
- while (bridge) {
- next = bridge->next;
- drm_bridge_detach(bridge);
- bridge = next;
- }
+ for (bridge = &encoder->bridge; bridge; bridge = next) {
+ next = bridge->next;
+ drm_bridge_detach(bridge);
}
drm_mode_object_unregister(dev, &encoder->base);
diff --git a/drivers/gpu/drm/drm_probe_helper.c b/drivers/gpu/drm/drm_probe_helper.c
index 351cbc40f0f8..e4af2f9fa372 100644
--- a/drivers/gpu/drm/drm_probe_helper.c
+++ b/drivers/gpu/drm/drm_probe_helper.c
@@ -113,7 +113,7 @@ drm_mode_validate_pipeline(struct drm_display_mode *mode,
continue;
}
- ret = drm_bridge_mode_valid(encoder->bridge, mode);
+ ret = drm_bridge_mode_valid(&encoder->bridge, mode);
if (ret != MODE_OK) {
/* There is also no point in continuing for crtc check
* here. */
diff --git a/drivers/gpu/drm/exynos/exynos_drm_dsi.c b/drivers/gpu/drm/exynos/exynos_drm_dsi.c
index 72726f2c7a9f..8e655ae1fb0c 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_dsi.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_dsi.c
@@ -1522,7 +1522,7 @@ static int exynos_dsi_host_attach(struct mipi_dsi_host *host,
if (out_bridge) {
drm_bridge_attach(encoder, out_bridge, NULL);
dsi->out_bridge = out_bridge;
- encoder->bridge = NULL;
+ encoder->bridge.next = NULL;
} else {
int ret = exynos_dsi_create_connector(encoder);
diff --git a/drivers/gpu/drm/msm/edp/edp.c b/drivers/gpu/drm/msm/edp/edp.c
index 0f312ac5b624..b54559a79d36 100644
--- a/drivers/gpu/drm/msm/edp/edp.c
+++ b/drivers/gpu/drm/msm/edp/edp.c
@@ -178,7 +178,7 @@ int msm_edp_modeset_init(struct msm_edp *edp, struct drm_device *dev,
goto fail;
}
- encoder->bridge = edp->bridge;
+ encoder->bridge.next = edp->bridge;
priv->bridges[priv->num_bridges++] = edp->bridge;
priv->connectors[priv->num_connectors++] = edp->connector;
diff --git a/drivers/gpu/drm/msm/edp/edp_bridge.c b/drivers/gpu/drm/msm/edp/edp_bridge.c
index 2950bba4aca9..446acca110e9 100644
--- a/drivers/gpu/drm/msm/edp/edp_bridge.c
+++ b/drivers/gpu/drm/msm/edp/edp_bridge.c
@@ -56,7 +56,7 @@ static void edp_bridge_mode_set(struct drm_bridge *bridge,
list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
if ((connector->encoder != NULL) &&
- (connector->encoder->bridge == bridge)) {
+ (connector->encoder->bridge.next == bridge)) {
msm_edp_ctrl_timing_cfg(edp->ctrl,
adjusted_mode, &connector->display_info);
break;
diff --git a/drivers/gpu/drm/msm/hdmi/hdmi.c b/drivers/gpu/drm/msm/hdmi/hdmi.c
index 0e4217be3f00..9d94a88dd8d6 100644
--- a/drivers/gpu/drm/msm/hdmi/hdmi.c
+++ b/drivers/gpu/drm/msm/hdmi/hdmi.c
@@ -327,7 +327,7 @@ int msm_hdmi_modeset_init(struct hdmi *hdmi,
goto fail;
}
- encoder->bridge = hdmi->bridge;
+ encoder->bridge.next = hdmi->bridge;
priv->bridges[priv->num_bridges++] = hdmi->bridge;
priv->connectors[priv->num_connectors++] = hdmi->connector;
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
index 2da46e3dc4ae..1bd748202946 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
@@ -681,7 +681,7 @@ static void rcar_du_crtc_atomic_enable(struct drm_crtc *crtc,
const struct drm_display_mode *mode =
&crtc->state->adjusted_mode;
- rcar_lvds_clk_enable(encoder->base.bridge,
+ rcar_lvds_clk_enable(encoder->base.bridge.next,
mode->clock * 1000);
}
@@ -707,7 +707,7 @@ static void rcar_du_crtc_atomic_disable(struct drm_crtc *crtc,
* Disable the LVDS clock output, see
* rcar_du_crtc_atomic_enable().
*/
- rcar_lvds_clk_disable(encoder->base.bridge);
+ rcar_lvds_clk_disable(encoder->base.bridge.next);
}
spin_lock_irq(&crtc->dev->event_lock);
diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
index 3f63943e5472..e64b66b1efcd 100644
--- a/drivers/gpu/drm/vc4/vc4_dsi.c
+++ b/drivers/gpu/drm/vc4/vc4_dsi.c
@@ -1610,7 +1610,7 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
* from our driver, since we need to sequence them within the
* encoder's enable/disable paths.
*/
- dsi->encoder->bridge = NULL;
+ dsi->encoder->bridge.next = NULL;
if (dsi->port == 0)
vc4_debugfs_add_regset32(drm, "dsi0_regs", &dsi->regset);
diff --git a/include/drm/drm_encoder.h b/include/drm/drm_encoder.h
index 70cfca03d812..30d347c37402 100644
--- a/include/drm/drm_encoder.h
+++ b/include/drm/drm_encoder.h
@@ -25,6 +25,7 @@
#include <linux/list.h>
#include <linux/ctype.h>
+#include <drm/drm_bridge.h>
#include <drm/drm_crtc.h>
#include <drm/drm_mode.h>
#include <drm/drm_mode_object.h>
@@ -89,7 +90,6 @@ struct drm_encoder_funcs {
* @head: list management
* @base: base KMS object
* @name: human readable name, can be overwritten by the driver
- * @bridge: bridge associated to the encoder
* @funcs: control functions
* @helper_private: mid-layer private data
*
@@ -172,13 +172,25 @@ struct drm_encoder {
* &drm_connector_state.crtc.
*/
struct drm_crtc *crtc;
- struct drm_bridge *bridge;
+
+ /**
+ * @bridge: Bridge representing our encoder. Other bridges might be
+ * linked to this dummy bridge element to form an encoder chain.
+ */
+ struct drm_bridge bridge;
+
const struct drm_encoder_funcs *funcs;
const struct drm_encoder_helper_funcs *helper_private;
};
#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
+static inline struct drm_encoder *
+bridge_to_encoder(struct drm_bridge *bridge)
+{
+ return container_of(bridge, struct drm_encoder, bridge);
+}
+
__printf(5, 6)
int drm_encoder_init(struct drm_device *dev,
struct drm_encoder *encoder,
--
2.21.0
More information about the dri-devel
mailing list