From patchwork Wed Jul 22 09:11:48 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Frattaroli X-Patchwork-Id: 2710 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mxe881.netcup.net (Postfix) with ESMTPS id 98F7F1C0BC1 for ; Wed, 22 Jul 2026 11:26:35 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=collabora.com; spf=pass (sender IP is 104.64.211.4) smtp.mailfrom=linux-sunxi+bounces-24582-noreply=patchwork.local@lists.linux.dev smtp.helo=sin.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 104.64.211.4 as permitted sender) client-ip=104.64.211.4; envelope-from=linux-sunxi+bounces-24582-noreply=patchwork.local@lists.linux.dev; helo=sin.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sin.lore.kernel.org (Postfix) with ESMTP id 743D33095591 for ; Wed, 22 Jul 2026 09:13:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F325379960; Wed, 22 Jul 2026 09:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b="DOSsKexY" X-Original-To: linux-sunxi@lists.linux.dev Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8097446D08E for ; Wed, 22 Jul 2026 09:12:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784711573; cv=pass; b=XfNddSRKEXPXeGFiekhWCy0pqL6MxWjIqYd5sQgURZ2oLoSwxS2BbaHHfjAlD5lScvVmT5NODBBpw45MyPTTaLVfhQPPKokReFqZsoLQ8vqdtY7Lciwunf7/A0GP36hCITBfVfC3KpGNSTm9LhBrkBdFpDtf55Hu6HLmm2kQ09c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784711573; c=relaxed/simple; bh=+DjN6ByW41aI3rhNO9UpSgapQLQ6r+kTqv6ZsZzBcbM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W83jC5nf0pQbtq3qTMlIfT5c/lUQjIOBsfRLhgCZx798RQ2I6ZJ7iWB2GAO8bvl/yPYEmfN0CsIIHHP7tKzc5OqPk5JYoWf2CJnFX9Io2ermSHBzXBvjx1o25Ac7XL1z+ghfcO4pstLtC7ymraQ9iNgpp9zOSZDNm3NeWpXzpkc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b=DOSsKexY; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com ARC-Seal: i=1; a=rsa-sha256; t=1784711543; cv=none; d=zohomail.com; s=zohoarc; b=V8zLT8/LivfLRz9xb+mbi8Ln3CrvLNF791HCyAQdkolEqISCDqwhZjc1fj4KXPXSQ03cCXluqHV7VoiDKxS+oamOVW2uT1SVh0vQeepFcSiU2+DZqoCY5wxOQTJ/uF0zIkDU1qC6NKll7rz/Vh9N8fpzsgGtxJHyVWPsJUywmXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784711543; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=t50jIyY6JuQksTKR2lD2BGO6e64BxG6DBdZAx/JaL/A=; b=SmGFh7zF+WHQmBzNRiAZe6nA6P9PMJ7L/AMZzV3+QB0zRLBXN1xtxc8mVFxzcVPDxUoxN99YHfDpCpud2KdAfMMUhFVSnleoBmltsP8JTiiwVlZU/464HTrBh4hj5kPXOzSJgUKKhFJX8W8P0X5SqAwDzudbUgr4tBqxy7Ap04w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1784711542; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=t50jIyY6JuQksTKR2lD2BGO6e64BxG6DBdZAx/JaL/A=; b=DOSsKexYWlEed4CaROGdyxGGES0KCkHaSirYawO3yJhvyeNrFGuw8JL0iFUhycAm Fp+DOiMOfoP1X9MebxxiiXR2N4Q1hBf+6Omd4aW1rJE8VHTP9aedj9b32URXAmPrmOS zN1Kms26b0ldB4UW/KtLyOCfEHkQgkeUBHiKmHdY= Received: by mx.zohomail.com with SMTPS id 17847115402831006.1481549752529; Wed, 22 Jul 2026 02:12:20 -0700 (PDT) From: Nicolas Frattaroli Date: Wed, 22 Jul 2026 11:11:48 +0200 Subject: [PATCH v8 2/5] drm/scdc-helper: Add scdc_status debugfs entry Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20260722-scdc-link-health-v8-2-cd1dacbb85d9@collabora.com> References: <20260722-scdc-link-health-v8-0-cd1dacbb85d9@collabora.com> In-Reply-To: <20260722-scdc-link-health-v8-0-cd1dacbb85d9@collabora.com> To: Jani Nikula , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Luca Ceresoli , Daniel Stone , Hans Verkuil , Chen-Yu Tsai , Samuel Holland , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Canal?= , Raspberry Pi Kernel Maintenance Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Nicolas Frattaroli X-Mailer: b4 0.15.2 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= SCDC provides status information on the current display link. At the very least, it may be useful to expose this info through debugfs. Add a debugfs entry for it under the connector, which displays a few more details parsed out of the SCDC registers. A new drm_scdc_debugfs_init function can be called by the connector implementation to initialise the debugfs file. Signed-off-by: Nicolas Frattaroli --- drivers/gpu/drm/display/drm_scdc_helper.c | 186 ++++++++++++++++++++++++++++++ include/drm/display/drm_scdc_helper.h | 32 +++++ 2 files changed, 218 insertions(+) diff --git a/drivers/gpu/drm/display/drm_scdc_helper.c b/drivers/gpu/drm/display/drm_scdc_helper.c index 8403f2390ab6..97256b272329 100644 --- a/drivers/gpu/drm/display/drm_scdc_helper.c +++ b/drivers/gpu/drm/display/drm_scdc_helper.c @@ -24,7 +24,9 @@ #include #include #include +#include #include +#include #include #include @@ -276,3 +278,187 @@ bool drm_scdc_set_high_tmds_clock_ratio(struct drm_connector *connector, return true; } EXPORT_SYMBOL(drm_scdc_set_high_tmds_clock_ratio); + +static void +drm_scdc_parse_status0_flags(u8 val, struct drm_scdc_status_flags *flags) +{ + flags->clock_detected = val & SCDC_CLOCK_DETECT; + flags->ch0_locked = val & SCDC_CH0_LOCK; + flags->ch1_locked = val & SCDC_CH1_LOCK; + flags->ch2_locked = val & SCDC_CH2_LOCK; +} + +static int drm_scdc_parse_error_counters(const u8 scdc[256], u16 counter[3]) +{ + u8 sum = 0; + int i; + + for (i = SCDC_ERR_DET_0_L; i <= SCDC_ERR_DET_CHECKSUM ; i++) + sum = wrapping_add(u8, sum, scdc[i]); + + if (sum) + return -EPROTO; + + for (i = 0; i < 3; i++) { + if (scdc[SCDC_ERR_DET_0_H + i * 2] & SCDC_CHANNEL_VALID) + counter[i] = (scdc[SCDC_ERR_DET_0_H + i * 2] & + ~SCDC_CHANNEL_VALID) << 8 | + scdc[SCDC_ERR_DET_0_L + i * 2]; + else + counter[i] = 0; + } + + return 0; +} + +/** + * drm_scdc_read_state - Update state from SCDC + * @connector: pointer to a &struct drm_connector on which to operate on + * @state: pointer to a &struct drm_scdc_state to fill + * + * Reads the entire 256 byte SCDC state and parses it. + * + * Returns: %0 on success, negative errno on failure. + */ +int drm_scdc_read_state(struct drm_connector *connector, struct drm_scdc_state *state) +{ + struct i2c_adapter *ddc; + struct drm_scdc *scdc; + u8 *buf = state->scdc; + int ret; + + if (!state || !connector) + return -ENODEV; + + scdc = &connector->display_info.hdmi.scdc; + ddc = connector->ddc; + + if (!scdc->supported || !ddc) + return -EOPNOTSUPP; + + /* Read in 128-byte chunks, to work around DP<->HDMI converters with issues. */ + ret = drm_scdc_read(ddc, 0, buf, 128); + if (ret) + return ret; + + ret = drm_scdc_read(ddc, 128, &buf[128], 128); + if (ret) + return ret; + + state->scrambling_enabled = buf[SCDC_TMDS_CONFIG] & SCDC_SCRAMBLING_ENABLE; + state->tmds_bclk_x40 = buf[SCDC_TMDS_CONFIG] & SCDC_TMDS_BIT_CLOCK_RATIO_BY_40; + + state->scrambling_detected = buf[SCDC_SCRAMBLER_STATUS] & SCDC_SCRAMBLING_STATUS; + + drm_scdc_parse_status0_flags(buf[SCDC_STATUS_FLAGS_0], &state->stf); + ret = drm_scdc_parse_error_counters(buf, state->error_count); + if (ret) + return ret; + + return 0; +} +EXPORT_SYMBOL(drm_scdc_read_state); + +#define scdc_print_str(_f, key, s) \ + (seq_printf((_f), "%-30s: %s\n", (key), (s))) +#define scdc_print_flag(_f, key, val) \ + (scdc_print_str((_f), (key), str_yes_no((val)))) +#define scdc_print_dec(_f, key, val) \ + (seq_printf((_f), "%-30s: %d\n", (key), (val))) + +static int scdc_status_show(struct seq_file *m, void *data) +{ + struct drm_connector *connector = m->private; + struct drm_scdc *scdc = &connector->display_info.hdmi.scdc; + struct drm_scdc_state *st; + int i, ret; + + drm_connector_get(connector); + + ret = mutex_lock_interruptible(&connector->dev->mode_config.mutex); + if (ret) + goto err_conn_put; + + if (connector->status != connector_status_connected) { + ret = -ENODEV; + goto err_conn_put; + } + + if (scdc->supported) { + st = kzalloc_obj(*st); + if (!st) { + ret = -ENOMEM; + goto err_unlock; + } + ret = drm_scdc_read_state(connector, st); + if (ret) + goto err_free_state; + + for (i = 0; i < ARRAY_SIZE(st->scdc); i += 16) + seq_printf(m, "%*ph\n", 16, &st->scdc[i]); + + seq_puts(m, "\n----------------\n\n"); + } + + scdc_print_flag(m, "SCDC Supported", scdc->supported); + if (!scdc->supported) { + ret = 0; + goto err_unlock; + } + + scdc_print_flag(m, "Sink Read Request Capable", scdc->read_request); + scdc_print_flag(m, "Scrambling Supported", scdc->scrambling.supported); + scdc_print_flag(m, "Low Rate Scrambling Supported", scdc->scrambling.low_rates); + + mutex_unlock(&connector->dev->mode_config.mutex); + + drm_connector_put(connector); + + scdc_print_flag(m, "Scrambling Enabled", st->scrambling_enabled); + scdc_print_flag(m, "Scrambling Detected", st->scrambling_detected); + + if (st->tmds_bclk_x40) + scdc_print_str(m, "TMDS Bit Clock Ratio", "1/40"); + else + scdc_print_str(m, "TMDS Bit Clock Ratio", "1/10"); + + scdc_print_flag(m, "Clock Detected", st->stf.clock_detected); + scdc_print_flag(m, "Channel 0 Locked", st->stf.ch0_locked); + scdc_print_flag(m, "Channel 1 Locked", st->stf.ch1_locked); + scdc_print_flag(m, "Channel 2 Locked", st->stf.ch2_locked); + + scdc_print_dec(m, "Channel 0 Errors", st->error_count[0]); + scdc_print_dec(m, "Channel 1 Errors", st->error_count[1]); + scdc_print_dec(m, "Channel 2 Errors", st->error_count[2]); + + kfree(st); + + return 0; + +err_free_state: + kfree(st); +err_unlock: + mutex_unlock(&connector->dev->mode_config.mutex); +err_conn_put: + drm_connector_put(connector); + + return ret; +} +DEFINE_SHOW_ATTRIBUTE(scdc_status); + +/** + * drm_scdc_debugfs_init - Initialize scdc files in connector debugfs + * @connector: pointer to &struct drm_connector to operate on + * @root: debugfs &struct dentry for the debugfs root of @connector + * + * Creates SCDC-related debugfs files for @connector. Must be called after + * @root is already created. + */ +void drm_scdc_debugfs_init(struct drm_connector *connector, struct dentry *root) +{ + if (!root || !connector) + return; + + debugfs_create_file("scdc_status", 0444, root, connector, &scdc_status_fops); +} +EXPORT_SYMBOL(drm_scdc_debugfs_init); diff --git a/include/drm/display/drm_scdc_helper.h b/include/drm/display/drm_scdc_helper.h index e9ccaeba56dd..e0b79d79e1ff 100644 --- a/include/drm/display/drm_scdc_helper.h +++ b/include/drm/display/drm_scdc_helper.h @@ -30,6 +30,34 @@ struct drm_connector; struct i2c_adapter; +struct dentry; + +struct drm_scdc_status_flags { + /* Status Register 0 */ + bool clock_detected; + bool ch0_locked; + bool ch1_locked; + bool ch2_locked; +}; + +struct drm_scdc_state { + /** @stf: contents of the status flag registers */ + struct drm_scdc_status_flags stf; + /** @scramling_enabled: true if TMDS scrambling is on */ + bool scrambling_enabled; + /** @scrambling_detected: true if the sink actually detected scrambling */ + bool scrambling_detected; + /** + * @tmds_bclk_x40: true if TMDS bit period is 1/40th of the TMDS + * clock period, false if it's 1/10th of the clock period. + */ + bool tmds_bclk_x40; + /** @error_count: character error counts for each channel */ + u16 error_count[3]; + + /** @scdc: raw SCDC data buffer */ + u8 scdc[256]; +}; int drm_scdc_read(struct i2c_adapter *adapter, u8 offset, void *buffer, size_t size); @@ -77,4 +105,8 @@ bool drm_scdc_get_scrambling_status(struct drm_connector *connector); bool drm_scdc_set_scrambling(struct drm_connector *connector, bool enable); bool drm_scdc_set_high_tmds_clock_ratio(struct drm_connector *connector, bool set); +int drm_scdc_read_state(struct drm_connector *connector, + struct drm_scdc_state *state); +void drm_scdc_debugfs_init(struct drm_connector *connector, struct dentry *root); + #endif