Page MenuHomeFreeBSD

[PREVIEW] twsi: fixes, improvements, cleanups
AbandonedPublic

Authored by avg on Aug 12 2020, 8:34 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 20, 6:10 PM
Unknown Object (File)
Dec 23 2023, 2:43 AM
Unknown Object (File)
Dec 14 2023, 2:46 PM
Unknown Object (File)
Nov 10 2023, 2:44 PM
Unknown Object (File)
Nov 8 2023, 8:54 AM
Unknown Object (File)
Nov 7 2023, 4:44 AM
Unknown Object (File)
Nov 4 2023, 5:14 PM
Unknown Object (File)
Oct 9 2023, 1:42 PM
Subscribers

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 - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 32956
Build 30350: 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
494

This can go it now.

518

Same, this can go in now.

550

Same, this can go in now.

592

Same, this can go in now.

686

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

This has been committed in ff1e8581806f7 and other commits.