linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] usb: typec: altmodes/displayport: add irq_hpd to sysfs
@ 2025-06-23 20:49 RD Babiera
  2025-06-24  9:23 ` Heikki Krogerus
  0 siblings, 1 reply; 2+ messages in thread
From: RD Babiera @ 2025-06-23 20:49 UTC (permalink / raw)
  Cc: heikki.krogerus, badhri, gregkh, linux-usb, linux-kernel,
	RD Babiera

Add irq_hpd sysfs node to displayport driver. This allows the userspace
to subscribe to irq events similar to how it can subscribe to changes in
hpd.

irq_hpd is read only and returns the number of irq events generated since
driver probe. pending_irq_hpd is added so that a sysfs_emit can be
generated if the HPD high event belonging to the same status message
is delayed until a successful configuration.

Signed-off-by: RD Babiera <rdbabiera@google.com>
Reviewed-by: Badhri Jagan Sridharan <badhri@google.com>
---
Changes since v1:
* fixed bracket styling error
---
 .../testing/sysfs-driver-typec-displayport    | 10 +++++++
 drivers/usb/typec/altmodes/displayport.c      | 28 +++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-driver-typec-displayport b/Documentation/ABI/testing/sysfs-driver-typec-displayport
index 256c87c5219a..314acd54e13e 100644
--- a/Documentation/ABI/testing/sysfs-driver-typec-displayport
+++ b/Documentation/ABI/testing/sysfs-driver-typec-displayport
@@ -62,3 +62,13 @@ Description:
 			     by VESA DisplayPort Alt Mode on USB Type-C Standard.
 			- 0 when HPD’s logical state is low (HPD_Low) as defined by
 			     VESA DisplayPort Alt Mode on USB Type-C Standard.
+
+What:		/sys/bus/typec/devices/.../displayport/irq_hpd
+Date:		June 2025
+Contact:	RD Babiera <rdbabiera@google.com>
+Description:
+		IRQ_HPD events are sent over the USB PD protocol in Status Update and
+		Attention messages. IRQ_HPD can only be asserted when HPD is high,
+		and is asserted when an IRQ_HPD has been issued since the last Status
+		Update. This is a read only node that returns the number of IRQ events
+		raised in the driver's lifetime.
diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
index b09b58d7311d..7f9f1f98f450 100644
--- a/drivers/usb/typec/altmodes/displayport.c
+++ b/drivers/usb/typec/altmodes/displayport.c
@@ -65,6 +65,13 @@ struct dp_altmode {
 	enum dp_state state;
 	bool hpd;
 	bool pending_hpd;
+	u32 irq_hpd_count;
+	/*
+	 * hpd is mandatory for irq_hpd assertion, so irq_hpd also needs its own pending flag if
+	 * both hpd and irq_hpd are asserted in the first Status Update before the pin assignment
+	 * is configured.
+	 */
+	bool pending_irq_hpd;
 
 	struct mutex lock; /* device lock */
 	struct work_struct work;
@@ -151,6 +158,7 @@ static int dp_altmode_status_update(struct dp_altmode *dp)
 {
 	bool configured = !!DP_CONF_GET_PIN_ASSIGN(dp->data.conf);
 	bool hpd = !!(dp->data.status & DP_STATUS_HPD_STATE);
+	bool irq_hpd = !!(dp->data.status & DP_STATUS_IRQ_HPD);
 	u8 con = DP_STATUS_CONNECTION(dp->data.status);
 	int ret = 0;
 
@@ -170,6 +178,8 @@ static int dp_altmode_status_update(struct dp_altmode *dp)
 				dp->hpd = hpd;
 				dp->pending_hpd = true;
 			}
+			if (dp->hpd && dp->pending_hpd && irq_hpd)
+				dp->pending_irq_hpd = true;
 		}
 	} else {
 		drm_connector_oob_hotplug_event(dp->connector_fwnode,
@@ -177,6 +187,10 @@ static int dp_altmode_status_update(struct dp_altmode *dp)
 						      connector_status_disconnected);
 		dp->hpd = hpd;
 		sysfs_notify(&dp->alt->dev.kobj, "displayport", "hpd");
+		if (hpd && irq_hpd) {
+			dp->irq_hpd_count++;
+			sysfs_notify(&dp->alt->dev.kobj, "displayport", "irq_hpd");
+		}
 	}
 
 	return ret;
@@ -196,6 +210,11 @@ static int dp_altmode_configured(struct dp_altmode *dp)
 						connector_status_connected);
 		sysfs_notify(&dp->alt->dev.kobj, "displayport", "hpd");
 		dp->pending_hpd = false;
+		if (dp->pending_irq_hpd) {
+			dp->irq_hpd_count++;
+			sysfs_notify(&dp->alt->dev.kobj, "displayport", "irq_hpd");
+			dp->pending_irq_hpd = false;
+		}
 	}
 
 	return dp_altmode_notify(dp);
@@ -707,10 +726,19 @@ static ssize_t hpd_show(struct device *dev, struct device_attribute *attr, char
 }
 static DEVICE_ATTR_RO(hpd);
 
+static ssize_t irq_hpd_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct dp_altmode *dp = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%d\n", dp->irq_hpd_count);
+}
+static DEVICE_ATTR_RO(irq_hpd);
+
 static struct attribute *displayport_attrs[] = {
 	&dev_attr_configuration.attr,
 	&dev_attr_pin_assignment.attr,
 	&dev_attr_hpd.attr,
+	&dev_attr_irq_hpd.attr,
 	NULL
 };
 

base-commit: e04c78d86a9699d136910cfc0bdcf01087e3267e
-- 
2.50.0.rc2.761.g2dc52ea45b-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] usb: typec: altmodes/displayport: add irq_hpd to sysfs
  2025-06-23 20:49 [PATCH v2] usb: typec: altmodes/displayport: add irq_hpd to sysfs RD Babiera
@ 2025-06-24  9:23 ` Heikki Krogerus
  0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2025-06-24  9:23 UTC (permalink / raw)
  To: RD Babiera; +Cc: badhri, gregkh, linux-usb, linux-kernel

On Mon, Jun 23, 2025 at 08:49:45PM +0000, RD Babiera wrote:
> Add irq_hpd sysfs node to displayport driver. This allows the userspace
> to subscribe to irq events similar to how it can subscribe to changes in
> hpd.
> 
> irq_hpd is read only and returns the number of irq events generated since
> driver probe. pending_irq_hpd is added so that a sysfs_emit can be
> generated if the HPD high event belonging to the same status message
> is delayed until a successful configuration.
> 
> Signed-off-by: RD Babiera <rdbabiera@google.com>
> Reviewed-by: Badhri Jagan Sridharan <badhri@google.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> Changes since v1:
> * fixed bracket styling error
> ---
>  .../testing/sysfs-driver-typec-displayport    | 10 +++++++
>  drivers/usb/typec/altmodes/displayport.c      | 28 +++++++++++++++++++
>  2 files changed, 38 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-driver-typec-displayport b/Documentation/ABI/testing/sysfs-driver-typec-displayport
> index 256c87c5219a..314acd54e13e 100644
> --- a/Documentation/ABI/testing/sysfs-driver-typec-displayport
> +++ b/Documentation/ABI/testing/sysfs-driver-typec-displayport
> @@ -62,3 +62,13 @@ Description:
>  			     by VESA DisplayPort Alt Mode on USB Type-C Standard.
>  			- 0 when HPD’s logical state is low (HPD_Low) as defined by
>  			     VESA DisplayPort Alt Mode on USB Type-C Standard.
> +
> +What:		/sys/bus/typec/devices/.../displayport/irq_hpd
> +Date:		June 2025
> +Contact:	RD Babiera <rdbabiera@google.com>
> +Description:
> +		IRQ_HPD events are sent over the USB PD protocol in Status Update and
> +		Attention messages. IRQ_HPD can only be asserted when HPD is high,
> +		and is asserted when an IRQ_HPD has been issued since the last Status
> +		Update. This is a read only node that returns the number of IRQ events
> +		raised in the driver's lifetime.
> diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
> index b09b58d7311d..7f9f1f98f450 100644
> --- a/drivers/usb/typec/altmodes/displayport.c
> +++ b/drivers/usb/typec/altmodes/displayport.c
> @@ -65,6 +65,13 @@ struct dp_altmode {
>  	enum dp_state state;
>  	bool hpd;
>  	bool pending_hpd;
> +	u32 irq_hpd_count;
> +	/*
> +	 * hpd is mandatory for irq_hpd assertion, so irq_hpd also needs its own pending flag if
> +	 * both hpd and irq_hpd are asserted in the first Status Update before the pin assignment
> +	 * is configured.
> +	 */
> +	bool pending_irq_hpd;
>  
>  	struct mutex lock; /* device lock */
>  	struct work_struct work;
> @@ -151,6 +158,7 @@ static int dp_altmode_status_update(struct dp_altmode *dp)
>  {
>  	bool configured = !!DP_CONF_GET_PIN_ASSIGN(dp->data.conf);
>  	bool hpd = !!(dp->data.status & DP_STATUS_HPD_STATE);
> +	bool irq_hpd = !!(dp->data.status & DP_STATUS_IRQ_HPD);
>  	u8 con = DP_STATUS_CONNECTION(dp->data.status);
>  	int ret = 0;
>  
> @@ -170,6 +178,8 @@ static int dp_altmode_status_update(struct dp_altmode *dp)
>  				dp->hpd = hpd;
>  				dp->pending_hpd = true;
>  			}
> +			if (dp->hpd && dp->pending_hpd && irq_hpd)
> +				dp->pending_irq_hpd = true;
>  		}
>  	} else {
>  		drm_connector_oob_hotplug_event(dp->connector_fwnode,
> @@ -177,6 +187,10 @@ static int dp_altmode_status_update(struct dp_altmode *dp)
>  						      connector_status_disconnected);
>  		dp->hpd = hpd;
>  		sysfs_notify(&dp->alt->dev.kobj, "displayport", "hpd");
> +		if (hpd && irq_hpd) {
> +			dp->irq_hpd_count++;
> +			sysfs_notify(&dp->alt->dev.kobj, "displayport", "irq_hpd");
> +		}
>  	}
>  
>  	return ret;
> @@ -196,6 +210,11 @@ static int dp_altmode_configured(struct dp_altmode *dp)
>  						connector_status_connected);
>  		sysfs_notify(&dp->alt->dev.kobj, "displayport", "hpd");
>  		dp->pending_hpd = false;
> +		if (dp->pending_irq_hpd) {
> +			dp->irq_hpd_count++;
> +			sysfs_notify(&dp->alt->dev.kobj, "displayport", "irq_hpd");
> +			dp->pending_irq_hpd = false;
> +		}
>  	}
>  
>  	return dp_altmode_notify(dp);
> @@ -707,10 +726,19 @@ static ssize_t hpd_show(struct device *dev, struct device_attribute *attr, char
>  }
>  static DEVICE_ATTR_RO(hpd);
>  
> +static ssize_t irq_hpd_show(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> +	struct dp_altmode *dp = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%d\n", dp->irq_hpd_count);
> +}
> +static DEVICE_ATTR_RO(irq_hpd);
> +
>  static struct attribute *displayport_attrs[] = {
>  	&dev_attr_configuration.attr,
>  	&dev_attr_pin_assignment.attr,
>  	&dev_attr_hpd.attr,
> +	&dev_attr_irq_hpd.attr,
>  	NULL
>  };
>  
> 
> base-commit: e04c78d86a9699d136910cfc0bdcf01087e3267e
> -- 
> 2.50.0.rc2.761.g2dc52ea45b-goog

-- 
heikki

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-24  9:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-23 20:49 [PATCH v2] usb: typec: altmodes/displayport: add irq_hpd to sysfs RD Babiera
2025-06-24  9:23 ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).