All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime@cerno.tech>
To: Andrzej Hajda <a.hajda@samsung.com>,
	Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
	Daniel Vetter <daniel.vetter@intel.com>,
	David Airlie <airlied@linux.ie>,
	Jernej Skrabec <jernej.skrabec@siol.net>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Maxime Ripard <maxime@cerno.tech>,
	Neil Armstrong <narmstrong@baylibre.com>,
	Jonas Karlman <jonas@kwiboo.se>
Cc: Tim Gover <tim.gover@raspberrypi.com>,
	Dave Stevenson <dave.stevenson@raspberrypi.com>,
	dri-devel@lists.freedesktop.org,
	bcm-kernel-feedback-list@broadcom.com,
	linux-rpi-kernel@lists.infradead.org,
	Phil Elwell <phil@raspberrypi.com>
Subject: [PATCH 01/18] drm: Introduce new HDMI helpers
Date: Wed, 17 Mar 2021 16:43:35 +0100	[thread overview]
Message-ID: <20210317154352.732095-2-maxime@cerno.tech> (raw)
In-Reply-To: <20210317154352.732095-1-maxime@cerno.tech>

The new bridge rework to support the input and output formats introduced
some boilerplate code that will need to be shared across drivers.

Since dw-hdmi is the only driver so far, let's introduce those helpers
based on that code.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
---
 drivers/gpu/drm/Makefile   |   2 +-
 drivers/gpu/drm/drm_hdmi.c | 170 +++++++++++++++++++++++++++++++++++++
 include/drm/drm_hdmi.h     |  24 ++++++
 3 files changed, 195 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_hdmi.c
 create mode 100644 include/drm/drm_hdmi.h

diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 5eb5bf7c16e3..1b77bd64a37e 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -17,7 +17,7 @@ drm-y       :=	drm_auth.o drm_cache.o \
 		drm_plane.o drm_color_mgmt.o drm_print.o \
 		drm_dumb_buffers.o drm_mode_config.o drm_vblank.o \
 		drm_syncobj.o drm_lease.o drm_writeback.o drm_client.o \
-		drm_client_modeset.o drm_atomic_uapi.o drm_hdcp.o \
+		drm_client_modeset.o drm_atomic_uapi.o drm_hdmi.o drm_hdcp.o \
 		drm_managed.o drm_vblank_work.o
 
 drm-$(CONFIG_DRM_LEGACY) += drm_bufs.o drm_context.o drm_dma.o drm_legacy_misc.o drm_lock.o \
diff --git a/drivers/gpu/drm/drm_hdmi.c b/drivers/gpu/drm/drm_hdmi.c
new file mode 100644
index 000000000000..3834d5dd6d88
--- /dev/null
+++ b/drivers/gpu/drm/drm_hdmi.c
@@ -0,0 +1,170 @@
+#include <linux/errno.h>
+#include <linux/hdmi.h>
+#include <linux/media-bus-format.h>
+#include <linux/types.h>
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_hdmi.h>
+
+/**
+ * drm_hdmi_bus_fmt_is_rgb() - Is the media bus format an RGB format?
+ * @bus_format: MEDIA_BUS_FMT* to test
+ *
+ * Checks if the media bus format is an RGB one
+ *
+ * RETURNS:
+ * True if the format is an RGB one, false otherwise
+ */
+bool drm_hdmi_bus_fmt_is_rgb(u32 bus_format)
+{
+	switch (bus_format) {
+	case MEDIA_BUS_FMT_RGB888_1X24:
+	case MEDIA_BUS_FMT_RGB101010_1X30:
+	case MEDIA_BUS_FMT_RGB121212_1X36:
+	case MEDIA_BUS_FMT_RGB161616_1X48:
+		return true;
+
+	default:
+		return false;
+	}
+}
+EXPORT_SYMBOL(drm_hdmi_bus_fmt_is_rgb);
+
+/**
+ * drm_hdmi_bus_fmt_is_yuv444() - Is the media bus format an YUV444 format?
+ * @bus_format: MEDIA_BUS_FMT* to test
+ *
+ * Checks if the media bus format is an YUV444 one
+ *
+ * RETURNS:
+ * True if the format is an YUV444 one, false otherwise
+ */
+bool drm_hdmi_bus_fmt_is_yuv444(u32 bus_format)
+{
+	switch (bus_format) {
+	case MEDIA_BUS_FMT_YUV8_1X24:
+	case MEDIA_BUS_FMT_YUV10_1X30:
+	case MEDIA_BUS_FMT_YUV12_1X36:
+	case MEDIA_BUS_FMT_YUV16_1X48:
+		return true;
+
+	default:
+		return false;
+	}
+}
+EXPORT_SYMBOL(drm_hdmi_bus_fmt_is_yuv444);
+
+/**
+ * drm_hdmi_bus_fmt_is_yuv422() - Is the media bus format an YUV422 format?
+ * @bus_format: MEDIA_BUS_FMT* to test
+ *
+ * Checks if the media bus format is an YUV422 one
+ *
+ * RETURNS:
+ * True if the format is an YUV422 one, false otherwise
+ */
+bool drm_hdmi_bus_fmt_is_yuv422(u32 bus_format)
+{
+	switch (bus_format) {
+	case MEDIA_BUS_FMT_UYVY8_1X16:
+	case MEDIA_BUS_FMT_UYVY10_1X20:
+	case MEDIA_BUS_FMT_UYVY12_1X24:
+		return true;
+
+	default:
+		return false;
+	}
+}
+EXPORT_SYMBOL(drm_hdmi_bus_fmt_is_yuv422);
+
+/**
+ * drm_hdmi_bus_fmt_is_yuv420() - Is the media bus format an YUV420 format?
+ * @bus_format: MEDIA_BUS_FMT* to test
+ *
+ * Checks if the media bus format is an YUV420 one
+ *
+ * RETURNS:
+ * True if the format is an YUV420 one, false otherwise
+ */
+bool drm_hdmi_bus_fmt_is_yuv420(u32 bus_format)
+{
+	switch (bus_format) {
+	case MEDIA_BUS_FMT_UYYVYY8_0_5X24:
+	case MEDIA_BUS_FMT_UYYVYY10_0_5X30:
+	case MEDIA_BUS_FMT_UYYVYY12_0_5X36:
+	case MEDIA_BUS_FMT_UYYVYY16_0_5X48:
+		return true;
+
+	default:
+		return false;
+	}
+}
+EXPORT_SYMBOL(drm_hdmi_bus_fmt_is_yuv420);
+
+/**
+ * drm_hdmi_bus_fmt_color_depth() - Returns the color depth in bits
+ * @bus_format: MEDIA_BUS_FMT* to test
+ *
+ * Computes the number of bits per color for a given media bus format
+ *
+ * RETURNS:
+ * The number of bits per color
+ */
+int drm_hdmi_bus_fmt_color_depth(u32 bus_format)
+{
+	switch (bus_format) {
+	case MEDIA_BUS_FMT_RGB888_1X24:
+	case MEDIA_BUS_FMT_YUV8_1X24:
+	case MEDIA_BUS_FMT_UYVY8_1X16:
+	case MEDIA_BUS_FMT_UYYVYY8_0_5X24:
+		return 8;
+
+	case MEDIA_BUS_FMT_RGB101010_1X30:
+	case MEDIA_BUS_FMT_YUV10_1X30:
+	case MEDIA_BUS_FMT_UYVY10_1X20:
+	case MEDIA_BUS_FMT_UYYVYY10_0_5X30:
+		return 10;
+
+	case MEDIA_BUS_FMT_RGB121212_1X36:
+	case MEDIA_BUS_FMT_YUV12_1X36:
+	case MEDIA_BUS_FMT_UYVY12_1X24:
+	case MEDIA_BUS_FMT_UYYVYY12_0_5X36:
+		return 12;
+
+	case MEDIA_BUS_FMT_RGB161616_1X48:
+	case MEDIA_BUS_FMT_YUV16_1X48:
+	case MEDIA_BUS_FMT_UYYVYY16_0_5X48:
+		return 16;
+
+	default:
+		return 0;
+	}
+}
+EXPORT_SYMBOL(drm_hdmi_bus_fmt_color_depth);
+
+/**
+ * drm_hdmi_bus_fmt_color_depth() - Returns the color depth in bits
+ * @bus_format: MEDIA_BUS_FMT* to test
+ *
+ * Computes the number of bits per color for a given media bus format
+ *
+ * RETURNS:
+ * The number of bits per color
+ */
+int drm_hdmi_avi_infoframe_output_colorspace(struct hdmi_avi_infoframe *frame,
+					     struct drm_bus_cfg *out_bus_cfg)
+{
+	if (drm_hdmi_bus_fmt_is_yuv444(out_bus_cfg->format))
+		frame->colorspace = HDMI_COLORSPACE_YUV444;
+	else if (drm_hdmi_bus_fmt_is_yuv422(out_bus_cfg->format))
+		frame->colorspace = HDMI_COLORSPACE_YUV422;
+	else if (drm_hdmi_bus_fmt_is_yuv420(out_bus_cfg->format))
+		frame->colorspace = HDMI_COLORSPACE_YUV420;
+	else if (drm_hdmi_bus_fmt_is_rgb(out_bus_cfg->format))
+		frame->colorspace = HDMI_COLORSPACE_RGB;
+	else
+		return -EINVAL;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_hdmi_avi_infoframe_output_colorspace);
diff --git a/include/drm/drm_hdmi.h b/include/drm/drm_hdmi.h
new file mode 100644
index 000000000000..8cd281699ea0
--- /dev/null
+++ b/include/drm/drm_hdmi.h
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2013-2015 Mentor Graphics Inc.
+ * Copyright (C) 2011-2013 Freescale Semiconductor, Inc.
+ * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
+ */
+
+#ifndef __DRM_HDMI_H_
+#define __DRM_HDMI_H_
+
+#include <linux/types.h>
+
+struct drm_bus_cfg;
+struct hdmi_avi_infoframe;
+
+bool drm_hdmi_bus_fmt_is_rgb(u32 bus_format);
+bool drm_hdmi_bus_fmt_is_yuv444(u32 bus_format);
+bool drm_hdmi_bus_fmt_is_yuv422(u32 bus_format);
+bool drm_hdmi_bus_fmt_is_yuv420(u32 bus_format);
+int drm_hdmi_bus_fmt_color_depth(u32 bus_format);
+int drm_hdmi_avi_infoframe_output_colorspace(struct hdmi_avi_infoframe *frame,
+					     struct drm_bus_cfg *out_bus_cfg);
+
+#endif // __DRM_HDMI_H_
-- 
2.30.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2021-03-17 15:44 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 15:43 [PATCH 00/18] drm/vc4: hdmi: Add Support for the YUV output Maxime Ripard
2021-03-17 15:43 ` Maxime Ripard [this message]
2021-04-09  7:16   ` [PATCH 01/18] drm: Introduce new HDMI helpers Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 02/18] drm/bridge: Add HDMI output fmt helper Maxime Ripard
2021-03-17 16:08   ` Neil Armstrong
2021-03-18 18:31     ` Jernej Škrabec
2021-03-19  9:44       ` Neil Armstrong
2021-03-19 10:09         ` Maxime Ripard
2021-04-09  8:03   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 03/18] drm/bridge: dw-hdmi: Use helpers Maxime Ripard
2021-04-09  8:05   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 04/18] drm/vc4: txp: Properly set the possible_crtcs mask Maxime Ripard
2021-04-09  8:07   ` Thomas Zimmermann
2021-04-09  8:11   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 05/18] drm/vc4: crtc: Skip the TXP Maxime Ripard
2021-04-09  8:10   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 06/18] drm/vc4: Rework the encoder retrieval code Maxime Ripard
2021-03-17 18:09   ` kernel test robot
2021-03-20  1:08   ` kernel test robot
2021-04-09  8:54   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 07/18] drm/vc4: hdmi: Add full range RGB helper Maxime Ripard
2021-04-12  9:44   ` Thomas Zimmermann
2021-04-14 13:48     ` Maxime Ripard
2021-03-17 15:43 ` [PATCH 08/18] drm/vc4: hdmi: Use full range helper in csc functions Maxime Ripard
2021-04-12  9:45   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 09/18] drm/vc4: hdmi: Remove limited_rgb_range Maxime Ripard
2021-04-12 10:19   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 10/18] drm/vc4: hdmi: Convert to bridge Maxime Ripard
2021-04-12 10:21   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 11/18] drm/vc4: hdmi: Move XBAR setup to csc_setup Maxime Ripard
2021-04-12 10:28   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 12/18] drm/vc4: hdmi: Replace CSC_CTL hardcoded value by defines Maxime Ripard
2021-04-12 10:28   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 13/18] drm/vc4: hdmi: Define colorspace matrices Maxime Ripard
2021-04-14 13:54   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 14/18] drm/vc4: hdmi: Change CSC callback prototype Maxime Ripard
2021-04-14 13:56   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 15/18] drm/vc4: hdmi: Rework the infoframe prototype Maxime Ripard
2021-04-14 13:58   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 16/18] drm/vc4: hdmi: Support HDMI YUV output Maxime Ripard
2021-04-15  6:43   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 17/18] drm/vc4: hdmi: Move the pixel rate calculation to a helper Maxime Ripard
2021-04-15  7:19   ` Thomas Zimmermann
2021-03-17 15:43 ` [PATCH 18/18] drm/vc4: hdmi: Force YUV422 if the rate is too high Maxime Ripard
2021-04-15  7:24   ` Thomas Zimmermann
2021-03-18 18:16 ` [PATCH 00/18] drm/vc4: hdmi: Add Support for the YUV output Jernej Škrabec
2021-03-19 10:13   ` Maxime Ripard
2021-04-09  9:47   ` Neil Armstrong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210317154352.732095-2-maxime@cerno.tech \
    --to=maxime@cerno.tech \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=a.hajda@samsung.com \
    --cc=airlied@linux.ie \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=daniel.vetter@intel.com \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jernej.skrabec@siol.net \
    --cc=jonas@kwiboo.se \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=narmstrong@baylibre.com \
    --cc=phil@raspberrypi.com \
    --cc=tim.gover@raspberrypi.com \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.