Skip to content

Commit

Permalink
i2c-bcm2835: Implement I2C_M_IGNORE_NAK
Browse files Browse the repository at this point in the history
Now that transfers aren't aborted immediately (and uncleanly) on
errors, and the FIFOs are always drained after all transfers, we
can implement I2C_M_IGNORE_NAK by ignoring the returned error
value.

Signed-off-by: Dave Stevenson <[email protected]>
  • Loading branch information
6by9 authored and pelwell committed May 25, 2023
1 parent 1b57d40 commit 8c4f88c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions drivers/i2c/busses/i2c-bcm2835.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ static int bcm2835_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
{
struct bcm2835_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
unsigned long time_left;
bool ignore_nak = false;
int i;

if (debug)
Expand All @@ -452,12 +453,15 @@ static int bcm2835_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
for (i = 0; i < num; i++)
bcm2835_debug_print_msg(i2c_dev, &msgs[i], i + 1, num, __func__);

for (i = 0; i < (num - 1); i++)
for (i = 0; i < (num - 1); i++) {
if (msgs[i].flags & I2C_M_RD) {
dev_warn_once(i2c_dev->dev,
"only one read message supported, has to be last\n");
return -EOPNOTSUPP;
}
if (msgs[i].flags & I2C_M_IGNORE_NAK)
ignore_nak = true;
}

i2c_dev->curr_msg = msgs;
i2c_dev->num_msgs = num;
Expand All @@ -471,6 +475,9 @@ static int bcm2835_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],

bcm2835_i2c_finish_transfer(i2c_dev);

if (ignore_nak)
i2c_dev->msg_err &= ~BCM2835_I2C_S_ERR;

if (debug > 1 || (debug && (!time_left || i2c_dev->msg_err)))
bcm2835_debug_print(i2c_dev);
i2c_dev->debug_num_msgs = 0;
Expand All @@ -497,7 +504,7 @@ static int bcm2835_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],

static u32 bcm2835_i2c_func(struct i2c_adapter *adap)
{
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING;
}

static const struct i2c_algorithm bcm2835_i2c_algo = {
Expand Down

0 comments on commit 8c4f88c

Please sign in to comment.