From patchwork Mon Mar 11 14:49:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13588924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 25360C54E58 for ; Mon, 11 Mar 2024 14:55:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=epy1atGNLSE1qL4NtwqHIEy4khJhRiAASM0K6ZBgBfc=; b=O21VIbi101v0rn Gu0XJQBOZKAPE0HpoWj9PAUntU2sZWCjCPCh9USmDEjjOUtP3QQxicVpdkrBtPAS3pzgyJ5yv7ftW uIRLXCSk4iwZdMai4XwEjKrT6K6Zorv8zRczqCq5lkIPJ53JzyOj3OMbvgnDJWqmoyjeamXV1Jrt2 x5IsJ+5glQyfU9OMcy8MHoFZ8P3ZrFQwWu+gY6B9GVwqOexTydy3p+o65yLUkM2TFaQecBpnfRXom gC0ckxOG46B+Oa44vSnTp9P5LC6Y2q4qSqiRRAAeWIEZRM5snlysC7PooHpWBxRJFcS7c+8WmE5cT A9Q8EamqlVK5TRGqJPIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rjh3Z-00000001vVq-2tnV; Mon, 11 Mar 2024 14:55:13 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rjgzY-00000001spa-2b5P; Mon, 11 Mar 2024 14:51:16 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C404060EAC; Mon, 11 Mar 2024 14:51:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44321C433F1; Mon, 11 Mar 2024 14:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710168663; bh=8/opTRplB5Ku39o1OEl1lg2hR6YKBkFWnOlEJPXB6sg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=S6zY0etKtkPf6wHL+91qGftBwWEN1RWDX69XX61l+SduvSeEa8CFbqY8j8xW9+baK vi53OeVv3WDDCCjvOEpoMSQH5mr3iiljUAw2Dm0Xm3UL7Id2F9nbnO2gTN7yCekC+/ wOcRA4wBb4pPamfaKTQx+YI0mgvW3ahtiwFIWoQW+lGo4k39GaPetiThOhLYyvzgZs +Z5nZ1ZYCNKxW3ra8E38Yc0Cgrma08dXFm0NMwANdyacmw7GNyd49QpjfyuTnZ3z4k X2WpqPYFkp1rDIP2SgLhI5UqPeeYv9t4B0xFO9mNjoSoYl/WELIFEAPQcV4uWIAzhI 0RAUiIvNDEXIw== From: Maxime Ripard Date: Mon, 11 Mar 2024 15:49:50 +0100 Subject: [PATCH v9 22/27] drm/connector: hdmi: Create Infoframe DebugFS entries MIME-Version: 1.0 Message-Id: <20240311-kms-hdmi-connector-state-v9-22-d45890323344@kernel.org> References: <20240311-kms-hdmi-connector-state-v9-0-d45890323344@kernel.org> In-Reply-To: <20240311-kms-hdmi-connector-state-v9-0-d45890323344@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , Sebastian Wick , =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Maxime Ripard X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4334; i=mripard@kernel.org; h=from:subject:message-id; bh=8/opTRplB5Ku39o1OEl1lg2hR6YKBkFWnOlEJPXB6sg=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKnvpYSEzv/evPRD6+GFc9oZmtcbir38K1DE563mUCt15 Ns5jneXO0pZGMS4GGTFFFlihM2XxJ2a9bqTjW8ezBxWJpAhDFycAjCR44WMDLe/6CmauRYoMSg/ e55cHSy63mzHueuTXey5YnY9nX+nip+R4fAKTyOTyWdWlxx7OrVxZ/OZ7MKAy9d9L1dsYk6JjNP oZwYA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240311_075105_190721_2351CFBC X-CRM114-Status: GOOD ( 14.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 --- drivers/gpu/drm/drm_debugfs.c | 110 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c index 08fcefd804bc..160389f3d84b 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -518,10 +518,118 @@ static const struct file_operations drm_connector_fops = { .llseek = seq_lseek, .release = single_release, .write = connector_write }; +struct debugfs_wrapper { + struct drm_connector *connector; + struct drm_connector_hdmi_infoframe *frame; +}; + +#define HDMI_MAX_INFOFRAME_SIZE 29 + +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_connector *connector = wrapper->connector; + struct drm_connector_hdmi_infoframe *infoframe = wrapper->frame; + union hdmi_infoframe *frame = &infoframe->data; + u8 buf[HDMI_MAX_INFOFRAME_SIZE]; + ssize_t len = 0; + + mutex_lock(&connector->hdmi.infoframes.lock); + + if (!infoframe->set) + goto out; + + len = hdmi_infoframe_pack(frame, buf, sizeof(buf)); + if (len < 0) + goto out; + + len = simple_read_from_buffer(ubuf, count, ppos, buf, len); + +out: + mutex_unlock(&connector->hdmi.infoframes.lock); + return len; +} + +static const struct file_operations infoframe_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = infoframe_read, +}; + +static int create_hdmi_infoframe_file(struct drm_connector *connector, + struct dentry *parent, + const char *filename, + struct drm_connector_hdmi_infoframe *frame) +{ + struct drm_device *dev = connector->dev; + struct debugfs_wrapper *wrapper; + struct dentry *file; + + wrapper = drmm_kzalloc(dev, sizeof(*wrapper), GFP_KERNEL); + if (!wrapper) + return -ENOMEM; + + wrapper->connector = 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_HDMI_INFOFRAME_FILE(c, p, i) \ + create_hdmi_infoframe_file(c, p, #i, &(c)->hdmi.infoframes.i) + +static int create_hdmi_infoframe_files(struct drm_connector *connector, + struct dentry *parent) +{ + int ret; + + ret = CREATE_HDMI_INFOFRAME_FILE(connector, parent, audio); + if (ret) + return ret; + + ret = CREATE_HDMI_INFOFRAME_FILE(connector, parent, avi); + if (ret) + return ret; + + ret = CREATE_HDMI_INFOFRAME_FILE(connector, parent, hdr_drm); + if (ret) + return ret; + + ret = CREATE_HDMI_INFOFRAME_FILE(connector, parent, spd); + if (ret) + return ret; + + ret = CREATE_HDMI_INFOFRAME_FILE(connector, parent, hdmi); + if (ret) + return ret; + + return 0; +} + +static void hdmi_debugfs_add(struct drm_connector *connector) +{ + struct dentry *dir; + + if (!(connector->connector_type == DRM_MODE_CONNECTOR_HDMIA || + connector->connector_type == DRM_MODE_CONNECTOR_HDMIB)) + return; + + dir = debugfs_create_dir("infoframes", connector->debugfs_entry); + if (IS_ERR(dir)) + return; + + create_hdmi_infoframe_files(connector, dir); +} + void drm_debugfs_connector_add(struct drm_connector *connector) { struct drm_device *dev = connector->dev; struct dentry *root; @@ -545,10 +653,12 @@ void drm_debugfs_connector_add(struct drm_connector *connector) /* max bpc */ debugfs_create_file("output_bpc", 0444, root, connector, &output_bpc_fops); + hdmi_debugfs_add(connector); + if (connector->funcs->debugfs_init) connector->funcs->debugfs_init(connector, root); } void drm_debugfs_connector_remove(struct drm_connector *connector)