diff mbox

[1/3] drm: add crtc helper drm_crtc_from_index()

Message ID 1483015290-16660-2-git-send-email-shawnguo@kernel.org
State New
Headers show

Commit Message

Shawn Guo Dec. 29, 2016, 12:41 p.m. UTC
From: Shawn Guo <shawn.guo@linaro.org>

It adds a crtc helper drm_crtc_from_index() to find the registered CRTC
with a given index, just like drm_plane_from_index().

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
 drivers/gpu/drm/drm_crtc.c | 20 ++++++++++++++++++++
 include/drm/drm_crtc.h     |  1 +
 2 files changed, 21 insertions(+)

Comments

Daniel Vetter Dec. 30, 2016, 11:14 a.m. UTC | #1
On Thu, Dec 29, 2016 at 08:41:28PM +0800, Shawn Guo wrote:
> From: Shawn Guo <shawn.guo@linaro.org>
> 
> It adds a crtc helper drm_crtc_from_index() to find the registered CRTC
> with a given index, just like drm_plane_from_index().
> 
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> ---
>  drivers/gpu/drm/drm_crtc.c | 20 ++++++++++++++++++++
>  include/drm/drm_crtc.h     |  1 +
>  2 files changed, 21 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index e75f62cd8a65..5c1bb1f34697 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -47,6 +47,26 @@
>  #include "drm_internal.h"
>  
>  /**
> + * drm_crtc_from_index - find the registered CRTC at an index
> + * @dev: DRM device
> + * @idx: index of registered CRTC to find for
> + *
> + * Given a CRTC index, return the registered CRTC from DRM device's
> + * list of CRTCs with matching index.
> + */

Might be useful to go through al the drm_*_inde and drm_*_from_index
functions we have and a sentence to each likt "This is the inverse of
drm_crtc_index()." to cross link them a bit.

Also here a sentence explaining that this is useful in the vblank code,
e.g.

"This is useful in the vblank callbacks (like &drm_driver.enable_vblank or
&drm_driver.disable_vblank), since that still deals with indices instead
of pointers to &struct drm_crtc."

Follow-up pach, since I applied these here already.
-Daniel

> +struct drm_crtc *drm_crtc_from_index(struct drm_device *dev, int idx)
> +{
> +	struct drm_crtc *crtc;
> +
> +	drm_for_each_crtc(crtc, dev)
> +		if (idx == crtc->index)
> +			return crtc;
> +
> +	return NULL;
> +}
> +EXPORT_SYMBOL(drm_crtc_from_index);
> +
> +/**
>   * drm_crtc_force_disable - Forcibly turn off a CRTC
>   * @crtc: CRTC to turn off
>   *
> diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
> index 946672f97e1e..a5627eb8621f 100644
> --- a/include/drm/drm_crtc.h
> +++ b/include/drm/drm_crtc.h
> @@ -830,6 +830,7 @@ void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
>  int drm_crtc_force_disable_all(struct drm_device *dev);
>  
>  int drm_mode_set_config_internal(struct drm_mode_set *set);
> +struct drm_crtc *drm_crtc_from_index(struct drm_device *dev, int idx);
>  
>  /* Helpers */
>  static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
> -- 
> 1.9.1
>
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index e75f62cd8a65..5c1bb1f34697 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -47,6 +47,26 @@ 
 #include "drm_internal.h"
 
 /**
+ * drm_crtc_from_index - find the registered CRTC at an index
+ * @dev: DRM device
+ * @idx: index of registered CRTC to find for
+ *
+ * Given a CRTC index, return the registered CRTC from DRM device's
+ * list of CRTCs with matching index.
+ */
+struct drm_crtc *drm_crtc_from_index(struct drm_device *dev, int idx)
+{
+	struct drm_crtc *crtc;
+
+	drm_for_each_crtc(crtc, dev)
+		if (idx == crtc->index)
+			return crtc;
+
+	return NULL;
+}
+EXPORT_SYMBOL(drm_crtc_from_index);
+
+/**
  * drm_crtc_force_disable - Forcibly turn off a CRTC
  * @crtc: CRTC to turn off
  *
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 946672f97e1e..a5627eb8621f 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -830,6 +830,7 @@  void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
 int drm_crtc_force_disable_all(struct drm_device *dev);
 
 int drm_mode_set_config_internal(struct drm_mode_set *set);
+struct drm_crtc *drm_crtc_from_index(struct drm_device *dev, int idx);
 
 /* Helpers */
 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,