Skip to content

Commit

Permalink
i2c: core: ACPI: Properly set status byte to 0 for multi-byte writes
Browse files Browse the repository at this point in the history
acpi_gsb_i2c_write_bytes() returns i2c_transfer()'s return value, which
is the number of transfers executed on success, so 1.

The ACPI code expects us to store 0 in gsb->status for success, not 1.

Specifically this breaks the following code in the Thinkpad 8 DSDT:

            ECWR = I2CW = ECWR /* \_SB_.I2C1.BAT0.ECWR */
            If ((ECST == Zero))
            {
                ECRD = I2CR /* \_SB_.I2C1.I2CR */
            }

Before this commit we set ECST to 1, causing the read to never happen
breaking battery monitoring on the Thinkpad 8.

This commit makes acpi_gsb_i2c_write_bytes() return 0 when i2c_transfer()
returns 1, so the single write transfer completed successfully, and
makes it return -EIO on for other (unexpected) return values >= 0.

Cc: [email protected]
Signed-off-by: Hans de Goede <[email protected]>
Acked-by: Mika Westerberg <[email protected]>
Signed-off-by: Wolfram Sang <[email protected]>
  • Loading branch information
jwrdegoede authored and Wolfram Sang committed Aug 20, 2018
1 parent 0857f50 commit c463a15
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions drivers/i2c/i2c-core-acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,16 @@ static int acpi_gsb_i2c_write_bytes(struct i2c_client *client,
msgs[0].buf = buffer;

ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
if (ret < 0)
dev_err(&client->adapter->dev, "i2c write failed\n");

kfree(buffer);
return ret;

if (ret < 0) {
dev_err(&client->adapter->dev, "i2c write failed: %d\n", ret);
return ret;
}

/* 1 transfer must have completed successfully */
return (ret == 1) ? 0 : -EIO;
}

static acpi_status
Expand Down

0 comments on commit c463a15

Please sign in to comment.