mirror of
https://github.com/AsahiLinux/m1n1
synced 2024-11-10 01:34:12 +00:00
i2c: Make error paths wait for bus in i2c_smbus_read
Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
64cb9892b1
commit
e1515b4376
3 changed files with 11 additions and 7 deletions
13
src/i2c.c
13
src/i2c.c
|
@ -121,18 +121,20 @@ static int i2c_xfer_write(i2c_dev_t *dev, u8 addr, u32 start, u32 stop, const u8
|
|||
return 0;
|
||||
}
|
||||
|
||||
size_t i2c_smbus_read(i2c_dev_t *dev, u8 addr, u8 reg, u8 *bfr, size_t len)
|
||||
int i2c_smbus_read(i2c_dev_t *dev, u8 addr, u8 reg, u8 *bfr, size_t len)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
i2c_clear_fifos(dev);
|
||||
i2c_clear_status(dev);
|
||||
|
||||
if (i2c_xfer_write(dev, addr, 1, 1, ®, 1))
|
||||
return 0;
|
||||
goto err;
|
||||
|
||||
i2c_xfer_start_read(dev, addr, len + 1);
|
||||
u8 len_reply;
|
||||
if (i2c_xfer_read(dev, &len_reply, 1) != 1)
|
||||
return 0;
|
||||
goto err;
|
||||
|
||||
if (len_reply < len)
|
||||
printf("i2c: want to read %ld bytes from addr %d but can only read %d\n", len, addr,
|
||||
|
@ -141,14 +143,15 @@ size_t i2c_smbus_read(i2c_dev_t *dev, u8 addr, u8 reg, u8 *bfr, size_t len)
|
|||
printf("i2c: want to read %ld bytes from addr %d but device wants to send %d\n", len, addr,
|
||||
len_reply);
|
||||
|
||||
size_t read = i2c_xfer_read(dev, bfr, min(len, len_reply));
|
||||
ret = i2c_xfer_read(dev, bfr, min(len, len_reply));
|
||||
|
||||
err:
|
||||
if (poll32(dev->base + PASEMI_STATUS, PASEMI_STATUS_XFER_BUSY, 0, 1000)) {
|
||||
printf("i2c: timeout while waiting for PASEMI_STATUS_XFER_BUSY to clear after read xfer\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return read;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int i2c_smbus_write(i2c_dev_t *dev, u8 addr, u8 reg, const u8 *bfr, size_t len)
|
||||
|
|
|
@ -10,7 +10,7 @@ typedef struct i2c_dev i2c_dev_t;
|
|||
i2c_dev_t *i2c_init(const char *adt_node);
|
||||
void i2c_shutdown(i2c_dev_t *dev);
|
||||
|
||||
size_t i2c_smbus_read(i2c_dev_t *dev, u8 addr, u8 reg, u8 *bfr, size_t len);
|
||||
int i2c_smbus_read(i2c_dev_t *dev, u8 addr, u8 reg, u8 *bfr, size_t len);
|
||||
int i2c_smbus_write(i2c_dev_t *dev, u8 addr, u8 reg, const u8 *bfr, size_t len);
|
||||
|
||||
int i2c_smbus_read32(i2c_dev_t *dev, u8 addr, u8 reg, u32 *val);
|
||||
|
|
|
@ -70,7 +70,8 @@ int tps6598x_command(tps6598x_dev_t *dev, const char *cmd, const u8 *data_in, si
|
|||
} while (cmd_status != 0);
|
||||
|
||||
if (len_out) {
|
||||
if (i2c_smbus_read(dev->i2c, dev->addr, TPS_REG_DATA1, data_out, len_out) != len_out)
|
||||
if (i2c_smbus_read(dev->i2c, dev->addr, TPS_REG_DATA1, data_out, len_out) !=
|
||||
(ssize_t)len_out)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue