All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxime Ripard <mripard@kernel.org>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
	Emma Anholt <emma@anholt.net>
Cc: Hans Verkuil <hverkuil@xs4all.nl>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	Maxime Ripard <mripard@kernel.org>
Subject: [PATCH RFC 11/13] drm/connector: hdmi: Create Infoframe DebugFS entries
Date: Mon, 14 Aug 2023 15:56:23 +0200	[thread overview]
Message-ID: <20230814-kms-hdmi-connector-state-v1-11-048054df3654@kernel.org> (raw)
In-Reply-To: <20230814-kms-hdmi-connector-state-v1-0-048054df3654@kernel.org>

There has been some discussions recently about the infoframes sent by
drivers and if they were properly generated.

In parallel, there's been some interest in creating an infoframe-decode
tool similar to edid-decode.

Both would be much easier if we were to expose the infoframes programmed
in the hardware. It won't be perfect since we have no guarantee that
it's actually what goes through the wire, but it's the best we can do.

Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
 drivers/gpu/drm/drm_hdmi_connector.c | 124 +++++++++++++++++++++++++++++++++++
 include/drm/drm_connector.h          |   4 ++
 2 files changed, 128 insertions(+)

diff --git a/drivers/gpu/drm/drm_hdmi_connector.c b/drivers/gpu/drm/drm_hdmi_connector.c
index 46cafb17def7..dcc45b1080f9 100644
--- a/drivers/gpu/drm/drm_hdmi_connector.c
+++ b/drivers/gpu/drm/drm_hdmi_connector.c
@@ -907,6 +907,130 @@ void drm_atomic_helper_hdmi_connector_print_state(struct drm_printer *p,
 }
 EXPORT_SYMBOL(drm_atomic_helper_hdmi_connector_print_state);
 
+struct debugfs_wrapper {
+	struct drm_hdmi_connector *hdmi_connector;
+	union hdmi_infoframe *frame;
+};
+
+static ssize_t
+infoframe_read(struct file *filp, char __user *ubuf, size_t count, loff_t *ppos)
+{
+	const struct debugfs_wrapper *wrapper = filp->private_data;
+	struct drm_hdmi_connector *hdmi_connector = wrapper->hdmi_connector;
+	union hdmi_infoframe *frame = wrapper->frame;
+	u8 buf[HDMI_MAX_INFOFRAME_SIZE];
+	ssize_t len;
+
+	len = hdmi_infoframe_pack(frame, buf, sizeof(buf));
+	if (len < 0)
+		return len;
+
+	mutex_lock(&hdmi_connector->infoframes.lock);
+	len = simple_read_from_buffer(ubuf, count, ppos, buf, len);
+	mutex_unlock(&hdmi_connector->infoframes.lock);
+
+	return len;
+}
+
+static const struct file_operations infoframe_fops = {
+	.owner   = THIS_MODULE,
+	.open    = simple_open,
+	.read    = infoframe_read,
+};
+
+static int create_debugfs_infoframe_file(struct drm_hdmi_connector *hdmi_connector,
+					 struct dentry *parent,
+					 const char *filename,
+					 union hdmi_infoframe *frame)
+{
+	struct drm_device *dev = hdmi_connector->base.dev;
+	struct debugfs_wrapper *wrapper;
+	struct dentry *file;
+
+	wrapper = drmm_kzalloc(dev, sizeof(*wrapper), GFP_KERNEL);
+	if (!wrapper)
+		return -ENOMEM;
+
+	wrapper->hdmi_connector = hdmi_connector;
+	wrapper->frame = frame;
+
+	file = debugfs_create_file(filename, 0400, parent, wrapper, &infoframe_fops);
+	if (IS_ERR(file))
+		return PTR_ERR(file);
+
+	return 0;
+}
+
+#define CREATE_INFOFRAME_FILE(c, p, i)		\
+	create_debugfs_infoframe_file(c, p, #i, (union hdmi_infoframe *)&(c)->infoframes.i)
+
+static int create_debugfs_infoframe_files(struct drm_hdmi_connector *hdmi_connector,
+					  struct dentry *parent)
+{
+	int ret;
+
+	ret = CREATE_INFOFRAME_FILE(hdmi_connector, parent, audio);
+	if (ret)
+		return ret;
+
+	ret = CREATE_INFOFRAME_FILE(hdmi_connector, parent, avi);
+	if (ret)
+		return ret;
+
+	ret = CREATE_INFOFRAME_FILE(hdmi_connector, parent, drm);
+	if (ret)
+		return ret;
+
+	ret = CREATE_INFOFRAME_FILE(hdmi_connector, parent, spd);
+	if (ret)
+		return ret;
+
+	ret = CREATE_INFOFRAME_FILE(hdmi_connector, parent, vendor);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+#undef CREATE_INFOFRAME_FILE
+
+static void remove_debugfs_dir(struct drm_device *dev, void *data)
+{
+	struct dentry *dir = data;
+
+	debugfs_remove_recursive(dir);
+}
+
+/**
+ * drm_helper_hdmi_connector_debugfs_init - DebugFS init for HDMI connectors
+ * @connector: Parent Connector
+ * @dentry: DebugFS root dentry
+ *
+ * Provides a default implementation for
+ * @drm_connector_helper_funcs.debugfs_init that will create all the
+ * files relevant for a @drm_hdmi_connector.
+ */
+void drm_helper_hdmi_connector_debugfs_init(struct drm_connector *connector,
+					    struct dentry *root)
+{
+	struct drm_hdmi_connector *hdmi_connector =
+		connector_to_hdmi_connector(connector);
+	struct drm_device *dev = hdmi_connector->base.dev;
+	struct dentry *dir;
+	int ret;
+
+	dir = debugfs_create_dir("infoframes", root);
+	if (IS_ERR(dir))
+		return;
+
+	ret = drmm_add_action_or_reset(dev, remove_debugfs_dir, dir);
+	if (ret)
+		return;
+
+	create_debugfs_infoframe_files(hdmi_connector, dir);
+}
+EXPORT_SYMBOL(drm_helper_hdmi_connector_debugfs_init);
+
 /**
  * drmm_hdmi_connector_init - Init a preallocated HDMI connector
  * @dev: DRM device
diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
index 21da6f428101..e5faaeb35a9d 100644
--- a/include/drm/drm_connector.h
+++ b/include/drm/drm_connector.h
@@ -2294,6 +2294,10 @@ int drmm_hdmi_connector_init(struct drm_device *dev,
 			     struct i2c_adapter *ddc,
 			     unsigned int max_bpc);
 
+void drm_helper_hdmi_connector_debugfs_init(struct drm_connector *connector,
+					    struct dentry *root);
+
+
 /**
  * struct drm_tile_group - Tile group metadata
  * @refcount: reference count

-- 
2.41.0


  parent reply	other threads:[~2023-08-14 13:57 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-14 13:56 [PATCH RFC 00/13] drm/connector: Create HDMI Connector infrastructure Maxime Ripard
2023-08-14 13:56 ` [PATCH RFC 01/13] drm/connector: Introduce an HDMI connector Maxime Ripard
2023-08-15  9:19   ` Jani Nikula
2023-08-14 13:56 ` [PATCH RFC 02/13] drm/connector: hdmi: Create a custom state Maxime Ripard
2023-08-14 13:56 ` [PATCH RFC 03/13] drm/connector: hdmi: Add Broadcast RGB property Maxime Ripard
2023-08-14 14:46   ` Simon Ser
2023-08-14 14:46     ` Simon Ser
2023-08-14 13:56 ` [PATCH RFC 04/13] drm/connector: hdmi: Add helper to get the RGB range Maxime Ripard
2023-08-14 13:56 ` [PATCH RFC 05/13] drm/connector: hdmi: Add output BPC to the connector state Maxime Ripard
2023-08-14 13:56 ` [PATCH RFC 06/13] drm/connector: hdmi: Add support for output format Maxime Ripard
2023-08-14 17:17   ` kernel test robot
2023-08-14 13:56 ` [PATCH RFC 07/13] drm/connector: hdmi: Calculate TMDS character rate Maxime Ripard
2023-08-14 13:56 ` [PATCH RFC 08/13] drm/connector: hdmi: Add custom hook to filter " Maxime Ripard
2023-08-14 13:56 ` [PATCH RFC 09/13] drm/connector: hdmi: Compute bpc and format automatically Maxime Ripard
2023-08-14 13:56 ` [PATCH RFC 10/13] drm/connector: hdmi: Add Infoframes generation Maxime Ripard
2023-08-15 11:20   ` Dave Stevenson
2023-08-15 11:20     ` Dave Stevenson
2023-08-14 13:56 ` Maxime Ripard [this message]
2023-08-14 13:56 ` [PATCH RFC 12/13] drm/vc4: hdmi: Create destroy state implementation Maxime Ripard
2023-08-14 13:56 ` [PATCH RFC 13/13] drm/vc4: hdmi: Switch to HDMI connector Maxime Ripard
2023-08-14 17:58   ` kernel test robot
2023-08-22 10:22   ` kernel test robot
2023-08-16  8:43 ` [PATCH RFC 00/13] drm/connector: Create HDMI Connector infrastructure Hans Verkuil
2023-08-22 14:16 ` Daniel Vetter
2023-08-22 14:16   ` Daniel Vetter
2023-08-22 14:35   ` Maxime Ripard
2023-08-22 14:41     ` Daniel Vetter
2023-08-22 14:41       ` Daniel Vetter
2023-08-22 14:51     ` Jani Nikula
2023-08-22 15:05       ` Daniel Vetter
2023-08-22 15:05         ` Daniel Vetter

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=20230814-kms-hdmi-connector-state-v1-11-048054df3654@kernel.org \
    --to=mripard@kernel.org \
    --cc=airlied@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emma@anholt.net \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.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.