[RFC v2 3/5] drm: Add HDMI infoframe helpers
Thierry Reding
thierry.reding at avionic-design.de
Wed Dec 5 08:45:42 PST 2012
Add a generic helper to fill in an HDMI AVI infoframe with data
extracted from a DRM display mode.
Signed-off-by: Thierry Reding <thierry.reding at avionic-design.de>
---
Changes in v2:
- reuse CEA modes defined in drm_edid_modes.h
drivers/gpu/drm/Kconfig | 7 +++++
drivers/gpu/drm/Makefile | 1 +
drivers/gpu/drm/drm_hdmi.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++
include/drm/drm_hdmi.h | 19 +++++++++++++
4 files changed, 98 insertions(+)
create mode 100644 drivers/gpu/drm/drm_hdmi.c
create mode 100644 include/drm/drm_hdmi.h
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 983201b..94a4623 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -69,6 +69,13 @@ config DRM_KMS_CMA_HELPER
help
Choose this if you need the KMS CMA helper functions
+config DRM_HDMI
+ bool
+ depends on DRM
+ select HDMI
+ help
+ Choose this if you need the HDMI helper functions
+
config DRM_TDFX
tristate "3dfx Banshee/Voodoo3+"
depends on DRM && PCI
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 6f58c81..4a0b781 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -16,6 +16,7 @@ drm-y := drm_auth.o drm_buffer.o drm_bufs.o drm_cache.o \
drm-$(CONFIG_COMPAT) += drm_ioc32.o
drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
+drm-$(CONFIG_DRM_HDMI) += drm_hdmi.o
drm-$(CONFIG_PCI) += ati_pcigart.o
drm-usb-y := drm_usb.o
diff --git a/drivers/gpu/drm/drm_hdmi.c b/drivers/gpu/drm/drm_hdmi.c
new file mode 100644
index 0000000..821ca56
--- /dev/null
+++ b/drivers/gpu/drm/drm_hdmi.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2012 Avionic Design GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/hdmi.h>
+
+#include <drm/drm_crtc.h>
+#include <drm/drm_hdmi.h>
+
+#include "drm_edid_modes.h"
+
+static inline unsigned int
+drm_mode_cea_vic(const struct drm_display_mode *mode)
+{
+ unsigned int i;
+
+ for (i = 0; i < drm_num_cea_modes; i++)
+ if (drm_mode_equal(mode, &edid_cea_modes[i]))
+ return i + 1;
+
+ return 0;
+}
+
+static inline enum hdmi_picture_aspect
+drm_display_mode_get_aspect(const struct drm_display_mode *mode)
+{
+ enum hdmi_picture_aspect aspect = HDMI_PICTURE_ASPECT_NONE;
+
+ if ((mode->hdisplay * 9) / 16 == mode->vdisplay)
+ aspect = HDMI_PICTURE_ASPECT_16_9;
+ else if ((mode->hdisplay * 3) / 4 == mode->vdisplay)
+ aspect = HDMI_PICTURE_ASPECT_4_3;
+
+ return aspect;
+}
+
+/**
+ * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
+ * data from a DRM display mode
+ * @frame: HDMI AVI infoframe
+ * @mode: DRM display mode
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int
+drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
+ const struct drm_display_mode *mode)
+{
+ int err;
+
+ if (!frame || !mode)
+ return -EINVAL;
+
+ err = hdmi_avi_infoframe_init(frame);
+ if (err < 0)
+ return err;
+
+ frame->video_code = drm_mode_cea_vic(mode);
+ if (!frame->video_code)
+ return 0;
+
+ frame->picture_aspect = drm_display_mode_get_aspect(mode);
+ frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
+
+ return 0;
+}
+EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
diff --git a/include/drm/drm_hdmi.h b/include/drm/drm_hdmi.h
new file mode 100644
index 0000000..e20462d
--- /dev/null
+++ b/include/drm/drm_hdmi.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2012 Avionic Design GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _DRM_HDMI_H_
+#define _DRM_HDMI_H_
+
+struct hdmi_avi_infoframe;
+struct drm_display_mode;
+
+int
+drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
+ const struct drm_display_mode *mode);
+
+#endif
--
1.8.0.1
More information about the dri-devel
mailing list