[PATCH v2 2/3] drm/atomic-helpers: Introduce drm_atomic_helper_disable_connector()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



drm_atomic_helper_disable_connector() disables a connector taking care
of disabling the CRTC as well if the disabled connector was the only one
connector connected to the CRTC.

Signed-off-by: Herve Codina <herve.codina@xxxxxxxxxxx>
---
 drivers/gpu/drm/drm_atomic_helper.c | 67 +++++++++++++++++++++++++++++
 include/drm/drm_atomic_helper.h     |  2 +
 2 files changed, 69 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 8ed186ddaeaf..1d691cbb047e 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -3279,6 +3279,73 @@ int drm_atomic_helper_set_config(struct drm_mode_set *set,
 }
 EXPORT_SYMBOL(drm_atomic_helper_set_config);
 
+/**
+ * drm_atomic_helper_disable_connector - disable connector
+ * @connector: connector to disable
+ * @ctx: lock acquisition context
+ *
+ * Turn off the given connector by setting its DPMS mode to off.
+ * Also deactivate the CRTC is this connector was the only one connected to the
+ * CRTC.
+ *
+ * Note that if callers haven't already acquired all modeset locks this might
+ * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
+ *
+ * Returns:
+ * 0 on success or a negative error code on failure.
+ */
+int drm_atomic_helper_disable_connector(struct drm_connector *connector,
+					struct drm_modeset_acquire_ctx *ctx)
+{
+	struct drm_connector_state *connector_state;
+	struct drm_crtc_state *crtc_state;
+	struct drm_atomic_state *state;
+	struct drm_crtc *crtc;
+	int ret;
+
+	state = drm_atomic_state_alloc(connector->dev);
+	if (!state)
+		return -ENOMEM;
+
+	state->acquire_ctx = ctx;
+
+	connector_state = drm_atomic_get_connector_state(state, connector);
+	if (IS_ERR(connector_state)) {
+		ret = PTR_ERR(connector_state);
+		goto end;
+	}
+
+	crtc = connector_state->crtc;
+
+	ret = drm_atomic_set_crtc_for_connector(connector_state, NULL);
+	if (ret < 0)
+		goto end;
+
+	crtc_state = drm_atomic_get_crtc_state(state, crtc);
+	if (IS_ERR(crtc_state)) {
+		ret = PTR_ERR(crtc_state);
+		goto end;
+	}
+
+	if (!crtc_state->connector_mask) {
+		/*
+		 * The only one connector from the crtc has
+		 * been disabled -> Disable the CRTC too
+		 */
+		ret = drm_atomic_set_mode_prop_for_crtc(crtc_state, NULL);
+		if (ret < 0)
+			goto end;
+
+		crtc_state->active = false;
+	}
+
+	ret = drm_atomic_commit(state);
+end:
+	drm_atomic_state_put(state);
+	return ret;
+}
+EXPORT_SYMBOL(drm_atomic_helper_disable_connector);
+
 /**
  * drm_atomic_helper_disable_all - disable all currently active outputs
  * @dev: DRM device
diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
index 9aa0a05aa072..923a354577a3 100644
--- a/include/drm/drm_atomic_helper.h
+++ b/include/drm/drm_atomic_helper.h
@@ -137,6 +137,8 @@ int drm_atomic_helper_disable_plane(struct drm_plane *plane,
 int drm_atomic_helper_set_config(struct drm_mode_set *set,
 				 struct drm_modeset_acquire_ctx *ctx);
 
+int drm_atomic_helper_disable_connector(struct drm_connector *connector,
+					struct drm_modeset_acquire_ctx *ctx);
 int drm_atomic_helper_disable_all(struct drm_device *dev,
 				  struct drm_modeset_acquire_ctx *ctx);
 void drm_atomic_helper_shutdown(struct drm_device *dev);
-- 
2.47.0





[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux