Page MenuHomeFreeBSD

[PREVIEW] twsi: fixes, improvements, cleanups
Needs ReviewPublic

Authored by avg on Aug 12 2020, 8:34 PM.

Details

Reviewers
manu
Summary

List of changes in no particular order.

twsi_transfer and twsi_intr are now protected with the mutex to
ensure a consistent view of the state.

msleep is paired with wakeup.
All wakeup calls are consolidtaed.

The control register is written exactly once in response to hardware events.
The hardware executes a next stage of I2C protocol when the interrupt flag is cleared,
so it is much easier to reason about what happens when with a single write to
the control register.

Improved diagnostic messages and code formatting.
Support for diagnostic messages is always compiled in
with the actual printing controlled via a sysctl (disabled by default).
I2C is not super-fast protocols, so having a bunch of extra condition checks
should not hurt the performance.
Also, debug messages in register access functions require a higher debug level
as their information is mostly redundant.

Support for more transfer combinations and types.
Examples:

  • zero length transfers (start-address-stop),
  • a write message with NO_STOP followed by another write message,
  • a read message with NO_STOP flag followed by a write message (with implied repeated start)

Somewhat better code structure to handle conditions like end of message,
end of all messages.

Detect and handle more unexpected conditions.

Always send STOP when any error (or unexpected condition) is detected.

Ensure that TWSI_CONTROL_ACK is always correctly or cleared depending on
how many octets we expect to receive.

Add KASSERT-s to ensure that the code correctly follows octet counts and
never tries to write or read beyond message data buffers.

Test Plan

Tested with:

  • DS1307 RTC (ds1307)
  • AT24C32 EEPROM (icee)
  • HTU21D temperature and humidity sensor (htu21, to be submitted later)
  • PCF8591 ADC/DAC (pcf8591, to be submitted later)
  • MAX44009 light sensor (max44009, to be submitted later)
  • TCA9548 I2C switch (pca954x, to be submitted later)

All with a10_twsi on an Allwinner H3 based board.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 34029
Build 31216: arc lint + arc unit

Event Timeline

avg requested review of this revision.Aug 12 2020, 8:34 PM

Added a few comments on what could be commited now.
I need to test on different allwinner devices (A20 for example fails to boot without i2c as the pmic sits on this bus) for the rest.

sys/dev/iicbus/twsi/twsi.c
505

This can go it now.

529

Same, this can go in now.

579

Same, this can go in now.

638–639

Same, this can go in now.

739–740

Same, this can go in now.

Update with the latest work in progress.

avg retitled this revision from twsi: better support for some messages sequences, plus small cleanups to [PREVIEW] twsi: fixes, improvements, cleanups.Sep 3 2020, 8:59 AM
avg edited the summary of this revision. (Show Details)
avg edited the test plan for this revision. (Show Details)
avg edited the summary of this revision. (Show Details)

rebase