mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Ripple <john.ripple@keysight.com>
To: dianders@chromium.org
Cc: Laurent.pinchart@ideasonboard.com, airlied@gmail.com,
	andrzej.hajda@intel.com, dri-devel@lists.freedesktop.org,
	jernej.skrabec@gmail.com, john.ripple@keysight.com,
	jonas@kwiboo.se, linux-kernel@vger.kernel.org,
	maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	neil.armstrong@linaro.org, rfoss@kernel.org, simona@ffwll.ch,
	tzimmermann@suse.de, blake.vermeer@keysight.com,
	matt_laubhan@keysight.com
Subject: [PATCH V2] drm/bridge: ti-sn65dsi86: Add support for DisplayPort mode  with HPD
Date: Mon,  8 Sep 2025 14:36:27 -0600	[thread overview]
Message-ID: <20250908203627.3750794-1-john.ripple@keysight.com> (raw)
In-Reply-To: <CAD=FV=WiORm+rawNZoinXFZWdt_yqKQfTFWCiBcJFyJKXj4spQ@mail.gmail.com>

Add support for DisplayPort to the bridge, which entails the following:
- Get and use an interrupt for HPD;
- Properly clear all status bits in the interrupt handler;

Signed-off-by: John Ripple <john.ripple@keysight.com>
---
V1 -> V2: Cleaned up coding style and addressed review comments

 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 93 +++++++++++++++++++++++++++
 1 file changed, 93 insertions(+)

diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
index ae0d08e5e960..ad0393212279 100644
--- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
+++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
@@ -106,10 +106,24 @@
 #define SN_PWM_EN_INV_REG			0xA5
 #define  SN_PWM_INV_MASK			BIT(0)
 #define  SN_PWM_EN_MASK				BIT(1)
+
+#define SN_IRQ_EN_REG				0xE0
+#define  IRQ_EN					BIT(0)
+
+#define SN_IRQ_EVENTS_EN_REG			0xE6
+#define  IRQ_HPD_EN				BIT(0)
+#define  HPD_INSERTION_EN			BIT(1)
+#define  HPD_REMOVAL_EN				BIT(2)
+#define  HPD_REPLUG_EN				BIT(3)
+#define  PLL_UNLOCK_EN				BIT(5)
+
 #define SN_AUX_CMD_STATUS_REG			0xF4
 #define  AUX_IRQ_STATUS_AUX_RPLY_TOUT		BIT(3)
 #define  AUX_IRQ_STATUS_AUX_SHORT		BIT(5)
 #define  AUX_IRQ_STATUS_NAT_I2C_FAIL		BIT(6)
+#define SN_IRQ_STATUS_REG			0xF5
+#define  HPD_REMOVAL_STATUS			BIT(2)
+#define  HPD_INSERTION_STATUS			BIT(1)
 
 #define MIN_DSI_CLK_FREQ_MHZ	40
 
@@ -221,6 +235,19 @@ static const struct regmap_config ti_sn65dsi86_regmap_config = {
 	.max_register = 0xFF,
 };
 
+static int ti_sn65dsi86_read(struct ti_sn65dsi86 *pdata, unsigned int reg,
+			     unsigned int *val)
+{
+	int ret;
+
+	ret = regmap_read(pdata->regmap, reg, val);
+	if (ret)
+		dev_err(pdata->dev, "fail to read raw reg %x: %d\n",
+			reg, ret);
+
+	return ret;
+}
+
 static int __maybe_unused ti_sn65dsi86_read_u16(struct ti_sn65dsi86 *pdata,
 						unsigned int reg, u16 *val)
 {
@@ -1219,12 +1246,28 @@ static void ti_sn_bridge_hpd_enable(struct drm_bridge *bridge)
 	 */
 
 	pm_runtime_get_sync(pdata->dev);
+
+	/* Enable HPD and PLL events. */
+	regmap_write(pdata->regmap, SN_IRQ_EVENTS_EN_REG,
+		     PLL_UNLOCK_EN |
+		     HPD_REPLUG_EN |
+		     HPD_REMOVAL_EN |
+		     HPD_INSERTION_EN |
+		     IRQ_HPD_EN);
+
+	regmap_update_bits(pdata->regmap, SN_IRQ_EN_REG, IRQ_EN,
+			   IRQ_EN);
 }
 
 static void ti_sn_bridge_hpd_disable(struct drm_bridge *bridge)
 {
 	struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge);
 
+	/* Disable HPD and PLL events. */
+	regmap_write(pdata->regmap, SN_IRQ_EVENTS_EN_REG, 0);
+
+	regmap_update_bits(pdata->regmap, SN_IRQ_EN_REG, IRQ_EN, 0);
+
 	pm_runtime_put_autosuspend(pdata->dev);
 }
 
@@ -1309,6 +1352,32 @@ static int ti_sn_bridge_parse_dsi_host(struct ti_sn65dsi86 *pdata)
 	return 0;
 }
 
+static irqreturn_t ti_sn_bridge_interrupt(int irq, void *private)
+{
+	struct ti_sn65dsi86 *pdata = private;
+	struct drm_device *dev = pdata->bridge.dev;
+	u32 status = 0;
+	bool hpd_event = false;
+	int ret = 0;
+
+	ret = ti_sn65dsi86_read(pdata, SN_IRQ_STATUS_REG, &status);
+	if (ret)
+		return ret;
+	hpd_event = status & (HPD_REMOVAL_STATUS | HPD_INSERTION_STATUS);
+	if (status) {
+		drm_dbg(dev, "(SN_IRQ_STATUS_REG = %#x)\n", status);
+		ret = regmap_write(pdata->regmap, SN_IRQ_STATUS_REG, status);
+		if (ret)
+			return ret;
+	}
+
+	/* Only send the HPD event if we are bound with a device. */
+	if (dev && hpd_event)
+		drm_kms_helper_hotplug_event(dev);
+
+	return IRQ_HANDLED;
+}
+
 static int ti_sn_bridge_probe(struct auxiliary_device *adev,
 			      const struct auxiliary_device_id *id)
 {
@@ -1971,6 +2040,30 @@ static int ti_sn65dsi86_probe(struct i2c_client *client)
 	if (strncmp(id_buf, "68ISD   ", ARRAY_SIZE(id_buf)))
 		return dev_err_probe(dev, -EOPNOTSUPP, "unsupported device id\n");
 
+	if (client->irq) {
+		enum drm_connector_status status;
+
+		ret = devm_request_threaded_irq(pdata->dev, client->irq, NULL,
+						ti_sn_bridge_interrupt,
+						IRQF_TRIGGER_RISING |
+						IRQF_TRIGGER_FALLING |
+						IRQF_ONESHOT,
+						"ti_sn65dsi86", pdata);
+		if (ret) {
+			return dev_err_probe(dev, ret,
+					     "failed to request interrupt\n");
+		}
+
+		/*
+		 * Cleaning status register at probe is needed because if the irq is
+		 * already high, the rising/falling condition will never occurs
+		 */
+		ret = ti_sn65dsi86_read(pdata, SN_IRQ_STATUS_REG, &status);
+		ret |= regmap_write(pdata->regmap, SN_IRQ_STATUS_REG, status);
+		if (ret)
+			pr_warn("Failed to clear IRQ initial state: %d\n", ret);
+	}
+
 	/*
 	 * Break ourselves up into a collection of aux devices. The only real
 	 * motiviation here is to solve the chicken-and-egg problem of probe

  reply	other threads:[~2025-09-08 20:48 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-20 15:24 [PATCH 1/2] " John Ripple
2025-08-20 15:24 ` [PATCH 2/2] drm/bridge: ti-sn65dsi86: break probe dependency loop John Ripple
2025-08-29 16:40   ` Doug Anderson
2025-09-01  7:00     ` Maxime Ripard
2025-09-02 16:22     ` John Ripple
2025-09-02 17:26       ` Doug Anderson
2025-08-29 16:40 ` [PATCH 1/2] drm/bridge: ti-sn65dsi86: Add support for DisplayPort mode with HPD Doug Anderson
2025-09-08 20:36   ` John Ripple [this message]
2025-09-09  0:11     ` [PATCH V2] " Doug Anderson
2025-09-09 19:36       ` John Ripple
2025-09-09 22:44         ` Doug Anderson
2025-09-10 18:33     ` [PATCH V3] " John Ripple
2025-09-10 20:48       ` Doug Anderson
2025-09-11 18:39         ` John Ripple
2025-09-11 23:25           ` Doug Anderson
2025-09-12 19:23             ` John Ripple
2025-09-12 19:24       ` [PATCH V4] " John Ripple
2025-09-12 20:02         ` Doug Anderson
2025-09-12 21:08         ` [PATCH V5] " John Ripple
2025-09-12 21:27           ` Doug Anderson
2025-09-15 16:50           ` [PATCH V6] " John Ripple
2025-09-15 17:33             ` Doug Anderson
2025-09-15 17:47               ` [PATCH V3] " John Ripple
2025-09-15 17:45             ` [PATCH V7] " John Ripple
2025-09-15 17:57               ` Doug Anderson
2025-09-23 15:23                 ` Doug Anderson
2025-09-16  5:46       ` [PATCH V3] " Dan Carpenter
2025-09-16 14:30         ` Doug Anderson

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=20250908203627.3750794-1-john.ripple@keysight.com \
    --to=john.ripple@keysight.com \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=airlied@gmail.com \
    --cc=andrzej.hajda@intel.com \
    --cc=blake.vermeer@keysight.com \
    --cc=dianders@chromium.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=jonas@kwiboo.se \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matt_laubhan@keysight.com \
    --cc=mripard@kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=rfoss@kernel.org \
    --cc=simona@ffwll.ch \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®