@@ -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);
@@ -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;
}
@@ -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;
@@ -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);
@@ -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. */
@@ -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);
@@ -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;
@@ -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;
@@ -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;
@@ -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);
@@ -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);
@@ -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,
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@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(-)