Skip to content

Commit e6a3215

Browse files
Andrei KuchynskiTzung-Bi Shih
authored andcommitted
platform/chrome: cros_ec_sysfs: Expose PD mux status
This adds sysfs attribute /sys/class/chromeos/cros_ec/usbpdmuxinfo to expose the PD mux status for each Type-C port. This allows user-space applications to easily determine the current mux state without using ioctls. Signed-off-by: Andrei Kuchynski <akuchynski@chromium.org> Link: https://lore.kernel.org/r/20250203125947.2701106-2-akuchynski@chromium.org Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
1 parent d83c45a commit e6a3215

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

Documentation/ABI/testing/sysfs-class-chromeos

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,16 @@ Date: August 2015
3131
KernelVersion: 4.2
3232
Description:
3333
Show the information about the EC software and hardware.
34+
35+
What: /sys/class/chromeos/cros_ec/usbpdmuxinfo
36+
Date: February 2025
37+
Description:
38+
Show PD mux status for each typec port with following flags:
39+
- "USB": USB connected
40+
- "DP": DP connected
41+
- "POLARITY": CC line Polarity inverted
42+
- "HPD_IRQ": Hot Plug Detect interrupt is asserted
43+
- "HPD_LVL": Hot Plug Detect level is asserted
44+
- "SAFE": DP is in safe mode
45+
- "TBT": TBT enabled
46+
- "USB4": USB4 enabled

drivers/platform/chrome/cros_ec_sysfs.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,69 @@ static ssize_t kb_wake_angle_store(struct device *dev,
296296
return count;
297297
}
298298

299+
static ssize_t usbpdmuxinfo_show(struct device *dev,
300+
struct device_attribute *attr,
301+
char *buf)
302+
{
303+
struct cros_ec_dev *ec = to_cros_ec_dev(dev);
304+
ssize_t count = 0;
305+
struct ec_response_usb_pd_ports resp_pd_ports;
306+
int ret;
307+
int i;
308+
309+
ret = cros_ec_cmd(ec->ec_dev, 0, EC_CMD_USB_PD_PORTS, NULL, 0,
310+
&resp_pd_ports, sizeof(resp_pd_ports));
311+
if (ret < 0)
312+
return -EIO;
313+
314+
for (i = 0; i < resp_pd_ports.num_ports; i++) {
315+
struct ec_response_usb_pd_mux_info resp_mux;
316+
struct ec_params_usb_pd_mux_info req = {
317+
.port = i,
318+
};
319+
320+
ret = cros_ec_cmd(ec->ec_dev, 0, EC_CMD_USB_PD_MUX_INFO,
321+
&req, sizeof(req), &resp_mux, sizeof(resp_mux));
322+
323+
if (ret >= 0) {
324+
count += sysfs_emit_at(buf, count, "Port %d:", i);
325+
count += sysfs_emit_at(buf, count, " USB=%d",
326+
!!(resp_mux.flags & USB_PD_MUX_USB_ENABLED));
327+
count += sysfs_emit_at(buf, count, " DP=%d",
328+
!!(resp_mux.flags & USB_PD_MUX_DP_ENABLED));
329+
count += sysfs_emit_at(buf, count, " POLARITY=%s",
330+
(resp_mux.flags & USB_PD_MUX_POLARITY_INVERTED) ?
331+
"INVERTED" : "NORMAL");
332+
count += sysfs_emit_at(buf, count, " HPD_IRQ=%d",
333+
!!(resp_mux.flags & USB_PD_MUX_HPD_IRQ));
334+
count += sysfs_emit_at(buf, count, " HPD_LVL=%d",
335+
!!(resp_mux.flags & USB_PD_MUX_HPD_LVL));
336+
count += sysfs_emit_at(buf, count, " SAFE=%d",
337+
!!(resp_mux.flags & USB_PD_MUX_SAFE_MODE));
338+
count += sysfs_emit_at(buf, count, " TBT=%d",
339+
!!(resp_mux.flags & USB_PD_MUX_TBT_COMPAT_ENABLED));
340+
count += sysfs_emit_at(buf, count, " USB4=%d\n",
341+
!!(resp_mux.flags & USB_PD_MUX_USB4_ENABLED));
342+
}
343+
}
344+
345+
return count ? : -EIO;
346+
}
347+
299348
/* Module initialization */
300349

301350
static DEVICE_ATTR_RW(reboot);
302351
static DEVICE_ATTR_RO(version);
303352
static DEVICE_ATTR_RO(flashinfo);
304353
static DEVICE_ATTR_RW(kb_wake_angle);
354+
static DEVICE_ATTR_RO(usbpdmuxinfo);
305355

306356
static struct attribute *__ec_attrs[] = {
307357
&dev_attr_kb_wake_angle.attr,
308358
&dev_attr_reboot.attr,
309359
&dev_attr_version.attr,
310360
&dev_attr_flashinfo.attr,
361+
&dev_attr_usbpdmuxinfo.attr,
311362
NULL,
312363
};
313364

@@ -320,6 +371,13 @@ static umode_t cros_ec_ctrl_visible(struct kobject *kobj,
320371
if (a == &dev_attr_kb_wake_angle.attr && !ec->has_kb_wake_angle)
321372
return 0;
322373

374+
if (a == &dev_attr_usbpdmuxinfo.attr) {
375+
struct cros_ec_platform *ec_platform = dev_get_platdata(ec->dev);
376+
377+
if (strcmp(ec_platform->ec_name, CROS_EC_DEV_NAME))
378+
return 0;
379+
}
380+
323381
return a->mode;
324382
}
325383

0 commit comments

Comments
 (0)