Commit 13f2ec31 authored by Dmitry Baryshkov's avatar Dmitry Baryshkov Committed by Greg Kroah-Hartman

usb: typec: ucsi: simplify command sending API

The sync_write and async_write are used only for writing UCSI commands
to the UCSI_CONTROL offsets. Rename sync_write and async_write
operations to sync_control and async_control accordingly. Drop the
offset and length fields and pass u64 command instead.
Tested-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://lore.kernel.org/r/20240627-ucsi-rework-interface-v4-2-289ddc6874c7@linaro.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a7d2fa77
...@@ -60,7 +60,7 @@ static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack) ...@@ -60,7 +60,7 @@ static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack)
ctrl |= UCSI_ACK_CONNECTOR_CHANGE; ctrl |= UCSI_ACK_CONNECTOR_CHANGE;
} }
return ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &ctrl, sizeof(ctrl)); return ucsi->ops->sync_control(ucsi, ctrl);
} }
static int ucsi_exec_command(struct ucsi *ucsi, u64 command); static int ucsi_exec_command(struct ucsi *ucsi, u64 command);
...@@ -155,7 +155,7 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd) ...@@ -155,7 +155,7 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd)
connector_num = 0; connector_num = 0;
} }
ret = ucsi->ops->sync_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd)); ret = ucsi->ops->sync_control(ucsi, cmd);
if (ret) if (ret)
return ret; return ret;
...@@ -1350,8 +1350,7 @@ static int ucsi_reset_ppm(struct ucsi *ucsi) ...@@ -1350,8 +1350,7 @@ static int ucsi_reset_ppm(struct ucsi *ucsi)
*/ */
if (cci & UCSI_CCI_RESET_COMPLETE) { if (cci & UCSI_CCI_RESET_COMPLETE) {
command = UCSI_SET_NOTIFICATION_ENABLE; command = UCSI_SET_NOTIFICATION_ENABLE;
ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command, ret = ucsi->ops->async_control(ucsi, command);
sizeof(command));
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -1372,8 +1371,7 @@ static int ucsi_reset_ppm(struct ucsi *ucsi) ...@@ -1372,8 +1371,7 @@ static int ucsi_reset_ppm(struct ucsi *ucsi)
} }
command = UCSI_PPM_RESET; command = UCSI_PPM_RESET;
ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command, ret = ucsi->ops->async_control(ucsi, command);
sizeof(command));
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -1394,9 +1392,7 @@ static int ucsi_reset_ppm(struct ucsi *ucsi) ...@@ -1394,9 +1392,7 @@ static int ucsi_reset_ppm(struct ucsi *ucsi)
/* If the PPM is still doing something else, reset it again. */ /* If the PPM is still doing something else, reset it again. */
if (cci & ~UCSI_CCI_RESET_COMPLETE) { if (cci & ~UCSI_CCI_RESET_COMPLETE) {
ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, ret = ucsi->ops->async_control(ucsi, command);
&command,
sizeof(command));
if (ret < 0) if (ret < 0)
goto out; goto out;
} }
...@@ -1924,7 +1920,7 @@ struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations *ops) ...@@ -1924,7 +1920,7 @@ struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations *ops)
{ {
struct ucsi *ucsi; struct ucsi *ucsi;
if (!ops || !ops->read || !ops->sync_write || !ops->async_write) if (!ops || !ops->read || !ops->sync_control || !ops->async_control)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
ucsi = kzalloc(sizeof(*ucsi), GFP_KERNEL); ucsi = kzalloc(sizeof(*ucsi), GFP_KERNEL);
...@@ -2000,7 +1996,7 @@ void ucsi_unregister(struct ucsi *ucsi) ...@@ -2000,7 +1996,7 @@ void ucsi_unregister(struct ucsi *ucsi)
cancel_work_sync(&ucsi->resume_work); cancel_work_sync(&ucsi->resume_work);
/* Disable notifications */ /* Disable notifications */
ucsi->ops->async_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd)); ucsi->ops->async_control(ucsi, cmd);
if (!ucsi->connector) if (!ucsi->connector)
return; return;
......
...@@ -57,8 +57,8 @@ struct dentry; ...@@ -57,8 +57,8 @@ struct dentry;
/** /**
* struct ucsi_operations - UCSI I/O operations * struct ucsi_operations - UCSI I/O operations
* @read: Read operation * @read: Read operation
* @sync_write: Blocking write operation * @sync_control: Blocking control operation
* @async_write: Non-blocking write operation * @async_control: Non-blocking control operation
* @update_altmodes: Squashes duplicate DP altmodes * @update_altmodes: Squashes duplicate DP altmodes
* @update_connector: Update connector capabilities before registering * @update_connector: Update connector capabilities before registering
* @connector_status: Updates connector status, called holding connector lock * @connector_status: Updates connector status, called holding connector lock
...@@ -70,10 +70,8 @@ struct dentry; ...@@ -70,10 +70,8 @@ struct dentry;
struct ucsi_operations { struct ucsi_operations {
int (*read)(struct ucsi *ucsi, unsigned int offset, int (*read)(struct ucsi *ucsi, unsigned int offset,
void *val, size_t val_len); void *val, size_t val_len);
int (*sync_write)(struct ucsi *ucsi, unsigned int offset, int (*sync_control)(struct ucsi *ucsi, u64 command);
const void *val, size_t val_len); int (*async_control)(struct ucsi *ucsi, u64 command);
int (*async_write)(struct ucsi *ucsi, unsigned int offset,
const void *val, size_t val_len);
bool (*update_altmodes)(struct ucsi *ucsi, struct ucsi_altmode *orig, bool (*update_altmodes)(struct ucsi *ucsi, struct ucsi_altmode *orig,
struct ucsi_altmode *updated); struct ucsi_altmode *updated);
void (*update_connector)(struct ucsi_connector *con); void (*update_connector)(struct ucsi_connector *con);
......
...@@ -61,22 +61,20 @@ static int ucsi_acpi_read(struct ucsi *ucsi, unsigned int offset, ...@@ -61,22 +61,20 @@ static int ucsi_acpi_read(struct ucsi *ucsi, unsigned int offset,
return 0; return 0;
} }
static int ucsi_acpi_async_write(struct ucsi *ucsi, unsigned int offset, static int ucsi_acpi_async_control(struct ucsi *ucsi, u64 command)
const void *val, size_t val_len)
{ {
struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi);
memcpy(ua->base + offset, val, val_len); memcpy(ua->base + UCSI_CONTROL, &command, sizeof(command));
ua->cmd = *(u64 *)val; ua->cmd = command;
return ucsi_acpi_dsm(ua, UCSI_DSM_FUNC_WRITE); return ucsi_acpi_dsm(ua, UCSI_DSM_FUNC_WRITE);
} }
static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset, static int ucsi_acpi_sync_control(struct ucsi *ucsi, u64 command)
const void *val, size_t val_len)
{ {
struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi);
bool ack = UCSI_COMMAND(*(u64 *)val) == UCSI_ACK_CC_CI; bool ack = UCSI_COMMAND(command) == UCSI_ACK_CC_CI;
int ret; int ret;
if (ack) if (ack)
...@@ -84,7 +82,7 @@ static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset, ...@@ -84,7 +82,7 @@ static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset,
else else
set_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags); set_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags);
ret = ucsi_acpi_async_write(ucsi, offset, val, val_len); ret = ucsi_acpi_async_control(ucsi, command);
if (ret) if (ret)
goto out_clear_bit; goto out_clear_bit;
...@@ -102,8 +100,8 @@ static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset, ...@@ -102,8 +100,8 @@ static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset,
static const struct ucsi_operations ucsi_acpi_ops = { static const struct ucsi_operations ucsi_acpi_ops = {
.read = ucsi_acpi_read, .read = ucsi_acpi_read,
.sync_write = ucsi_acpi_sync_write, .sync_control = ucsi_acpi_sync_control,
.async_write = ucsi_acpi_async_write .async_control = ucsi_acpi_async_control
}; };
static int static int
...@@ -125,8 +123,8 @@ ucsi_zenbook_read(struct ucsi *ucsi, unsigned int offset, void *val, size_t val_ ...@@ -125,8 +123,8 @@ ucsi_zenbook_read(struct ucsi *ucsi, unsigned int offset, void *val, size_t val_
static const struct ucsi_operations ucsi_zenbook_ops = { static const struct ucsi_operations ucsi_zenbook_ops = {
.read = ucsi_zenbook_read, .read = ucsi_zenbook_read,
.sync_write = ucsi_acpi_sync_write, .sync_control = ucsi_acpi_sync_control,
.async_write = ucsi_acpi_async_write .async_control = ucsi_acpi_async_control
}; };
static int ucsi_gram_read(struct ucsi *ucsi, unsigned int offset, static int ucsi_gram_read(struct ucsi *ucsi, unsigned int offset,
...@@ -157,13 +155,12 @@ static int ucsi_gram_read(struct ucsi *ucsi, unsigned int offset, ...@@ -157,13 +155,12 @@ static int ucsi_gram_read(struct ucsi *ucsi, unsigned int offset,
return ret; return ret;
} }
static int ucsi_gram_sync_write(struct ucsi *ucsi, unsigned int offset, static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command)
const void *val, size_t val_len)
{ {
struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi);
int ret; int ret;
ret = ucsi_acpi_sync_write(ucsi, offset, val, val_len); ret = ucsi_acpi_sync_control(ucsi, command);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -177,8 +174,8 @@ static int ucsi_gram_sync_write(struct ucsi *ucsi, unsigned int offset, ...@@ -177,8 +174,8 @@ static int ucsi_gram_sync_write(struct ucsi *ucsi, unsigned int offset,
static const struct ucsi_operations ucsi_gram_ops = { static const struct ucsi_operations ucsi_gram_ops = {
.read = ucsi_gram_read, .read = ucsi_gram_read,
.sync_write = ucsi_gram_sync_write, .sync_control = ucsi_gram_sync_control,
.async_write = ucsi_acpi_async_write .async_control = ucsi_acpi_async_control
}; };
static const struct dmi_system_id ucsi_acpi_quirks[] = { static const struct dmi_system_id ucsi_acpi_quirks[] = {
......
...@@ -610,25 +610,23 @@ static int ucsi_ccg_read(struct ucsi *ucsi, unsigned int offset, ...@@ -610,25 +610,23 @@ static int ucsi_ccg_read(struct ucsi *ucsi, unsigned int offset,
return ret; return ret;
} }
static int ucsi_ccg_async_write(struct ucsi *ucsi, unsigned int offset, static int ucsi_ccg_async_control(struct ucsi *ucsi, u64 command)
const void *val, size_t val_len)
{ {
struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi);
u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(offset); u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(UCSI_CONTROL);
/* /*
* UCSI may read CCI instantly after async_write, * UCSI may read CCI instantly after async_control,
* clear CCI to avoid caller getting wrong data before we get CCI from ISR * clear CCI to avoid caller getting wrong data before we get CCI from ISR
*/ */
spin_lock(&uc->op_lock); spin_lock(&uc->op_lock);
uc->op_data.cci = 0; uc->op_data.cci = 0;
spin_unlock(&uc->op_lock); spin_unlock(&uc->op_lock);
return ccg_write(uc, reg, val, val_len); return ccg_write(uc, reg, (u8 *)&command, sizeof(command));
} }
static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset, static int ucsi_ccg_sync_control(struct ucsi *ucsi, u64 command)
const void *val, size_t val_len)
{ {
struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi); struct ucsi_ccg *uc = ucsi_get_drvdata(ucsi);
struct ucsi_connector *con; struct ucsi_connector *con;
...@@ -639,19 +637,17 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset, ...@@ -639,19 +637,17 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset,
pm_runtime_get_sync(uc->dev); pm_runtime_get_sync(uc->dev);
set_bit(DEV_CMD_PENDING, &uc->flags); set_bit(DEV_CMD_PENDING, &uc->flags);
if (offset == UCSI_CONTROL && val_len == sizeof(uc->last_cmd_sent)) { uc->last_cmd_sent = command;
uc->last_cmd_sent = *(u64 *)val;
if (UCSI_COMMAND(uc->last_cmd_sent) == UCSI_SET_NEW_CAM && if (UCSI_COMMAND(uc->last_cmd_sent) == UCSI_SET_NEW_CAM &&
uc->has_multiple_dp) { uc->has_multiple_dp) {
con_index = (uc->last_cmd_sent >> 16) & con_index = (uc->last_cmd_sent >> 16) &
UCSI_CMD_CONNECTOR_MASK; UCSI_CMD_CONNECTOR_MASK;
con = &uc->ucsi->connector[con_index - 1]; con = &uc->ucsi->connector[con_index - 1];
ucsi_ccg_update_set_new_cam_cmd(uc, con, (u64 *)val); ucsi_ccg_update_set_new_cam_cmd(uc, con, &command);
}
} }
ret = ucsi_ccg_async_write(ucsi, offset, val, val_len); ret = ucsi_ccg_async_control(ucsi, command);
if (ret) if (ret)
goto err_clear_bit; goto err_clear_bit;
...@@ -668,8 +664,8 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset, ...@@ -668,8 +664,8 @@ static int ucsi_ccg_sync_write(struct ucsi *ucsi, unsigned int offset,
static const struct ucsi_operations ucsi_ccg_ops = { static const struct ucsi_operations ucsi_ccg_ops = {
.read = ucsi_ccg_read, .read = ucsi_ccg_read,
.sync_write = ucsi_ccg_sync_write, .sync_control = ucsi_ccg_sync_control,
.async_write = ucsi_ccg_async_write, .async_control = ucsi_ccg_async_control,
.update_altmodes = ucsi_ccg_update_altmodes .update_altmodes = ucsi_ccg_update_altmodes
}; };
......
...@@ -143,21 +143,19 @@ static int pmic_glink_ucsi_locked_write(struct pmic_glink_ucsi *ucsi, unsigned i ...@@ -143,21 +143,19 @@ static int pmic_glink_ucsi_locked_write(struct pmic_glink_ucsi *ucsi, unsigned i
return 0; return 0;
} }
static int pmic_glink_ucsi_async_write(struct ucsi *__ucsi, unsigned int offset, static int pmic_glink_ucsi_async_control(struct ucsi *__ucsi, u64 command)
const void *val, size_t val_len)
{ {
struct pmic_glink_ucsi *ucsi = ucsi_get_drvdata(__ucsi); struct pmic_glink_ucsi *ucsi = ucsi_get_drvdata(__ucsi);
int ret; int ret;
mutex_lock(&ucsi->lock); mutex_lock(&ucsi->lock);
ret = pmic_glink_ucsi_locked_write(ucsi, offset, val, val_len); ret = pmic_glink_ucsi_locked_write(ucsi, UCSI_CONTROL, &command, sizeof(command));
mutex_unlock(&ucsi->lock); mutex_unlock(&ucsi->lock);
return ret; return ret;
} }
static int pmic_glink_ucsi_sync_write(struct ucsi *__ucsi, unsigned int offset, static int pmic_glink_ucsi_sync_control(struct ucsi *__ucsi, u64 command)
const void *val, size_t val_len)
{ {
struct pmic_glink_ucsi *ucsi = ucsi_get_drvdata(__ucsi); struct pmic_glink_ucsi *ucsi = ucsi_get_drvdata(__ucsi);
unsigned long left; unsigned long left;
...@@ -169,7 +167,7 @@ static int pmic_glink_ucsi_sync_write(struct ucsi *__ucsi, unsigned int offset, ...@@ -169,7 +167,7 @@ static int pmic_glink_ucsi_sync_write(struct ucsi *__ucsi, unsigned int offset,
ucsi->sync_val = 0; ucsi->sync_val = 0;
reinit_completion(&ucsi->sync_ack); reinit_completion(&ucsi->sync_ack);
ucsi->sync_pending = true; ucsi->sync_pending = true;
ret = pmic_glink_ucsi_locked_write(ucsi, offset, val, val_len); ret = pmic_glink_ucsi_locked_write(ucsi, UCSI_CONTROL, &command, sizeof(command));
mutex_unlock(&ucsi->lock); mutex_unlock(&ucsi->lock);
left = wait_for_completion_timeout(&ucsi->sync_ack, 5 * HZ); left = wait_for_completion_timeout(&ucsi->sync_ack, 5 * HZ);
...@@ -217,8 +215,8 @@ static void pmic_glink_ucsi_connector_status(struct ucsi_connector *con) ...@@ -217,8 +215,8 @@ static void pmic_glink_ucsi_connector_status(struct ucsi_connector *con)
static const struct ucsi_operations pmic_glink_ucsi_ops = { static const struct ucsi_operations pmic_glink_ucsi_ops = {
.read = pmic_glink_ucsi_read, .read = pmic_glink_ucsi_read,
.sync_write = pmic_glink_ucsi_sync_write, .sync_control = pmic_glink_ucsi_sync_control,
.async_write = pmic_glink_ucsi_async_write, .async_control = pmic_glink_ucsi_async_control,
.update_connector = pmic_glink_ucsi_update_connector, .update_connector = pmic_glink_ucsi_update_connector,
.connector_status = pmic_glink_ucsi_connector_status, .connector_status = pmic_glink_ucsi_connector_status,
}; };
......
...@@ -359,8 +359,7 @@ static int ucsi_stm32g0_read(struct ucsi *ucsi, unsigned int offset, void *val, ...@@ -359,8 +359,7 @@ static int ucsi_stm32g0_read(struct ucsi *ucsi, unsigned int offset, void *val,
return 0; return 0;
} }
static int ucsi_stm32g0_async_write(struct ucsi *ucsi, unsigned int offset, const void *val, static int ucsi_stm32g0_async_control(struct ucsi *ucsi, u64 command)
size_t len)
{ {
struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi);
struct i2c_client *client = g0->client; struct i2c_client *client = g0->client;
...@@ -373,19 +372,19 @@ static int ucsi_stm32g0_async_write(struct ucsi *ucsi, unsigned int offset, cons ...@@ -373,19 +372,19 @@ static int ucsi_stm32g0_async_write(struct ucsi *ucsi, unsigned int offset, cons
unsigned char *buf; unsigned char *buf;
int ret; int ret;
buf = kmalloc(len + 1, GFP_KERNEL); buf = kmalloc(sizeof(command) + 1, GFP_KERNEL);
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
buf[0] = offset; buf[0] = UCSI_CONTROL;
memcpy(&buf[1], val, len); memcpy(&buf[1], &command, sizeof(command));
msg[0].len = len + 1; msg[0].len = sizeof(command) + 1;
msg[0].buf = buf; msg[0].buf = buf;
ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
kfree(buf); kfree(buf);
if (ret != ARRAY_SIZE(msg)) { if (ret != ARRAY_SIZE(msg)) {
dev_err(g0->dev, "i2c write %02x, %02x error: %d\n", client->addr, offset, ret); dev_err(g0->dev, "i2c write %02x, %02x error: %d\n", client->addr, UCSI_CONTROL, ret);
return ret < 0 ? ret : -EIO; return ret < 0 ? ret : -EIO;
} }
...@@ -393,11 +392,10 @@ static int ucsi_stm32g0_async_write(struct ucsi *ucsi, unsigned int offset, cons ...@@ -393,11 +392,10 @@ static int ucsi_stm32g0_async_write(struct ucsi *ucsi, unsigned int offset, cons
return 0; return 0;
} }
static int ucsi_stm32g0_sync_write(struct ucsi *ucsi, unsigned int offset, const void *val, static int ucsi_stm32g0_sync_control(struct ucsi *ucsi, u64 command)
size_t len)
{ {
struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi); struct ucsi_stm32g0 *g0 = ucsi_get_drvdata(ucsi);
bool ack = UCSI_COMMAND(*(u64 *)val) == UCSI_ACK_CC_CI; bool ack = UCSI_COMMAND(command) == UCSI_ACK_CC_CI;
int ret; int ret;
if (ack) if (ack)
...@@ -405,7 +403,7 @@ static int ucsi_stm32g0_sync_write(struct ucsi *ucsi, unsigned int offset, const ...@@ -405,7 +403,7 @@ static int ucsi_stm32g0_sync_write(struct ucsi *ucsi, unsigned int offset, const
else else
set_bit(COMMAND_PENDING, &g0->flags); set_bit(COMMAND_PENDING, &g0->flags);
ret = ucsi_stm32g0_async_write(ucsi, offset, val, len); ret = ucsi_stm32g0_async_control(ucsi, command);
if (ret) if (ret)
goto out_clear_bit; goto out_clear_bit;
...@@ -449,8 +447,8 @@ static irqreturn_t ucsi_stm32g0_irq_handler(int irq, void *data) ...@@ -449,8 +447,8 @@ static irqreturn_t ucsi_stm32g0_irq_handler(int irq, void *data)
static const struct ucsi_operations ucsi_stm32g0_ops = { static const struct ucsi_operations ucsi_stm32g0_ops = {
.read = ucsi_stm32g0_read, .read = ucsi_stm32g0_read,
.sync_write = ucsi_stm32g0_sync_write, .sync_control = ucsi_stm32g0_sync_control,
.async_write = ucsi_stm32g0_async_write, .async_control = ucsi_stm32g0_async_control,
}; };
static int ucsi_stm32g0_register(struct ucsi *ucsi) static int ucsi_stm32g0_register(struct ucsi *ucsi)
......
...@@ -56,23 +56,17 @@ static int yoga_c630_ucsi_read(struct ucsi *ucsi, unsigned int offset, ...@@ -56,23 +56,17 @@ static int yoga_c630_ucsi_read(struct ucsi *ucsi, unsigned int offset,
} }
} }
static int yoga_c630_ucsi_async_write(struct ucsi *ucsi, unsigned int offset, static int yoga_c630_ucsi_async_control(struct ucsi *ucsi, u64 command)
const void *val, size_t val_len)
{ {
struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi);
if (offset != UCSI_CONTROL || return yoga_c630_ec_ucsi_write(uec->ec, (u8*)&command);
val_len != YOGA_C630_UCSI_WRITE_SIZE)
return -EINVAL;
return yoga_c630_ec_ucsi_write(uec->ec, val);
} }
static int yoga_c630_ucsi_sync_write(struct ucsi *ucsi, unsigned int offset, static int yoga_c630_ucsi_sync_control(struct ucsi *ucsi, u64 command)
const void *val, size_t val_len)
{ {
struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi); struct yoga_c630_ucsi *uec = ucsi_get_drvdata(ucsi);
bool ack = UCSI_COMMAND(*(u64 *)val) == UCSI_ACK_CC_CI; bool ack = UCSI_COMMAND(command) == UCSI_ACK_CC_CI;
int ret; int ret;
if (ack) if (ack)
...@@ -82,7 +76,7 @@ static int yoga_c630_ucsi_sync_write(struct ucsi *ucsi, unsigned int offset, ...@@ -82,7 +76,7 @@ static int yoga_c630_ucsi_sync_write(struct ucsi *ucsi, unsigned int offset,
reinit_completion(&uec->complete); reinit_completion(&uec->complete);
ret = yoga_c630_ucsi_async_write(ucsi, offset, val, val_len); ret = yoga_c630_ucsi_async_control(ucsi, command);
if (ret) if (ret)
goto out_clear_bit; goto out_clear_bit;
...@@ -100,8 +94,8 @@ static int yoga_c630_ucsi_sync_write(struct ucsi *ucsi, unsigned int offset, ...@@ -100,8 +94,8 @@ static int yoga_c630_ucsi_sync_write(struct ucsi *ucsi, unsigned int offset,
const struct ucsi_operations yoga_c630_ucsi_ops = { const struct ucsi_operations yoga_c630_ucsi_ops = {
.read = yoga_c630_ucsi_read, .read = yoga_c630_ucsi_read,
.sync_write = yoga_c630_ucsi_sync_write, .sync_control = yoga_c630_ucsi_sync_control,
.async_write = yoga_c630_ucsi_async_write, .async_control = yoga_c630_ucsi_async_control,
}; };
static void yoga_c630_ucsi_notify_ucsi(struct yoga_c630_ucsi *uec, u32 cci) static void yoga_c630_ucsi_notify_ucsi(struct yoga_c630_ucsi *uec, u32 cci)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment