Skip to content

Commit 45c03c6

Browse files
author
Wolfram Sang
committed
i2c: testunit: return current command on read messages
Because the testunit can start tests in the future via the DELAY register, it may happen that a command is still pending. Support detecting that by returning the number of a command in progress (if there is one). Signed-off-by: Wolfram Sang <[email protected]>
1 parent 6b21470 commit 45c03c6

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Documentation/i2c/slave-testunit-backend.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ Instantiating the device is regular. Example for bus 0, address 0x30::
2020

2121
# echo "slave-testunit 0x1030" > /sys/bus/i2c/devices/i2c-0/new_device
2222

23-
After that, you will have a write-only device listening. Reads will just return
24-
an 8-bit version number of the testunit. When writing, the device consists of 4
25-
8-bit registers and, except for some "partial" commands, all registers must be
26-
written to start a testcase, i.e. you usually write 4 bytes to the device. The
27-
registers are:
23+
After that, you will have the device listening. Reading will return a single
24+
byte. Its value is 0 if the testunit is idle, otherwise the command number of
25+
the currently running command.
26+
27+
When writing, the device consists of 4 8-bit registers and, except for some
28+
"partial" commands, all registers must be written to start a testcase, i.e. you
29+
usually write 4 bytes to the device. The registers are:
2830

2931
.. csv-table::
3032
:header: "Offset", "Name", "Description"
@@ -170,4 +172,4 @@ are not equivalent to a REPEATED START. As an example, this returns just the
170172
default response::
171173

172174
# i2cset -y 0 0x30 4 0 0 i; i2cget -y 0 0x30
173-
0x01
175+
0x00

drivers/i2c/i2c-slave-testunit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <linux/slab.h>
1616
#include <linux/workqueue.h> /* FIXME: is system_long_wq the best choice? */
1717

18-
#define TU_CUR_VERSION 0x01
1918
#define TU_VERSION_MAX_LENGTH 128
2019

2120
enum testunit_cmds {
@@ -159,7 +158,8 @@ static int i2c_slave_testunit_slave_cb(struct i2c_client *client,
159158
else if (is_proc_call)
160159
*val = tu->regs[TU_REG_DATAH];
161160
else
162-
*val = TU_CUR_VERSION;
161+
*val = test_bit(TU_FLAG_IN_PROCESS, &tu->flags) ?
162+
tu->regs[TU_REG_CMD] : 0;
163163
break;
164164
}
165165

0 commit comments

Comments
 (0)