From: Andrey Grodzovsky Date: Tue, 26 Jan 2021 17:09:18 +0000 (-0500) Subject: drm/amd/pm: SMU I2C: Return number of messages processed X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=14df56504fdf5d1e84096a4818ff7efc891bfdb6;p=linux.git 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 Cc: Alexander Deucher Cc: Andrey Grodzovsky Cc: Lijo Lazar Cc: Stanley Yang Cc: Hawking Zhang Signed-off-by: Andrey Grodzovsky Signed-off-by: Luben Tuikov Reviewed-by: Luben Tuikov Reviewed-by: Alexander Deucher Signed-off-by: Alex Deucher --- 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 efbb24ae4ad30..b26cfa994c278 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 1741598bc9fea..e2f55727c6fde 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 7c266420e31cc..8f8e5c7df44a1 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);