From: Andrey Grodzovsky <andrey.grodzovsky@xxxxxxx> Fix from number of processed bytes to number of processed I2C messages. Cc: Jean Delvare <jdelvare@xxxxxxx> Cc: Alexander Deucher <Alexander.Deucher@xxxxxxx> Cc: Andrey Grodzovsky <Andrey.Grodzovsky@xxxxxxx> Cc: Lijo Lazar <Lijo.Lazar@xxxxxxx> Cc: Stanley Yang <Stanley.Yang@xxxxxxx> Cc: Hawking Zhang <Hawking.Zhang@xxxxxxx> Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@xxxxxxx> Signed-off-by: Luben Tuikov <luben.tuikov@xxxxxxx> Reviewed-by: Luben Tuikov <luben.tuikov@xxxxxxx> --- .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 43 +++++++++++-------- .../gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 43 +++++++++++-------- .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 43 +++++++++++-------- 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 235e83e9f0feb7..409299a608e1b3 100644 --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c @@ -1913,9 +1913,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 */ @@ -1923,8 +1922,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); @@ -1934,24 +1940,28 @@ static int arcturus_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 |= 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)) @@ -1964,21 +1974,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 b94c5a1d3eb756..4010b891f25678 100644 --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c @@ -2708,9 +2708,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 */ @@ -2718,8 +2717,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); @@ -2729,24 +2735,28 @@ static int navi10_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 |= 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)) @@ -2759,21 +2769,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 2fa667a86c1a54..d5b750d84112fa 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 @@ -3396,9 +3396,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 */ @@ -3406,8 +3405,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); @@ -3417,24 +3423,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)) @@ -3447,21 +3457,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); -- 2.32.0 _______________________________________________ amd-gfx mailing list amd-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/amd-gfx