[PATCH 40/40] drm/amdgpu: Use a single loop

Alex Deucher alexdeucher at gmail.com
Thu Jun 10 21:25:22 UTC 2021


On Tue, Jun 8, 2021 at 5:41 PM Luben Tuikov <luben.tuikov at amd.com> wrote:
>
> In smu_v11_0_i2c_transmit() use a single loop to
> transmit bytes, instead of two nested loops.
>
> Cc: Alexander Deucher <Alexander.Deucher at amd.com>
> Cc: Andrey Grodzovsky <Andrey.Grodzovsky at amd.com>
> Signed-off-by: Luben Tuikov <luben.tuikov at amd.com>

Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/smu_v11_0_i2c.c | 72 ++++++++++------------
>  1 file changed, 34 insertions(+), 38 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/smu_v11_0_i2c.c b/drivers/gpu/drm/amd/amdgpu/smu_v11_0_i2c.c
> index 7f48ee020bc03e..751ea2517c4380 100644
> --- a/drivers/gpu/drm/amd/amdgpu/smu_v11_0_i2c.c
> +++ b/drivers/gpu/drm/amd/amdgpu/smu_v11_0_i2c.c
> @@ -243,49 +243,45 @@ static uint32_t smu_v11_0_i2c_transmit(struct i2c_adapter *control,
>         /* Clear status bits */
>         smu_v11_0_i2c_clear_status(control);
>
> -
>         timeout_counter = jiffies + msecs_to_jiffies(20);
>
>         while (numbytes > 0) {
>                 reg = RREG32_SOC15(SMUIO, 0, mmCKSVII2C_IC_STATUS);
> -               if (REG_GET_FIELD(reg, CKSVII2C_IC_STATUS, TFNF)) {
> -                       do {
> -                               reg = REG_SET_FIELD(reg, CKSVII2C_IC_DATA_CMD, DAT, data[bytes_sent]);
> -
> -                               /* Final message, final byte, must
> -                                * generate a STOP, to release the
> -                                * bus, i.e. don't hold SCL low.
> -                                */
> -                               if (numbytes == 1 && i2c_flag & I2C_M_STOP)
> -                                       reg = REG_SET_FIELD(reg,
> -                                                           CKSVII2C_IC_DATA_CMD,
> -                                                           STOP, 1);
> -
> -                               if (bytes_sent == 0 && i2c_flag & I2C_X_RESTART)
> -                                       reg = REG_SET_FIELD(reg,
> -                                                           CKSVII2C_IC_DATA_CMD,
> -                                                           RESTART, 1);
> -
> -                               /* Write */
> -                               reg = REG_SET_FIELD(reg, CKSVII2C_IC_DATA_CMD, CMD, 0);
> -                               WREG32_SOC15(SMUIO, 0, mmCKSVII2C_IC_DATA_CMD, reg);
> -
> -                               /* Record that the bytes were transmitted */
> -                               bytes_sent++;
> -                               numbytes--;
> -
> -                               reg = RREG32_SOC15(SMUIO, 0, mmCKSVII2C_IC_STATUS);
> -
> -                       } while (numbytes &&  REG_GET_FIELD(reg, CKSVII2C_IC_STATUS, TFNF));
> -               }
> +               if (!REG_GET_FIELD(reg, CKSVII2C_IC_STATUS, TFNF)) {
> +                       /*
> +                        * We waited for too long for the transmission
> +                        * FIFO to become not-full.  Exit the loop
> +                        * with error.
> +                        */
> +                       if (time_after(jiffies, timeout_counter)) {
> +                               ret |= I2C_SW_TIMEOUT;
> +                               goto Err;
> +                       }
> +               } else {
> +                       reg = REG_SET_FIELD(reg, CKSVII2C_IC_DATA_CMD, DAT,
> +                                           data[bytes_sent]);
>
> -               /*
> -                * We waited too long for the transmission FIFO to become not-full.
> -                * Exit the loop with error.
> -                */
> -               if (time_after(jiffies, timeout_counter)) {
> -                       ret |= I2C_SW_TIMEOUT;
> -                       goto Err;
> +                       /* Final message, final byte, must generate a
> +                        * STOP to release the bus, i.e. don't hold
> +                        * SCL low.
> +                        */
> +                       if (numbytes == 1 && i2c_flag & I2C_M_STOP)
> +                               reg = REG_SET_FIELD(reg,
> +                                                   CKSVII2C_IC_DATA_CMD,
> +                                                   STOP, 1);
> +
> +                       if (bytes_sent == 0 && i2c_flag & I2C_X_RESTART)
> +                               reg = REG_SET_FIELD(reg,
> +                                                   CKSVII2C_IC_DATA_CMD,
> +                                                   RESTART, 1);
> +
> +                       /* Write */
> +                       reg = REG_SET_FIELD(reg, CKSVII2C_IC_DATA_CMD, CMD, 0);
> +                       WREG32_SOC15(SMUIO, 0, mmCKSVII2C_IC_DATA_CMD, reg);
> +
> +                       /* Record that the bytes were transmitted */
> +                       bytes_sent++;
> +                       numbytes--;
>                 }
>         }
>
> --
> 2.32.0
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx


More information about the amd-gfx mailing list