2020–11–30:
Improved ANX7688 driver and increased I2C speed
I've looked again at the mud stained hair ball that is ANX7688 firmware and
extended my driver to better work with the USB-C docks when the docks are
powered. The driver now works better also with other USB-PD enabled devices.
The changes mostly relate to making sure Pinephone will not overload a PD
charger or a dock when powered from said dock. USB-C, USB-PD, and BC 1.2 specs
specify various methods for determining the the current that can be used by the
device, and it's quite complicated to put it all together reliably.
The approach the driver takes now is to wait for 3s after the cable is
plugged in, and if no power source announces itself via a PD message, it will
fallback to determining the maximum input current from the resistors connected
to the CC pins. If the power source announces itself via PD message, the driver
will wait 0.5s after the ANX7688 FW forwards the announcement and ramps up the
input current limit to the one hopefully negotiated with the power source by the
ANX7688 firmware.
After quite some testing, this approach seems to work for most of the USB-C
devices and their combinations that I have at home, except for:
- connecting two pinephones together (ANX7688 firmware seemingly doesn't
negotiate properly with other devices running the same firmware)
- PINE64 dock when powered by by external charger is detected/or asks for its
USB port to be treated as a host port (this is either the dock's bug, or
ANX7688 FW bug, though other dock that I have works correctly so it's likely
to be a bug in the PINE64 dock)
- PINE64 dock issue was present in my 5.9 kernel too, so at least that is not
a regression
Most of the new patches are available here https://megous.com/git/linux/log/?h=anx-5.10
I've also bumped the I2C bus speed to 400kHz, which should make communication
with I2C devices faster. This may be noticeable when using the touchscreen (~4ms
shorter input latency).
One last thing I've changed was configuring PMIC via p-boot to limit power
consumption, so that VBUS voltage never drops below 4.5V. This does away with
USB-PD hard resets I've seen when using my USB-PD 5V/3A charger with Pinephone.
USB-PD controllers probably do some VBUS voltage monitoring (ANX7688 does for
sure), and try to recover when VBUS drops bellow certain threshold.
The patch is in p-boot for now: https://megous.com/git/p-boot/commit/?id=a80cac6bdea170ddeaee9475c976ba76558839ed
With this I could charge my Pinephone from USB-C PD charger without a single
hard reset. Previously there were many.