Skip to content

Commit 775fae5

Browse files
pakatiyargregkh
authored andcommitted
usb: typec: ucsi: Enable debugfs for message_out data structure
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/0a81c2209eb299c1af191cd7ce758a92d5adf81b.1761773881.git.pooja.katiyar@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent db00286 commit 775fae5

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

drivers/usb/typec/ucsi/debugfs.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,30 @@ static int ucsi_vbus_volt_show(struct seq_file *m, void *v)
110110
}
111111
DEFINE_SHOW_ATTRIBUTE(ucsi_vbus_volt);
112112

113+
static ssize_t ucsi_message_out_write(struct file *file,
114+
const char __user *data, size_t count, loff_t *ppos)
115+
{
116+
struct ucsi *ucsi = file->private_data;
117+
int ret;
118+
119+
char *buf __free(kfree) = memdup_user_nul(data, count);
120+
if (IS_ERR(buf))
121+
return PTR_ERR(buf);
122+
123+
ucsi->message_out_size = min(count / 2, UCSI_MAX_MESSAGE_OUT_LENGTH);
124+
ret = hex2bin(ucsi->message_out, buf, ucsi->message_out_size);
125+
if (ret)
126+
return ret;
127+
128+
return count;
129+
}
130+
131+
static const struct file_operations ucsi_message_out_fops = {
132+
.open = simple_open,
133+
.write = ucsi_message_out_write,
134+
.llseek = generic_file_llseek,
135+
};
136+
113137
void ucsi_debugfs_register(struct ucsi *ucsi)
114138
{
115139
ucsi->debugfs = kzalloc(sizeof(*ucsi->debugfs), GFP_KERNEL);
@@ -122,6 +146,8 @@ void ucsi_debugfs_register(struct ucsi *ucsi)
122146
debugfs_create_file("peak_current", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_peak_curr_fops);
123147
debugfs_create_file("avg_current", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_avg_curr_fops);
124148
debugfs_create_file("vbus_voltage", 0400, ucsi->debugfs->dentry, ucsi, &ucsi_vbus_volt_fops);
149+
debugfs_create_file("message_out", 0200, ucsi->debugfs->dentry, ucsi,
150+
&ucsi_message_out_fops);
125151
}
126152

127153
void ucsi_debugfs_unregister(struct ucsi *ucsi)

0 commit comments

Comments
 (0)