usb: typec: ucsi: Add support for SET_PDOS command
Subsystems (4)
v8 cover usb: typec: ucsi: Add support for SET_PDOS command
This series implements support for UCSI SET PDOS command. It provides interface to send message out data and update source or sink capabilities PDOs on a connector over debugfs interface.
Changelog v8:
- Rebase onto v7.1-rc3
Pooja Katiyar (3):
usb: typec: ucsi: Add support for message_out data structure
usb: typec: ucsi: Enable debugfs for message_out data structure
usb: typec: ucsi: Add support for SET_PDOS command
drivers/usb/typec/ucsi/cros_ec_ucsi.c | 6 ++- drivers/usb/typec/ucsi/debugfs.c | 31 +++++++++++++++ drivers/usb/typec/ucsi/ucsi.c | 52 ++++++++++++++++++++----- drivers/usb/typec/ucsi/ucsi.h | 20 +++++++++- drivers/usb/typec/ucsi/ucsi_acpi.c | 22 ++++++++++- drivers/usb/typec/ucsi/ucsi_ccg.c | 6 ++- drivers/usb/typec/ucsi/ucsi_yoga_c630.c | 6 ++- 7 files changed, 123 insertions(+), 20 deletions(-)
Signature · 1 line
2.43.0
PATCH v8 1/3 usb: typec: ucsi: Add support for message_out data structure
Add support for UCSI message_out data structure. The UCSI interface defines separate message_in and message_out data structure for bidirectional communication, where commands like Set PDOs and LPM Firmware Update require writing data to message_out before command execution.
Add write_message_out operation to ucsi_operations structure to allow platform drivers to implement message_out data writing capability.
Update ucsi_sync_control_common to accept message_out parameters and call write_message_out followed by command execution to maintain proper sequencing as per the UCSI specification.
Introduce ucsi_write_message_out_command for commands that need to send message_out data, while maintaining ucsi_send_command for commands that only require message_in response data.
---
Changelog v7:
- Added changelogs.
Changelog v6:
- Removed message_in and message_out related fields from global ucsi data structure and replaced with function parameter approach.
- Added message_out parameters to existing function parameters, keeping the flow similar to message_in data handling.
- Modified ucsi_sync_control_common() signature to accept msg_out and msg_out_size.
- Added write_message_out() to ucsi_operations struct.
- Added ucsi_write_message_out_command() function to handle commands which need to send message_out data to PPM.
- Updated platform interfaces and other function callers with new function signatures.
Changelog v5:
- Rebased patches to v6.18-rc3.
Changelog v4:
- Fixed build errors reported by kernel test robot.
- Added changelogs.
Changelog v3:
- Added message fields to UCSI structure and updated sync_control handling.
Changelog v2:
- Moved write_message_out operation to .sync_control.
- Updated ucsi_send_command to accept message_out data.
drivers/usb/typec/ucsi/cros_ec_ucsi.c | 6 ++- drivers/usb/typec/ucsi/ucsi.c | 52 ++++++++++++++++++++----- drivers/usb/typec/ucsi/ucsi.h | 13 ++++++- drivers/usb/typec/ucsi/ucsi_acpi.c | 22 ++++++++++- drivers/usb/typec/ucsi/ucsi_ccg.c | 6 ++- drivers/usb/typec/ucsi/ucsi_yoga_c630.c | 6 ++- 6 files changed, 85 insertions(+), 20 deletions(-)
drivers/usb/typec/ucsi/cros_ec_ucsi.c +4 -2
@@ -114,12 +114,14 @@ static int cros_ucsi_async_control(struct ucsi *ucsi, u64 cmd) }static int cros_ucsi_sync_control (struct ucsi *ucsi,u64 cmd,u32 *cci, -void *data,size_t size) +void *data,size_t size,void *msg_out, +size_t msg_out_size) {struct cros_ucsi_data *udata =ucsi_get_drvdata (ucsi);int ret; - ret =ucsi_sync_control_common (ucsi, cmd, cci, data, size); + ret =ucsi_sync_control_common (ucsi, cmd, cci, data, size, msg_out, + msg_out_size);switch (ret) {case -EBUSY :/* EC may return -EBUSY if CCI.busy is set.
drivers/usb/typec/ucsi/ucsi.c +42 -10
114 lines not on this page · raw message
drivers/usb/typec/ucsi/ucsi.h +11 -2
@@ -65,6 +65,7 @@ struct dentry;* @read_cci: Read CCI register * @poll_cci: Read CCI register while polling with notifications disabled * @read_message_in: Read message data from UCSI +* @write_message_out: Write message data to UCSI * @sync_control: Blocking control operation * @async_control: Non-blocking control operation * @update_altmodes: Squashes duplicate DP altmodes
@@ -82,8 +83,9 @@ struct ucsi_operations {int (*read_cci)(struct ucsi *ucsi,u32 *cci);int (*poll_cci)(struct ucsi *ucsi,u32 *cci);int (*read_message_in)(struct ucsi *ucsi,void *val,size_t val_len); +int (*write_message_out)(struct ucsi *ucsi,void *data,size_t data_len);int (*sync_control)(struct ucsi *ucsi,u64 command,u32 *cci, -void *data,size_t size); +void *data,size_t size,void *msg_out,size_t msg_out_size);int (*async_control)(struct ucsi *ucsi,u64 command); bool (*update_altmodes)(struct ucsi *ucsi, u8 recipient, struct ucsi_altmode *orig,
@@ -503,6 +505,9 @@ struct ucsi { };#define UCSI_MAX_DATA_LENGTH (u) (((u)->version < UCSI_VERSION_2_0) ? 0x10 : 0xff) +#define UCSI_MAX_MSG_OUT_DATA_LEN (u) \ + (((u)->version >= UCSI_VERSION_3_0) ? 255 : \ + (((u)->version >= UCSI_VERSION_2_0) ? 256 : 16))#define UCSI_MAX_SVID 5#define UCSI_MAX_ALTMODES (UCSI_MAX_SVID * 6)
@@ -564,13 +569,17 @@ struct ucsi_connector {int ucsi_send_command (struct ucsi *ucsi,u64 command,void *retval,size_t size); +int ucsi_write_message_out_command (struct ucsi *ucsi,u64 command, +void *retval,size_t size, +void *msg_out,size_t msg_out_size);void ucsi_altmode_update_active (struct ucsi_connector *con);int ucsi_resume (struct ucsi *ucsi);void ucsi_notify_common (struct ucsi *ucsi,u32 cci);int ucsi_sync_control_common (struct ucsi *ucsi,u64 command,u32 *cci, -void *data,size_t size); +void *data,size_t size,void *msg_out, +size_t msg_out_size);#if IS_ENABLED (CONFIG_POWER_SUPPLY )int ucsi_register_port_psy (struct ucsi_connector *con);
drivers/usb/typec/ucsi/ucsi_acpi.c +20 -2
@@ -86,6 +86,21 @@ static int ucsi_acpi_read_message_in(struct ucsi *ucsi, void *val, size_t val_lereturn 0 ; } +static int ucsi_acpi_write_message_out (struct ucsi *ucsi,void *data,size_t data_len) +{ +struct ucsi_acpi *ua =ucsi_get_drvdata (ucsi); + +if (!data || !data_len) +return -EINVAL ; + +if (ucsi->version <=UCSI_VERSION_1_2 ) +memcpy (ua->base +UCSI_MESSAGE_OUT , data, data_len); +else +memcpy (ua->base + UCSIv2_MESSAGE_OUT, data, data_len); + +return 0 ; +} +static int ucsi_acpi_async_control (struct ucsi *ucsi,u64 command) {struct ucsi_acpi *ua =ucsi_get_drvdata (ucsi);
@@ -101,19 +116,22 @@ static const struct ucsi_operations ucsi_acpi_ops = { .read_cci = ucsi_acpi_read_cci, .poll_cci = ucsi_acpi_poll_cci, .read_message_in = ucsi_acpi_read_message_in, + .write_message_out = ucsi_acpi_write_message_out, .sync_control = ucsi_sync_control_common, .async_control = ucsi_acpi_async_control };static int ucsi_gram_sync_control (struct ucsi *ucsi,u64 command,u32 *cci, -void *val,size_t len) +void *val,size_t len,void *msg_out, +size_t msg_out_size) {u16 bogus_change =UCSI_CONSTAT_POWER_LEVEL_CHANGE |UCSI_CONSTAT_PDOS_CHANGE ;struct ucsi_acpi *ua =ucsi_get_drvdata (ucsi);int ret; - ret =ucsi_sync_control_common (ucsi, command, cci, val, len); + ret =ucsi_sync_control_common (ucsi, command, cci, val, len, + msg_out, msg_out_size);if (ret <0 )return ret;
drivers/usb/typec/ucsi/ucsi_ccg.c +4 -2
@@ -608,7 +608,8 @@ static int ucsi_ccg_async_control(struct ucsi *ucsi, u64 command) }static int ucsi_ccg_sync_control (struct ucsi *ucsi,u64 command,u32 *cci, -void *data,size_t size) +void *data,size_t size,void *msg_out, +size_t msg_out_size) {struct ucsi_ccg *uc =ucsi_get_drvdata (ucsi);struct ucsi_connector *con;
@@ -630,7 +631,8 @@ static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command, u32 *cci,ucsi_ccg_update_set_new_cam_cmd (uc, con, &command); } - ret =ucsi_sync_control_common (ucsi, command, cci, data, size); + ret =ucsi_sync_control_common (ucsi, command, cci, data, size, + msg_out, msg_out_size);switch (UCSI_COMMAND (command)) {case UCSI_GET_CURRENT_CAM :
drivers/usb/typec/ucsi/ucsi_yoga_c630.c +4 -2
@@ -89,7 +89,8 @@ static int yoga_c630_ucsi_async_control(struct ucsi *ucsi, u64 command)static int yoga_c630_ucsi_sync_control (struct ucsi *ucsi,u64 command,u32 *cci, -void *data,size_t size) +void *data,size_t size, +void *msg_out,size_t msg_out_size) {int ret;
@@ -126,7 +127,8 @@ static int yoga_c630_ucsi_sync_control(struct ucsi *ucsi,return 0 ; } - ret =ucsi_sync_control_common (ucsi, command, cci, data, size); + ret =ucsi_sync_control_common (ucsi, command, cci, + data, size, msg_out, msg_out_size);if (ret <0 )return ret;
Signature · 1 line
2.43.0
PATCH v8 2/3 usb: typec: ucsi: Enable debugfs for message_out data structure
In reply to Pooja KatiyarAdd 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
---
Changelog v7:
- Added changelog.
Changelog v6:
- Removed message_out field from UCSI structure and added it back to ucsi_debugfs_entry structure.
Changelog v3:
- Updated debugfs message_out write handler to use message_out fields in UCSI structure.
drivers/usb/typec/ucsi/debugfs.c | 26 ++++++++++++++++++++++++++ drivers/usb/typec/ucsi/ucsi.h | 3 +++ 2 files changed, 29 insertions(+)
drivers/usb/typec/ucsi/debugfs.c +26 -0
@@ -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)
drivers/usb/typec/ucsi/ucsi.h +3 -0
@@ -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; };
Signature · 1 line
2.43.0
PATCH v8 3/3 usb: typec: ucsi: Add support for SET_PDOS command
In reply to Pooja KatiyarAdd support for UCSI SET_PDOS command as per UCSI specification v2.1 and above to debugfs.
---
Changelog v7:
- Added changelogs.
Changelog v6:
- Removed message_out field from UCSI structure and added it back to ucsi_debugfs_entry structure.
Changelog v2:
- Send message_out data as part of ucsi_send_command.
drivers/usb/typec/ucsi/debugfs.c | 5 +++++ drivers/usb/typec/ucsi/ucsi.h | 4 ++++ 2 files changed, 9 insertions(+)
drivers/usb/typec/ucsi/debugfs.c +5 -0
@@ -40,6 +40,11 @@ static int ucsi_cmd(void *data, u64 val)case UCSI_READ_POWER_LEVEL : ret =ucsi_send_command (ucsi, val,NULL ,0 );break ; +case UCSI_SET_PDOS : + ret =ucsi_write_message_out_command (ucsi, val,NULL ,0 , + ucsi->debugfs->message_out, +UCSI_COMMAND_DATA_LEN (val)); +break ;case UCSI_GET_CAPABILITY :case UCSI_GET_CONNECTOR_CAPABILITY :case UCSI_GET_ALTERNATE_MODES :
drivers/usb/typec/ucsi/ucsi.h +4 -0
@@ -138,6 +138,7 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num);#define UCSI_GET_PD_MESSAGE 0x15#define UCSI_GET_CAM_CS 0x18#define UCSI_SET_SINK_PATH 0x1c +#define UCSI_SET_PDOS 0x1d#define UCSI_READ_POWER_LEVEL 0x1e#define UCSI_SET_USB 0x21#define UCSI_GET_LPM_PPM_INFO 0x22
@@ -215,6 +216,9 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num);#define UCSI_GET_PD_MESSAGE_TYPE_IDENTITY 4#define UCSI_GET_PD_MESSAGE_TYPE_REVISION 5 +/* Data length bits */ +#define UCSI_COMMAND_DATA_LEN (_cmd_) (((_cmd_) >> 8) & GENMASK(7, 0)) +/* -------------------------------------------------------------------------- */ /* Error information returned by PPM in response to GET_ERROR_STATUS command. */
Signature · 1 line
2.43.0