public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/crtc: Add a helper func to get a registered crtc from its index
@ 2015-08-25  3:13 Xinliang Liu
  2015-08-25  9:36 ` Daniel Vetter
  0 siblings, 1 reply; 4+ messages in thread
From: Xinliang Liu @ 2015-08-25  3:13 UTC (permalink / raw)
  To: airlied, dri-devel
  Cc: linux-kernel, benjamin.gaignard, liguozhu, kong.kongxinwei,
	Xinliang Liu

This patch add a helper func to get a registered crtc from its index.
In some case, where we know the crtc's index and we want to know the
crtc too.

For example, the enable_vblank func of struct drm_driver:
In the implementation of this func, we know the index of the crtc but
we want to know the crtc. This helper func can get the crtc easily.
A sample impelmentation of enable_vblank is as shown as bellow:

int hisi_drm_crtc_enable_vblank(struct drm_device *dev, int c)
{
	struct drm_crtc *crtc = drm_get_crtc_from_index(dev, c);
	struct hisi_crtc *hcrtc = to_hisi_crtc(crtc);
	struct hisi_crtc_ops *ops = hcrtc->ops;
	int ret = 0;

	if (ops->enable_vblank)
		ret = ops->enable_vblank(hcrtc);

	return ret;
}

Signed-off-by: Xinliang Liu <xinliang.liu@linaro.org>
---
 drivers/gpu/drm/drm_crtc.c | 25 +++++++++++++++++++++++++
 include/drm/drm_crtc.h     |  2 ++
 2 files changed, 27 insertions(+)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index b9ba061..8764765 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -747,6 +747,31 @@ unsigned int drm_crtc_index(struct drm_crtc *crtc)
 }
 EXPORT_SYMBOL(drm_crtc_index);
 
+/**
+ * drm_get_crtc_from_index - find a registered CRTC from the index
+ * @dev: DRM device
+ * @index: index of a registered CRTC
+ *
+ * Given a index, return the registered CRTC within a DRM
+ * device's list of CRTCs.
+ */
+struct drm_crtc *drm_get_crtc_from_index(struct drm_device *dev,
+					 unsigned int index)
+{
+	unsigned int index_tmp = 0;
+	struct drm_crtc *crtc;
+
+	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
+		if (index_tmp == index)
+			return crtc;
+
+		index_tmp++;
+	}
+
+	BUG();
+}
+EXPORT_SYMBOL(drm_get_crtc_from_index);
+
 /*
  * drm_mode_remove - remove and free a mode
  * @connector: connector list to modify
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 57ca8cc..3a46d39d 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -1225,6 +1225,8 @@ extern int drm_crtc_init_with_planes(struct drm_device *dev,
 				     const struct drm_crtc_funcs *funcs);
 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
 extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
+extern struct drm_crtc *drm_get_crtc_from_index(struct drm_device *dev,
+						unsigned int index);
 
 /**
  * drm_crtc_mask - find the mask of a registered CRTC
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-10  9:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-25  3:13 [PATCH] drm/crtc: Add a helper func to get a registered crtc from its index Xinliang Liu
2015-08-25  9:36 ` Daniel Vetter
2015-08-26 11:04   ` Thierry Reding
     [not found]   ` <CAGd==06xkndVgMdGgC1Hd5QtHSK8q=a30rpjGKWUzTOgCay_jw@mail.gmail.com>
2015-09-10  9:46     ` Daniel Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox