ZeroPhone / Discussion-and-Research

General-purpose ZeroPhone discussion (mostly happening in Issues tab)
GNU General Public License v3.0
10 stars 0 forks source link

MCP23017 - tailoring the Linux driver for ZeroPhone needs #16

Open CRImier opened 6 years ago

CRImier commented 6 years ago

There's a Linux driver that controls the MCP23017 IO expander, ZeroPhone uses such an expander for system management functions. We have a problem with it - among all things, the MCP23017 controls a ZeroPhone power switch (active low), which is able to power off the Raspberry Pi Zero. In hardware, the switch is set to "default off", meaning that, in order to power the ZeroPhone up, you need to either plug the charger in or hold a button on the back.

Right now, control of this switch is done in userspace from a systemd script, and only on bootup - it remains on after shutdown, so after ZeroPhone shuts down, there's no way to turn it back on without replugging the batteries (whereas, if the switch were to turn off automatically after shutdown, it'd be enough to hold the power button to power the phone back on).

Additionally, starting from Delta, there's a feature that should technically allow to sense the state of power button while still using a single GPIO. To do that, the GPIO has to be turned off for a short period and set as input with a pullup, so that the actual state of the button can be read - and once it's read, set it to output low again. However, this can't be done from userspace, as the period has to be rather short - if exceeded, the phone will turn off or glitch due to a brownout on the Pi Zero power input, so the period has to be of a reliable length, too (something harder to achieve from userspace). This hardware feature wasn't yet tested, either, so it might happen that, say, capacitor value is insufficient.

For a start, the power switch management needs to be done in a driver, so that:

Here's a schematic of the MCP23017 pinout (on Delta boards):

image

Here's a schematic for the power switch circuit (including the circuitry allowing to sense the power switch state):

image

ZeroPhone uses the ID EEPROM mechanism, which should allow us to load drivers automatically depending on the values flashed into the EEPROM. So, we will likely make different drivers (one per hardware revision) and then flash the driver&overlay names in the EEPROM once the hardware is done.

TODO:

Features that could be added to the driver, but might not have to be:

Links:

CRImier commented 6 years ago

Part of #9 , but better documented, so that it can be used as a specification.