HomeFreeBSD

twsi: support more message combinations in transfers

Description

twsi: support more message combinations in transfers

Most prominently, add support for a transfer where a write with no-stop
flag is followed by a write with no-start flag. Logically, it's a
single larger write, but consumers may want to split it like that
because one part can be a register ID and the other part can be data to
be written to (or starting at) that register.

Such a transfer can be created by i2c tool and iic(4) driver, e.g., for
an EEPROM write at specific offset:

i2c -m tr -a 0x50 -d w -w 16 -o 0 -c 8 -v < /dev/random

This should be fixed by new code that handles the end of data transfer
for both reads and writes. It handles two existing conditions and one
new. Namely:

  • the last message has been completed -- end of transfer;
  • a message has been completed and the next one requires the start condition;
  • a message has been completed and the next one should be sent without the start condition.

In the last case we simply switch to the next message and start sending
its data. Reads without the start condition are not supported yet,
though. That's because we NACK the last byte of the previous message,
so the device stops sending data. To fix this we will need to add a
look-ahead at the next message when handling the penultimate byte of the
current one.

This change also fixed a bug where msg_idx was not incremented after a
read message. Apparently, typically a read message is a last message in
a transfer, so the bug did not cause much trouble.

PR: 258994

(cherry picked from commit ff1e8581806f70e54fecddf8a6a23488dc7b968a)

Details

Provenance
avgAuthored on Nov 26 2021, 9:48 AM
Parents
rG3fab2b02d69b: twsi: make data receiving code safer
Branches
Unknown
Tags
Unknown