Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: typec: ucsi: return CCI and message from sync_control callback

Some of the drivers emulate or handle some of the commands in the
platform-specific way. The code ends up being split between several
callbacks, which complicates emulation.

In preparation to reworking such drivers, move read_cci() and
read_message_in() calls into ucsi_sync_control_common().

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reviewed-by: Łukasz Bartosik <ukaszb@chromium.org>
Link: https://lore.kernel.org/r/20250120-ucsi-merge-commands-v2-1-462a1ec22ecc@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Dmitry Baryshkov and committed by
Greg Kroah-Hartman
667ecac5 41d5e380

+24 -16
+3 -2
drivers/usb/typec/ucsi/cros_ec_ucsi.c
··· 105 105 return 0; 106 106 } 107 107 108 - static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd) 108 + static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd, u32 *cci, 109 + void *data, size_t size) 109 110 { 110 111 struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi); 111 112 int ret; 112 113 113 - ret = ucsi_sync_control_common(ucsi, cmd); 114 + ret = ucsi_sync_control_common(ucsi, cmd, cci, data, size); 114 115 switch (ret) { 115 116 case -EBUSY: 116 117 /* EC may return -EBUSY if CCI.busy is set.
+11 -8
drivers/usb/typec/ucsi/ucsi.c
··· 55 55 } 56 56 EXPORT_SYMBOL_GPL(ucsi_notify_common); 57 57 58 - int ucsi_sync_control_common(struct ucsi *ucsi, u64 command) 58 + int ucsi_sync_control_common(struct ucsi *ucsi, u64 command, u32 *cci, 59 + void *data, size_t size) 59 60 { 60 61 bool ack = UCSI_COMMAND(command) == UCSI_ACK_CC_CI; 61 62 int ret; ··· 81 80 else 82 81 clear_bit(COMMAND_PENDING, &ucsi->flags); 83 82 83 + if (!ret && cci) 84 + ret = ucsi->ops->read_cci(ucsi, cci); 85 + 86 + if (!ret && data && 87 + (*cci & UCSI_CCI_COMMAND_COMPLETE)) 88 + ret = ucsi->ops->read_message_in(ucsi, data, size); 89 + 84 90 return ret; 85 91 } 86 92 EXPORT_SYMBOL_GPL(ucsi_sync_control_common); ··· 103 95 ctrl |= UCSI_ACK_CONNECTOR_CHANGE; 104 96 } 105 97 106 - return ucsi->ops->sync_control(ucsi, ctrl); 98 + return ucsi->ops->sync_control(ucsi, ctrl, NULL, NULL, 0); 107 99 } 108 100 109 101 static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, ··· 116 108 if (size > UCSI_MAX_DATA_LENGTH(ucsi)) 117 109 return -EINVAL; 118 110 119 - ret = ucsi->ops->sync_control(ucsi, command); 120 - if (ucsi->ops->read_cci(ucsi, cci)) 121 - return -EIO; 111 + ret = ucsi->ops->sync_control(ucsi, command, cci, data, size); 122 112 123 113 if (*cci & UCSI_CCI_BUSY) 124 114 return ucsi_run_command(ucsi, UCSI_CANCEL, cci, NULL, 0, false) ?: -EBUSY; ··· 132 126 err = -EIO; 133 127 else 134 128 err = 0; 135 - 136 - if (!err && data && UCSI_CCI_LENGTH(*cci)) 137 - err = ucsi->ops->read_message_in(ucsi, data, size); 138 129 139 130 /* 140 131 * Don't ACK connection change if there was an error.
+4 -2
drivers/usb/typec/ucsi/ucsi.h
··· 77 77 int (*read_version)(struct ucsi *ucsi, u16 *version); 78 78 int (*read_cci)(struct ucsi *ucsi, u32 *cci); 79 79 int (*read_message_in)(struct ucsi *ucsi, void *val, size_t val_len); 80 - int (*sync_control)(struct ucsi *ucsi, u64 command); 80 + int (*sync_control)(struct ucsi *ucsi, u64 command, u32 *cci, 81 + void *data, size_t size); 81 82 int (*async_control)(struct ucsi *ucsi, u64 command); 82 83 bool (*update_altmodes)(struct ucsi *ucsi, struct ucsi_altmode *orig, 83 84 struct ucsi_altmode *updated); ··· 532 531 int ucsi_resume(struct ucsi *ucsi); 533 532 534 533 void ucsi_notify_common(struct ucsi *ucsi, u32 cci); 535 - int ucsi_sync_control_common(struct ucsi *ucsi, u64 command); 534 + int ucsi_sync_control_common(struct ucsi *ucsi, u64 command, u32 *cci, 535 + void *data, size_t size); 536 536 537 537 #if IS_ENABLED(CONFIG_POWER_SUPPLY) 538 538 int ucsi_register_port_psy(struct ucsi_connector *con);
+3 -2
drivers/usb/typec/ucsi/ucsi_acpi.c
··· 122 122 return ret; 123 123 } 124 124 125 - static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command) 125 + static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command, u32 *cci, 126 + void *data, size_t size) 126 127 { 127 128 struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); 128 129 int ret; 129 130 130 - ret = ucsi_sync_control_common(ucsi, command); 131 + ret = ucsi_sync_control_common(ucsi, command, cci, data, size); 131 132 if (ret < 0) 132 133 return ret; 133 134
+3 -2
drivers/usb/typec/ucsi/ucsi_ccg.c
··· 628 628 return ccg_write(uc, reg, (u8 *)&command, sizeof(command)); 629 629 } 630 630 631 - static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command) 631 + static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command, u32 *cci, 632 + void *data, size_t size) 632 633 { 633 634 struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); 634 635 struct ucsi_connector *con; ··· 653 652 ucsi_ccg_update_set_new_cam_cmd(uc, con, &command); 654 653 } 655 654 656 - ret = ucsi_sync_control_common(ucsi, command); 655 + ret = ucsi_sync_control_common(ucsi, command, cci, data, size); 657 656 658 657 err_put: 659 658 pm_runtime_put_sync(uc->dev);