Page MenuHomeFreeBSD

[PREVIEW] twsi: fixes, improvements, cleanups
AbandonedPublic

Authored by avg on Aug 12 2020, 8:34 PM.
Tags
None
Referenced Files
F102355672: D26049.diff
Mon, Nov 11, 3:44 AM
Unknown Object (File)
Fri, Oct 18, 6:26 PM
Unknown Object (File)
Oct 8 2024, 5:37 PM
Unknown Object (File)
Oct 2 2024, 6:34 PM
Unknown Object (File)
Oct 2 2024, 2:37 PM
Unknown Object (File)
Oct 1 2024, 5:24 AM
Unknown Object (File)
Sep 30 2024, 5:04 PM
Unknown Object (File)
Sep 30 2024, 1:13 AM
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 33355
Build 30664: 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
506

This can go it now.

530

Same, this can go in now.

580

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

This has been committed in ff1e8581806f7 and other commits.