Bug 247576 - [regression] v356609 breaks i2c on Allwinner H5
Summary: [regression] v356609 breaks i2c on Allwinner H5
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-arm (Nobody)
Depends on:
Reported: 2020-06-27 08:50 UTC by Manuel Stühn
Modified: 2020-07-09 16:22 UTC (History)
1 user (show)

See Also:

Fix twsi bug (1.49 KB, patch)
2020-07-05 17:12 UTC, Emmanuel Vadot
no flags Details | Diff
Fix twsi bug (5.68 KB, patch)
2020-07-06 17:33 UTC, Emmanuel Vadot
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Manuel Stühn 2020-06-27 08:50:53 UTC
Commit https://svnweb.freebsd.org/base?view=revision&revision=356609 breaks the I2C on my Allwinner H5 based NanoPI NEO2. If i revert this one commit, I'm able to use the I2C 0.96" OLED again (CURRENT v362543).

Unfortunately i'm not able to provide much debug information because all the programs using i2c (i2c -s for example) do simply not return. They do provide no error messages, they cannot be aborted via ctrl-c. top(1) shows as state for those processes "twi".
Comment 1 Emmanuel Vadot freebsd_committer 2020-07-05 17:12:43 UTC
Created attachment 216223 [details]
Fix twsi bug

Could you test the attached patch ?
This fix two things :
When we don't receive an ack we still send a stop bit, some (most/all ?) device don't send a ack for the last transmitted bit. Not doing this make the controller goes crazy.
Some IP (Like H3/H5) have a bug where we need to write to the control register with the interrupt enabled flag after each interrupts have fired once.
Comment 2 Manuel Stühn 2020-07-06 16:54:45 UTC
This patch works for me.
Thank you!
Comment 3 Emmanuel Vadot freebsd_committer 2020-07-06 17:14:16 UTC
(In reply to Manuel Stühn from comment #2)
That's good that it works for you but it's still not good :)
I've fixed more bug and will post a new patch tonight (even if not finished).
Comment 4 Emmanuel Vadot freebsd_committer 2020-07-06 17:33:11 UTC
Created attachment 216261 [details]
Fix twsi bug

Could you test this patch too ?
I still have weird stuff happening but it might be that I'm not talking correctly to the device.
Comment 5 Manuel Stühn 2020-07-06 19:17:20 UTC
Also the new patch works (was the eeprom@50 change in sun8i-h3-i2c0.dtso intentional?). Nevertheless, i2c -s finds the display at address 0x3C and to the display can be written to.

Thanks again.
Comment 6 Emmanuel Vadot freebsd_committer 2020-07-06 19:42:50 UTC
(In reply to Manuel Stühn from comment #5)
No the dtso was just a local change that I included by mistake.
Thanks for testing, I'll do more work into this and will commit a proper version before saturday after more testing.
Comment 7 commit-hook freebsd_committer 2020-07-08 19:15:31 UTC
A commit references this bug:

Author: manu
Date: Wed Jul  8 19:14:44 UTC 2020
New revision: 363021
URL: https://svnweb.freebsd.org/changeset/base/363021

  twsi: Fix for > Allwinner A20

  Every revision of twsi after the A20 have a bug where we need to
  write again the control register after each interrupts. We also need
  to add some delay before writing to this register, a simple read of the
  same register does the job so do that.
  Also fix the case when we have finish sending all the bytes, it only worked
  for 1 byte transfer (the same kind that we do for talking to the PMIC on A20
  While here add more debug messages and rework some of them.

  This was tested by talking to a AT23C32 eeprom and a DS3231 RTC from an
  H3 and A20 board.

  PR:		247576
  Reported by:	Manuel St?hn (freebsd@justmail.de)
  MFC after:	1 week

Comment 8 Manuel Stühn 2020-07-09 16:22:34 UTC
Tested the commited revision. Works fine for me.

Thanks again.