Skip to content

Commit 10330f3

Browse files
ziuziakowskaAlexJones0
authored andcommitted
[ot] docs: opentitan: document I2C Host Proxy in i2c_host_proxy.md
Signed-off-by: Alice Ziuziakowska <[email protected]>
1 parent 28393dd commit 10330f3

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

docs/opentitan/i2c_host_proxy.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# OpenTitan I2C Host Proxy
2+
3+
The `ot-i2c-host-proxy` device provides a way to execute I2C transactions with QEMU I2C bus devices
4+
through an externally driven `chardev` interface.
5+
6+
The device can perform read or write transactions with bus devices and is intended to be used to
7+
drive the Opentitan I2C device Target mode, though it can be used to interact with other devices on
8+
the QEMU I2C buses.
9+
10+
## Configuration
11+
12+
A chardev and proxy device can be created in QEMU with the following arguments:
13+
14+
`-chardev pty,i2cN -device ot-i2c-host-proxy,bus=<bus>,chardev=i2cN`
15+
16+
Where `bus` is any of the system's I2C buses. On Earl Grey for example, these are `ot-i2c0`,
17+
`ot-i2c1`, and `ot-i2c2`.
18+
19+
## Protocol
20+
21+
The protocol over the chardev mirrors the I2C specification closely.
22+
23+
Before each transaction, the protocol version must be sent. This is sent as an `i` byte (for I2C),
24+
followed by the version number byte (currently 1). The device will respond with an ACK byte
25+
(see below) if the version matches the implementation, and a NACK byte otherwise.
26+
27+
A start and repeated start condition is signalled with an `S` byte, followed by a byte containing
28+
the 7-bit target address of the transaction and the read/write bit as the least significant bit
29+
(0 indicates a write transfer, 1 indicates a read transfer).
30+
31+
On a repeated start condition, the I2C target address of the first transfer will be used, and the
32+
provided address is ignored (transfer direction can be changed). This is a limitation of QEMU.
33+
34+
When a read transfer is active, a `R` byte can be sent to read a byte of data from the target I2C
35+
device.
36+
37+
When a write transfer is active, a `W` byte, followed by a data byte, can be sent to write that
38+
byte to the target I2C device.
39+
40+
A stop condition to end the transaction is signalled with a `P` byte.
41+
42+
Following a start/repeated start condition and the address byte, as well as after every byte
43+
written during a write transfer, an ACK is signalled with a `.` byte, and a NACK is signalled with
44+
a `!` byte. If the start of a transfer is NACKed, the transaction should be terminated with a stop
45+
condition.
46+
47+
On a parser error, a `x` byte will be returned, and the parser will not accept any more command
48+
bytes until reset.
49+
50+
The implementation will throttle processing of written bytes to allow control to return to the
51+
vCPU, so that OT I2C may process the current transaction and prepare response bytes for upcoming
52+
reads.

0 commit comments

Comments
 (0)