[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ac222017-d4e2-4fa7-beed-cc6b73042a73@samsung.com>
Date: Mon, 25 Aug 2025 16:16:50 +0200
From: Marek Szyprowski <m.szyprowski@...sung.com>
To: Henrik Grimler <henrik@...mler.se>, Dmitry Baryshkov
<dmitry.baryshkov@....qualcomm.com>, Andrzej Hajda
<andrzej.hajda@...el.com>, Neil Armstrong <neil.armstrong@...aro.org>,
Robert Foss <rfoss@...nel.org>, Laurent Pinchart
<Laurent.pinchart@...asonboard.com>, Jonas Karlman <jonas@...boo.se>, Jernej
Skrabec <jernej.skrabec@...il.com>, Maarten Lankhorst
<maarten.lankhorst@...ux.intel.com>, Maxime Ripard <mripard@...nel.org>,
Thomas Zimmermann <tzimmermann@...e.de>, David Airlie <airlied@...il.com>,
Simona Vetter <simona@...ll.ch>
Cc: dri-devel@...ts.freedesktop.org, linux-samsung-soc@...r.kernel.org,
~postmarketos/upstreaming@...ts.sr.ht, replicant@...osl.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 3/3] drm/bridge: sii9234: use extcon cable detection
logic to detect MHL
On 24.08.2025 13:16, Henrik Grimler wrote:
> 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.
>
> Signed-off-by: Henrik Grimler <henrik@...mler.se>
Tested-by: Marek Szyprowski <m.szyprowski@...sung.com>
On Trats2 board the status of HDMI connector is no properly reported as
disconnected when no cable is attached.
> ---
> 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
> <lkp@...el.com>
> ---
> 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 6945029b35929a8e30054ac1a699bd88ab0487f2..bf73f8d900ebd8da9fa3444c0b2d9bfc901ea773 100644
> --- a/drivers/gpu/drm/bridge/Kconfig
> +++ b/drivers/gpu/drm/bridge/Kconfig
> @@ -304,6 +304,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 e43248e515b3dcdde043997288d61f738417b8f0..72c6aeed6e12e43df3b052dadc0990f1609253f0 100644
> --- a/drivers/gpu/drm/bridge/sii9234.c
> +++ b/drivers/gpu/drm/bridge/sii9234.c
> @@ -19,6 +19,7 @@
>
> #include <linux/delay.h>
> #include <linux/err.h>
> +#include <linux/extcon.h>
> #include <linux/gpio/consumer.h>
> #include <linux/i2c.h>
> #include <linux/interrupt.h>
> @@ -26,6 +27,7 @@
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/mutex.h>
> +#include <linux/of_graph.h>
> #include <linux/regulator/consumer.h>
> #include <linux/slab.h>
>
> @@ -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);
> }
>
>
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
Powered by blists - more mailing lists