From mboxrd@z Thu Jan 1 00:00:00 1970 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 615E3CD6E57 for ; Tue, 2 Jun 2026 18:47:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C21F510F4CF; Tue, 2 Jun 2026 18:47:48 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; secure) header.d=grimler.se header.i=@grimler.se header.b="Wh7rVw1t"; dkim-atps=neutral Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) by gabe.freedesktop.org (Postfix) with ESMTPS id B01A910F4CE for ; Tue, 2 Jun 2026 18:47:47 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grimler.se; s=key1; t=1780425475; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WxMYC4T1LGG7DL25LkdKxvkXEaCcM5nAzX/5lfuA2Hc=; b=Wh7rVw1tYHNqYWPTzBP57ZGQzQKY5xTG+zrHYG3pqe+SfeghdLE3Somd74L5h2hsg99yE2 YRx4+4iF59XrFjiSKKnPVgXW81wNMxTrTf3rHXFFLsOxl7k2Covu6eKsmqRBOxDf0dQhsi lTD0UBAFPcsJDhCTfKiUZPI75tp8IXA= From: Henrik Grimler Date: Tue, 02 Jun 2026 20:36:50 +0200 Subject: [PATCH RESEND v4 3/3] drm/bridge: sii9234: use extcon cable detection logic to detect MHL MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260602-exynos4-sii9234-driver-v4-3-9b2fc38e104a@grimler.se> References: <20260602-exynos4-sii9234-driver-v4-0-9b2fc38e104a@grimler.se> In-Reply-To: <20260602-exynos4-sii9234-driver-v4-0-9b2fc38e104a@grimler.se> To: Dmitry Baryshkov , Marek Szyprowski , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, replicant@osuosl.org, linux-kernel@vger.kernel.org, Henrik Grimler X-Developer-Signature: v=1; a=openpgp-sha256; l=4934; i=henrik@grimler.se; h=from:subject:message-id; bh=J2VrdZZdHdrUSvVv2/0hRbTGcr86aySVkMiUCH39Ld4=; b=owEBbQGS/pANAwAKAbAHbkkLcWFrAcsmYgBqHyLv132KVuTm+PwuW9cyhgbWox+p1MI5l8ytv Lc6CdMzpuSJATMEAAEKAB0WIQQsfymul4kfZBmp4s2wB25JC3FhawUCah8i7wAKCRCwB25JC3Fh a85yB/9pljhUB9wE1+ub5xWBjYeuyWheF5e3cs9FG332jfHA7MNhxV3jAy6ph44Dt2NwElbxhZk MJdh6JkGO1EKm/L5euXIEJjZq2LUooo4zQJXIXjEzmEj7LunTbJbwq3l+d1Obyyg/eLxQokugWC a5kojU/pnRDnfLkUvxvbqaKonQWFkDhLd5MNJJQtlG1rC3idlEGwUD/tbgQJLe0ttuLhONv79na Zw9c4hXWAUXPUHFbCJF/N9gSpUh19fm04xTePQFEQqWbNWBzYIwMN7qVsc5ThmvTMlpEX98CAkF YfVyb5whq2UwCMmH6hZErjM6DH7RiP0kAFSshpa8M3LWZ0iT X-Developer-Key: i=henrik@grimler.se; a=openpgp; fpr=2C7F29AE97891F6419A9E2CDB0076E490B71616B X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To use MHL we currently need the MHL chip to be permanently on, which consumes unnecessary power. Let's use extcon attached to MUIC to enable the MHL chip only if it detects an MHL cable. Tested-by: Marek Szyprowski Signed-off-by: Henrik Grimler --- v4: collect tags v3: add missing return in error path, spotted by Marek Use depends on EXTCON || !EXTCON instead of select v2: add dependency on extcon. Issue reported by kernel test robot --- drivers/gpu/drm/bridge/Kconfig | 1 + drivers/gpu/drm/bridge/sii9234.c | 89 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig index 39385deafc68..a8343df2d424 100644 --- a/drivers/gpu/drm/bridge/Kconfig +++ b/drivers/gpu/drm/bridge/Kconfig @@ -310,6 +310,7 @@ config DRM_SII902X config DRM_SII9234 tristate "Silicon Image SII9234 HDMI/MHL bridge" depends on OF + depends on EXTCON || !EXTCON help Say Y here if you want support for the MHL interface. It is an I2C driver, that detects connection of MHL bridge diff --git a/drivers/gpu/drm/bridge/sii9234.c b/drivers/gpu/drm/bridge/sii9234.c index e43248e515b3..72c6aeed6e12 100644 --- a/drivers/gpu/drm/bridge/sii9234.c +++ b/drivers/gpu/drm/bridge/sii9234.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,7 @@ #include #include #include +#include #include #include @@ -170,8 +172,12 @@ struct sii9234 { struct drm_bridge bridge; struct device *dev; struct gpio_desc *gpio_reset; - int i2c_error; struct regulator_bulk_data supplies[4]; + struct extcon_dev *extcon; + struct notifier_block extcon_nb; + struct work_struct extcon_wq; + int cable_state; + int i2c_error; struct mutex lock; /* Protects fields below and device registers */ enum sii9234_state state; @@ -863,6 +869,70 @@ static int sii9234_init_resources(struct sii9234 *ctx, return 0; } +static void sii9234_extcon_work(struct work_struct *work) +{ + struct sii9234 *ctx = + container_of(work, struct sii9234, extcon_wq); + int state = extcon_get_state(ctx->extcon, EXTCON_DISP_MHL); + + if (state == ctx->cable_state) + return; + + ctx->cable_state = state; + + if (state > 0) + sii9234_cable_in(ctx); + else + sii9234_cable_out(ctx); +} + +static int sii9234_extcon_notifier(struct notifier_block *self, + unsigned long event, void *ptr) +{ + struct sii9234 *ctx = + container_of(self, struct sii9234, extcon_nb); + + schedule_work(&ctx->extcon_wq); + + return NOTIFY_DONE; +} + +static int sii9234_extcon_init(struct sii9234 *ctx) +{ + struct extcon_dev *edev; + struct device_node *musb, *muic; + int ret; + + /* Get micro-USB connector node */ + musb = of_graph_get_remote_node(ctx->dev->of_node, 1, -1); + /* Then get micro-USB Interface Controller node */ + muic = of_get_next_parent(musb); + + if (!muic) { + dev_info(ctx->dev, + "no extcon found, switching to 'always on' mode\n"); + return 0; + } + + edev = extcon_find_edev_by_node(muic); + of_node_put(muic); + if (IS_ERR(edev)) { + return dev_err_probe(ctx->dev, PTR_ERR(edev), + "invalid or missing extcon\n"); + } + + ctx->extcon = edev; + ctx->extcon_nb.notifier_call = sii9234_extcon_notifier; + INIT_WORK(&ctx->extcon_wq, sii9234_extcon_work); + ret = extcon_register_notifier(edev, EXTCON_DISP_MHL, &ctx->extcon_nb); + if (ret) { + dev_err(ctx->dev, "failed to register notifier for MHL\n"); + return ret; + } + + return 0; +} + static enum drm_mode_status sii9234_mode_valid(struct drm_bridge *bridge, const struct drm_display_info *info, const struct drm_display_mode *mode) @@ -915,12 +985,17 @@ static int sii9234_probe(struct i2c_client *client) if (ret < 0) return ret; + ret = sii9234_extcon_init(ctx); + if (ret < 0) + return ret; + i2c_set_clientdata(client, ctx); ctx->bridge.of_node = dev->of_node; drm_bridge_add(&ctx->bridge); - sii9234_cable_in(ctx); + if (!ctx->extcon) + sii9234_cable_in(ctx); return 0; } @@ -929,7 +1004,15 @@ static void sii9234_remove(struct i2c_client *client) { struct sii9234 *ctx = i2c_get_clientdata(client); - sii9234_cable_out(ctx); + if (ctx->extcon) { + extcon_unregister_notifier(ctx->extcon, EXTCON_DISP_MHL, + &ctx->extcon_nb); + flush_work(&ctx->extcon_wq); + if (ctx->cable_state > 0) + sii9234_cable_out(ctx); + } else { + sii9234_cable_out(ctx); + } drm_bridge_remove(&ctx->bridge); } -- 2.54.0