]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
usb: typec: ucsi: Enable debugfs for message_out data structure
authorPooja Katiyar <pooja.katiyar@intel.com>
Tue, 19 May 2026 18:45:13 +0000 (11:45 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 22 May 2026 09:35:50 +0000 (11:35 +0200)
Add debugfs entry for writing message_out data structure to handle
UCSI 2.1 and 3.0 commands through debugfs interface.

Users writing to the message_out debugfs file should ensure the input
data adheres to the following format:
1. Input must be a non-empty valid hexadecimal string.
2. Input length of hexadecimal string must not exceed 256 bytes of
   length to be in alignment with the message out data structure size
   as per the UCSI specification v2.1.
3. If the input string length is odd, then user needs to prepend a
   '0' to the first character for proper hex conversion.

Below are examples of valid hex strings. Note that these values are
just examples. The exact values depend on specific command use case.

        #echo 1A2B3C4D > message_out
        #echo 01234567 > message_out

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Pooja Katiyar <pooja.katiyar@intel.com>
Link: https://patch.msgid.link/812820ed3caae2d9ab86e4b26022c5a36b645f86.1778798352.git.pooja.katiyar@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/ucsi/debugfs.c
drivers/usb/typec/ucsi/ucsi.h

index a4b9a6b51649d6497fc7c8fe799467e4c80673b3..be987e53a8bd123c8626b2d493e30905fa86c477 100644 (file)
@@ -110,6 +110,30 @@ static int ucsi_vbus_volt_show(struct seq_file *m, void *v)
 }
 DEFINE_SHOW_ATTRIBUTE(ucsi_vbus_volt);
 
+static ssize_t ucsi_message_out_write(struct file *file,
+                                     const char __user *data, size_t count, loff_t *ppos)
+{
+       struct ucsi *ucsi = file->private_data;
+       int ret;
+
+       char *buf __free(kfree) = memdup_user_nul(data, count);
+       if (IS_ERR(buf))
+               return PTR_ERR(buf);
+
+       ret = hex2bin(ucsi->debugfs->message_out, buf,
+                     min(count / 2, sizeof(ucsi->debugfs->message_out)));
+       if (ret)
+               return ret;
+
+       return count;
+}
+
+static const struct file_operations ucsi_message_out_fops = {
+       .open = simple_open,
+       .write = ucsi_message_out_write,
+       .llseek = generic_file_llseek,
+};
+
 void ucsi_debugfs_register(struct ucsi *ucsi)
 {
        ucsi->debugfs = kzalloc_obj(*ucsi->debugfs);
@@ -122,6 +146,8 @@ void ucsi_debugfs_register(struct ucsi *ucsi)
        debugfs_create_file("peak_current", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_peak_curr_fops);
        debugfs_create_file("avg_current", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_avg_curr_fops);
        debugfs_create_file("vbus_voltage", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_vbus_volt_fops);
+       debugfs_create_file("message_out", 0200, ucsi->debugfs->dentry, ucsi,
+                           &ucsi_message_out_fops);
 }
 
 void ucsi_debugfs_unregister(struct ucsi *ucsi)
index 402f45494dfa893627361652c8d0d58f514ae80a..64ccfd6a6d502b048c2e2c2d6d774e6cfa6e73ac 100644 (file)
@@ -455,6 +455,8 @@ struct ucsi_bitfield {
 
 /* -------------------------------------------------------------------------- */
 
+#define MESSAGE_OUT_MAX_LEN 256
+
 struct ucsi_debugfs_entry {
        u64 command;
        struct ucsi_data {
@@ -462,6 +464,7 @@ struct ucsi_debugfs_entry {
                u64 high;
        } response;
        int status;
+       u8 message_out[MESSAGE_OUT_MAX_LEN];
        struct dentry *dentry;
 };