Skip to content

Commit 6ad30f7

Browse files
author
Wolfram Sang
committed
i2c: testunit: on errors, repeat NACK until STOP
This backend requests a NACK from the controller driver when it detects an error. If that request gets ignored from some reason, subsequent accesses will wrongly be handled OK. To fix this, an error now changes the state machine, so the backend will report NACK until a STOP condition has been detected. This make the driver more robust against controllers which will sadly apply the NACK not to the current byte but the next one. Fixes: a8335c6 ("i2c: add slave testunit driver") Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
1 parent 093f70c commit 6ad30f7

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

drivers/i2c/i2c-slave-testunit.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ enum testunit_regs {
3838

3939
enum testunit_flags {
4040
TU_FLAG_IN_PROCESS,
41+
TU_FLAG_NACK,
4142
};
4243

4344
struct testunit_data {
@@ -90,17 +91,21 @@ static int i2c_slave_testunit_slave_cb(struct i2c_client *client,
9091

9192
switch (event) {
9293
case I2C_SLAVE_WRITE_REQUESTED:
93-
if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags))
94-
return -EBUSY;
94+
if (test_bit(TU_FLAG_IN_PROCESS | TU_FLAG_NACK, &tu->flags)) {
95+
ret = -EBUSY;
96+
break;
97+
}
9598

9699
memset(tu->regs, 0, TU_NUM_REGS);
97100
tu->reg_idx = 0;
98101
tu->read_idx = 0;
99102
break;
100103

101104
case I2C_SLAVE_WRITE_RECEIVED:
102-
if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags))
103-
return -EBUSY;
105+
if (test_bit(TU_FLAG_IN_PROCESS | TU_FLAG_NACK, &tu->flags)) {
106+
ret = -EBUSY;
107+
break;
108+
}
104109

105110
if (tu->reg_idx < TU_NUM_REGS)
106111
tu->regs[tu->reg_idx] = *val;
@@ -129,6 +134,8 @@ static int i2c_slave_testunit_slave_cb(struct i2c_client *client,
129134
* here because we still need them in the workqueue!
130135
*/
131136
tu->reg_idx = 0;
137+
138+
clear_bit(TU_FLAG_NACK, &tu->flags);
132139
break;
133140

134141
case I2C_SLAVE_READ_PROCESSED:
@@ -151,6 +158,10 @@ static int i2c_slave_testunit_slave_cb(struct i2c_client *client,
151158
break;
152159
}
153160

161+
/* If an error occurred somewhen, we NACK everything until next STOP */
162+
if (ret)
163+
set_bit(TU_FLAG_NACK, &tu->flags);
164+
154165
return ret;
155166
}
156167

0 commit comments

Comments
 (0)