[PATCH 2/2] platform/chrome: cros_ec_typec: Expose AP_MODE_ENTRY feature state via sysfs

From: Andrei Kuchynski
Date: Mon Feb 03 2025 - 08:00:53 EST


This adds sysfs attribute /sys/class/chromeos/cros_ec/ap_mode_entry
to expose the status of the AP_MODE_ENTRY feature. This attribute
indicate whether the EC requires direction from the Application
Processor (AP) before entering Type-C alternate modes or USB4 mode.
This allows user-space applications to easily determine if the AP needs
to be involved in mode entry.

Signed-off-by: Andrei Kuchynski <akuchynski@xxxxxxxxxxxx>
---
Documentation/ABI/testing/sysfs-class-chromeos | 7 +++++++
drivers/platform/chrome/cros_ec_sysfs.c | 15 ++++++++++++++-
2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/Documentation/ABI/testing/sysfs-class-chromeos b/Documentation/ABI/testing/sysfs-class-chromeos
index e067dbdab170..7fa5be6cc774 100644
--- a/Documentation/ABI/testing/sysfs-class-chromeos
+++ b/Documentation/ABI/testing/sysfs-class-chromeos
@@ -44,3 +44,10 @@ Description:
- "SAFE": DP is in safe mode
- "TBT": TBT enabled
- "USB4": USB4 enabled
+
+What: /sys/class/chromeos/cros_ec/ap_mode_entry
+Date: February 2025
+Description:
+ Show if the AP mode entry EC feature is supported.
+ It indicates whether the EC waits for direction from the AP
+ to enter Type-C altmodes or USB4 mode.
diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c
index 93e9ed87249c..f22e9523da3e 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -345,6 +345,16 @@ static ssize_t usbpdmuxinfo_show(struct device *dev,
return count ? : -EIO;
}

+static ssize_t ap_mode_entry_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct cros_ec_dev *ec = to_cros_ec_dev(dev);
+ const bool ap_driven_altmode = cros_ec_check_features(
+ ec, EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY);
+
+ return sysfs_emit(buf, "%s\n", ap_driven_altmode ? "yes" : "no");
+}
+
/* Module initialization */

static DEVICE_ATTR_RW(reboot);
@@ -352,6 +362,7 @@ static DEVICE_ATTR_RO(version);
static DEVICE_ATTR_RO(flashinfo);
static DEVICE_ATTR_RW(kb_wake_angle);
static DEVICE_ATTR_RO(usbpdmuxinfo);
+static DEVICE_ATTR_RO(ap_mode_entry);

static struct attribute *__ec_attrs[] = {
&dev_attr_kb_wake_angle.attr,
@@ -359,6 +370,7 @@ static struct attribute *__ec_attrs[] = {
&dev_attr_version.attr,
&dev_attr_flashinfo.attr,
&dev_attr_usbpdmuxinfo.attr,
+ &dev_attr_ap_mode_entry.attr,
NULL,
};

@@ -371,7 +383,8 @@ static umode_t cros_ec_ctrl_visible(struct kobject *kobj,
if (a == &dev_attr_kb_wake_angle.attr && !ec->has_kb_wake_angle)
return 0;

- if (a == &dev_attr_usbpdmuxinfo.attr) {
+ if (a == &dev_attr_usbpdmuxinfo.attr ||
+ a == &dev_attr_ap_mode_entry.attr) {
struct cros_ec_platform *ec_platform = dev_get_platdata(ec->dev);

if (strcmp(ec_platform->ec_name, CROS_EC_DEV_NAME))
--
2.48.1.362.g079036d154-goog