summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/amd/pm/swsmu/smu11
diff options
context:
space:
mode:
authorAndrey Grodzovsky <andrey.grodzovsky@amd.com>2021-01-26 12:09:18 -0500
committerAlex Deucher <alexander.deucher@amd.com>2021-07-01 00:24:40 -0400
commit14df56504fdf5d1e84096a4818ff7efc891bfdb6 (patch)
treec6f8cfd26ab15136060f3f48ccb985464059e6c4 /drivers/gpu/drm/amd/pm/swsmu/smu11
parent6a0a55a2eb4584a7189daa3dabdf0c82bdd6466b (diff)
drm/amd/pm: SMU I2C: Return number of messages processed
Fix from number of processed bytes to number of processed I2C messages. Cc: Jean Delvare <jdelvare@suse.de> Cc: Alexander Deucher <Alexander.Deucher@amd.com> Cc: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com> Cc: Lijo Lazar <Lijo.Lazar@amd.com> Cc: Stanley Yang <Stanley.Yang@amd.com> Cc: Hawking Zhang <Hawking.Zhang@amd.com> Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com> Signed-off-by: Luben Tuikov <luben.tuikov@amd.com> Reviewed-by: Luben Tuikov <luben.tuikov@amd.com> Reviewed-by: Alexander Deucher <Alexander.Deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/pm/swsmu/smu11')
-rw-r--r--drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c43
-rw-r--r--drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c43
-rw-r--r--drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c43
3 files changed, 75 insertions, 54 deletions
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c
index efbb24ae4ad3..b26cfa994c27 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c
@@ -1943,9 +1943,8 @@ static int arcturus_i2c_xfer(struct i2c_adapter *i2c_adap,
struct smu_table_context *smu_table = &adev->smu.smu_table;
struct smu_table *table = &smu_table->driver_table;
SwI2cRequest_t *req, *res = (SwI2cRequest_t *)table->cpu_addr;
- u16 bytes_to_transfer, remaining_bytes, msg_bytes;
- u16 available_bytes = MAX_SW_I2C_COMMANDS;
- int i, j, r, c;
+ short available_bytes = MAX_SW_I2C_COMMANDS;
+ int i, j, r, c, num_done = 0;
u8 slave;
/* only support a single slave addr per transaction */
@@ -1953,8 +1952,15 @@ static int arcturus_i2c_xfer(struct i2c_adapter *i2c_adap,
for (i = 0; i < num; i++) {
if (slave != msgs[i].addr)
return -EINVAL;
- bytes_to_transfer += min(msgs[i].len, available_bytes);
- available_bytes -= bytes_to_transfer;
+
+ available_bytes -= msgs[i].len;
+ if (available_bytes >= 0) {
+ num_done++;
+ } else {
+ /* This message and all the follwing won't be processed */
+ available_bytes += msgs[i].len;
+ break;
+ }
}
req = kzalloc(sizeof(*req), GFP_KERNEL);
@@ -1964,24 +1970,28 @@ static int arcturus_i2c_xfer(struct i2c_adapter *i2c_adap,
req->I2CcontrollerPort = 0;
req->I2CSpeed = I2C_SPEED_FAST_400K;
req->SlaveAddress = slave << 1; /* 8 bit addresses */
- req->NumCmds = bytes_to_transfer;
+ req->NumCmds = MAX_SW_I2C_COMMANDS - available_bytes;;
- remaining_bytes = bytes_to_transfer;
c = 0;
- for (i = 0; i < num; i++) {
+ for (i = 0; i < num_done; i++) {
struct i2c_msg *msg = &msgs[i];
- msg_bytes = min(msg->len, remaining_bytes);
- for (j = 0; j < msg_bytes; j++) {
+ for (j = 0; j < msg->len; j++) {
SwI2cCmd_t *cmd = &req->SwI2cCmds[c++];
- remaining_bytes--;
if (!(msg[i].flags & I2C_M_RD)) {
/* write */
cmd->CmdConfig |= I2C_CMD_WRITE;
cmd->RegisterAddr = msg->buf[j];
}
- if (!remaining_bytes)
+
+ /*
+ * Insert STOP if we are at the last byte of either last
+ * message for the transaction or the client explicitly
+ * requires a STOP at this particular message.
+ */
+ if ((j == msg->len -1 ) &&
+ ((i == num_done - 1) || (msg[i].flags & I2C_M_STOP)))
cmd->CmdConfig |= CMDCONFIG_STOP_MASK;
if ((j == 0) && !(msg[i].flags & I2C_M_NOSTART))
@@ -1994,21 +2004,18 @@ static int arcturus_i2c_xfer(struct i2c_adapter *i2c_adap,
if (r)
goto fail;
- remaining_bytes = bytes_to_transfer;
c = 0;
- for (i = 0; i < num; i++) {
+ for (i = 0; i < num_done; i++) {
struct i2c_msg *msg = &msgs[i];
- msg_bytes = min(msg->len, remaining_bytes);
- for (j = 0; j < msg_bytes; j++) {
+ for (j = 0; j < msg->len; j++) {
SwI2cCmd_t *cmd = &res->SwI2cCmds[c++];
- remaining_bytes--;
if (msg[i].flags & I2C_M_RD)
msg->buf[j] = cmd->Data;
}
}
- r = bytes_to_transfer;
+ r = num_done;
fail:
kfree(req);
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c
index 1741598bc9fe..e2f55727c6fd 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c
@@ -2742,9 +2742,8 @@ static int navi10_i2c_xfer(struct i2c_adapter *i2c_adap,
struct smu_table_context *smu_table = &adev->smu.smu_table;
struct smu_table *table = &smu_table->driver_table;
SwI2cRequest_t *req, *res = (SwI2cRequest_t *)table->cpu_addr;
- u16 bytes_to_transfer, remaining_bytes, msg_bytes;
- u16 available_bytes = MAX_SW_I2C_COMMANDS;
- int i, j, r, c;
+ short available_bytes = MAX_SW_I2C_COMMANDS;
+ int i, j, r, c, num_done = 0;
u8 slave;
/* only support a single slave addr per transaction */
@@ -2752,8 +2751,15 @@ static int navi10_i2c_xfer(struct i2c_adapter *i2c_adap,
for (i = 0; i < num; i++) {
if (slave != msgs[i].addr)
return -EINVAL;
- bytes_to_transfer += min(msgs[i].len, available_bytes);
- available_bytes -= bytes_to_transfer;
+
+ available_bytes -= msgs[i].len;
+ if (available_bytes >= 0) {
+ num_done++;
+ } else {
+ /* This message and all the follwing won't be processed */
+ available_bytes += msgs[i].len;
+ break;
+ }
}
req = kzalloc(sizeof(*req), GFP_KERNEL);
@@ -2763,24 +2769,28 @@ static int navi10_i2c_xfer(struct i2c_adapter *i2c_adap,
req->I2CcontrollerPort = 0;
req->I2CSpeed = I2C_SPEED_FAST_400K;
req->SlaveAddress = slave << 1; /* 8 bit addresses */
- req->NumCmds = bytes_to_transfer;
+ req->NumCmds = MAX_SW_I2C_COMMANDS - available_bytes;;
- remaining_bytes = bytes_to_transfer;
c = 0;
- for (i = 0; i < num; i++) {
+ for (i = 0; i < num_done; i++) {
struct i2c_msg *msg = &msgs[i];
- msg_bytes = min(msg->len, remaining_bytes);
- for (j = 0; j < msg_bytes; j++) {
+ for (j = 0; j < msg->len; j++) {
SwI2cCmd_t *cmd = &req->SwI2cCmds[c++];
- remaining_bytes--;
if (!(msg[i].flags & I2C_M_RD)) {
/* write */
cmd->CmdConfig |= I2C_CMD_WRITE;
cmd->RegisterAddr = msg->buf[j];
}
- if (!remaining_bytes)
+
+ /*
+ * Insert STOP if we are at the last byte of either last
+ * message for the transaction or the client explicitly
+ * requires a STOP at this particular message.
+ */
+ if ((j == msg->len -1 ) &&
+ ((i == num_done - 1) || (msg[i].flags & I2C_M_STOP)))
cmd->CmdConfig |= CMDCONFIG_STOP_MASK;
if ((j == 0) && !(msg[i].flags & I2C_M_NOSTART))
@@ -2793,21 +2803,18 @@ static int navi10_i2c_xfer(struct i2c_adapter *i2c_adap,
if (r)
goto fail;
- remaining_bytes = bytes_to_transfer;
c = 0;
- for (i = 0; i < num; i++) {
+ for (i = 0; i < num_done; i++) {
struct i2c_msg *msg = &msgs[i];
- msg_bytes = min(msg->len, remaining_bytes);
- for (j = 0; j < msg_bytes; j++) {
+ for (j = 0; j < msg->len; j++) {
SwI2cCmd_t *cmd = &res->SwI2cCmds[c++];
- remaining_bytes--;
if (msg[i].flags & I2C_M_RD)
msg->buf[j] = cmd->Data;
}
}
- r = bytes_to_transfer;
+ r = num_done;
fail:
kfree(req);
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
index 7c266420e31c..8f8e5c7df44a 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
@@ -3449,9 +3449,8 @@ static int sienna_cichlid_i2c_xfer(struct i2c_adapter *i2c_adap,
struct smu_table_context *smu_table = &adev->smu.smu_table;
struct smu_table *table = &smu_table->driver_table;
SwI2cRequest_t *req, *res = (SwI2cRequest_t *)table->cpu_addr;
- u16 bytes_to_transfer, remaining_bytes, msg_bytes;
- u16 available_bytes = MAX_SW_I2C_COMMANDS;
- int i, j, r, c;
+ short available_bytes = MAX_SW_I2C_COMMANDS;
+ int i, j, r, c, num_done = 0;
u8 slave;
/* only support a single slave addr per transaction */
@@ -3459,8 +3458,15 @@ static int sienna_cichlid_i2c_xfer(struct i2c_adapter *i2c_adap,
for (i = 0; i < num; i++) {
if (slave != msgs[i].addr)
return -EINVAL;
- bytes_to_transfer += min(msgs[i].len, available_bytes);
- available_bytes -= bytes_to_transfer;
+
+ available_bytes -= msgs[i].len;
+ if (available_bytes >= 0) {
+ num_done++;
+ } else {
+ /* This message and all the follwing won't be processed */
+ available_bytes += msgs[i].len;
+ break;
+ }
}
req = kzalloc(sizeof(*req), GFP_KERNEL);
@@ -3470,24 +3476,28 @@ static int sienna_cichlid_i2c_xfer(struct i2c_adapter *i2c_adap,
req->I2CcontrollerPort = 1;
req->I2CSpeed = I2C_SPEED_FAST_400K;
req->SlaveAddress = slave << 1; /* 8 bit addresses */
- req->NumCmds = bytes_to_transfer;
+ req->NumCmds = MAX_SW_I2C_COMMANDS - available_bytes;;
- remaining_bytes = bytes_to_transfer;
c = 0;
- for (i = 0; i < num; i++) {
+ for (i = 0; i < num_done; i++) {
struct i2c_msg *msg = &msgs[i];
- msg_bytes = min(msg->len, remaining_bytes);
- for (j = 0; j < msg_bytes; j++) {
+ for (j = 0; j < msg->len; j++) {
SwI2cCmd_t *cmd = &req->SwI2cCmds[c++];
- remaining_bytes--;
if (!(msg[i].flags & I2C_M_RD)) {
/* write */
cmd->CmdConfig |= CMDCONFIG_READWRITE_MASK;
cmd->ReadWriteData = msg->buf[j];
}
- if (!remaining_bytes)
+
+ /*
+ * Insert STOP if we are at the last byte of either last
+ * message for the transaction or the client explicitly
+ * requires a STOP at this particular message.
+ */
+ if ((j == msg->len -1 ) &&
+ ((i == num_done - 1) || (msg[i].flags & I2C_M_STOP)))
cmd->CmdConfig |= CMDCONFIG_STOP_MASK;
if ((j == 0) && !(msg[i].flags & I2C_M_NOSTART))
@@ -3500,21 +3510,18 @@ static int sienna_cichlid_i2c_xfer(struct i2c_adapter *i2c_adap,
if (r)
goto fail;
- remaining_bytes = bytes_to_transfer;
c = 0;
- for (i = 0; i < num; i++) {
+ for (i = 0; i < num_done; i++) {
struct i2c_msg *msg = &msgs[i];
- msg_bytes = min(msg->len, remaining_bytes);
- for (j = 0; j < msg_bytes; j++) {
+ for (j = 0; j < msg->len; j++) {
SwI2cCmd_t *cmd = &res->SwI2cCmds[c++];
- remaining_bytes--;
if (msg[i].flags & I2C_M_RD)
msg->buf[j] = cmd->ReadWriteData;
}
}
- r = bytes_to_transfer;
+ r = num_done;
fail:
kfree(req);