OTG_CONFIG=1 When It Shouldn't Be
The BQ25895's OTG_CONFIG bit is not being set to 1 on the basis of the TPS65982's VconnEnabled, DataRole, PortRole, ConnState, and PlugPresent bits. It seems to always be set to 1, which means if the OTG pin is set to 1 then we will waste energy (less battery life).
From what I tested, we can use the TPS65982's 0x1A status register to determine when the BQ25895's boost mode should be enabled (when OTG_CONFIG=1 and/or when the OTG pin is set HIGH). The least significant byte in the status register tells us if the phone needs to supply VBUS and has negotiated to be a PD source:
Here is what you would get if the phone is a PD sink, connected to a host that is supplying VBUS:
purism@pureos:~$ sudo i2ctransfer -f -y 0 w1@0x3f 0x1a r5
0x04 0x0d 0x0c 0x94 0x01
0x0d here tells us VconnEnabled=0, DataRole=0, PortRole=0, ConnState=110, and PlugPresent=1. This allows us to know that we are connected to a USB PD source and do not need to put the BQ25895 into its OTG boost mode.
Here is what you would get if the phone is a PD source, connected to a device that needs VBUS to be supplied to it:
purism@pureos:~$ sudo i2ctransfer -f -y 0 w1@0x3f 0x1a r5
0x04 0x7d 0x00 0x14 0x01
In this case, 0x7d tell us connEnabled=1, DataRole=1, PortRole=1, ConnState=110, and PlugPresent=1. This allows us to know that we are connected to a USB PD sink. However, 0x00 shows us that PP_5V0 switch is disabled because the BQ25895 is not in its boost mode. When we find that we're connected to a USB PD sink we can put the BQ25895 into its OTG mode to supply VBUS, this is how that could happen:
purism@pureos:~$ sudo i2ctransfer -f -y 0 w1@0x3f 0x1a r5
0x04 0x7d 0x00 0x14 0x01
purism@pureos:~$ echo 255 | sudo tee /sys/class/leds/chg_otg_en/brightness
255
purism@pureos:~$ sudo i2ctransfer -f -y 0 w1@0x3f 0x1a r5
0x04 0x7d 0x02 0x14 0x01
As you can see, the 0x00 become 0x02, showing us that PP_5V0 is enabled and the phone is supplying 5V to VBUS (as was shown by my USB-C meter dongle thing during my test). We could use OTG_CONFIG instead of the OTG GPIO to accomplish the same thing, but we need to make sure we leave OTG_CONFIG=0 in all other conditions.
When nothing is connected to the USB-C port it is quite obvious that nothing is there and we should not put the BQ25895 into its boost mode. We can determine this simply by seeing if the least significant bit (PlugPresent) of the TPS65982's 0x1A register is 0 or 1.
Here's what I get when nothing is inserted:
purism@pureos:~$ sudo i2ctransfer -f -y 0 w1@0x3f 0x1a r5
0x04 0x60 0x00 0x14 0x01
I've also gotten this:
purism@pureos:~$ sudo i2ctransfer -f -y 0 w1@0x3f 0x1a r5
0x04 0x40 0x00 0x14 0x01
Which shows that the DataRole and PortRole bits are meaningless when there is nothing inserted, but the PlugPresent bit tells us whether or not something is actually connected.