From 528fe7e07c1e9cc98b1243daa3913e89ec0fec90 Mon Sep 17 00:00:00 2001 From: Djhg2000 Date: Thu, 4 Mar 2021 20:08:12 +0100 Subject: [PATCH] Add a 100ms delay before PWRKEY sequence This brings the power on sequence in line with the EG25-G Hardware Design datasheet, which states we need to wait at least 30 ms after VBAT becomes stable before pulling PWRKEY low (first action of the power on sequene). After this change the sequence becomes as follows: - Set RESET_N high - Wait 60 ms (double 30 ms) - Execute PWRKEY sequence 60 ms was choosen because we don't know when VBAT becomes stable, but it should be much less than an additional 30 ms. Empirical evidence suggests PinePhone units with a healthy battery do not see serious side effects from not doing this, while the modem will fail to boot and/or throw random errors on boot with a worn out battery. --- data/pine64,pinephone-1.0.toml | 3 +++ data/pine64,pinephone-1.1.toml | 3 +++ data/pine64,pinephone-1.2.toml | 4 ++++ src/manager.c | 14 ++++++++++++++ src/manager.h | 1 + 5 files changed, 25 insertions(+) diff --git a/data/pine64,pinephone-1.0.toml b/data/pine64,pinephone-1.0.toml index c0e9192..f5d2451 100644 --- a/data/pine64,pinephone-1.0.toml +++ b/data/pine64,pinephone-1.0.toml @@ -3,6 +3,9 @@ need_libusb = true usb_vid = 0x2c7c usb_pid = 0x0125 +# Delay between setting GPIO and PWRKEY sequence, set in microseconds +poweron_delay = 100000 + # Uncomment the following if you need to change the modem detection timeout on # resume and/or the time during which suspend is blocked after modem boot #[suspend] diff --git a/data/pine64,pinephone-1.1.toml b/data/pine64,pinephone-1.1.toml index c0e9192..f5d2451 100644 --- a/data/pine64,pinephone-1.1.toml +++ b/data/pine64,pinephone-1.1.toml @@ -3,6 +3,9 @@ need_libusb = true usb_vid = 0x2c7c usb_pid = 0x0125 +# Delay between setting GPIO and PWRKEY sequence, set in microseconds +poweron_delay = 100000 + # Uncomment the following if you need to change the modem detection timeout on # resume and/or the time during which suspend is blocked after modem boot #[suspend] diff --git a/data/pine64,pinephone-1.2.toml b/data/pine64,pinephone-1.2.toml index 566ac80..f35c84e 100644 --- a/data/pine64,pinephone-1.2.toml +++ b/data/pine64,pinephone-1.2.toml @@ -1,3 +1,7 @@ +[manager] +# Delay between setting GPIO and PWRKEY sequence, set in microseconds +poweron_delay = 100000 + # Uncomment the following if you need to change the modem detection timeout on # resume and/or the time during which suspend is blocked after modem boot #[suspend] diff --git a/src/manager.c b/src/manager.c index aaa3905..75a88f2 100644 --- a/src/manager.c +++ b/src/manager.c @@ -86,6 +86,9 @@ static gboolean modem_start(struct EG25Manager *manager) if (should_boot) { g_message("Starting modem..."); + // Modem might crash on boot (especially with worn battery) if we don't delay here + if (manager->poweron_delay > 0) + g_usleep(manager->poweron_delay); gpio_sequence_poweron(manager); manager->modem_state = EG25_STATE_POWERED; } else { @@ -300,6 +303,17 @@ int main(int argc, char *argv[]) toml_value = toml_int_in(toml_manager, "usb_pid"); if (toml_value.ok) manager.usb_pid = toml_value.u.i; + + toml_value = toml_int_in(toml_manager, "poweron_delay"); + if (toml_value.ok) { + if (toml_value.u.i >= 0 && toml_value.u.i <= G_MAXULONG) { + // Safe to cast into gulong + manager.poweron_delay = (gulong) toml_value.u.i; + } else { + // Changed from initialized default value but not in range + g_message("Configured poweron_delay out of range, using default"); + } + } } at_init(&manager, toml_table_in(toml_config, "at")); diff --git a/src/manager.h b/src/manager.h index 48ff237..041928a 100644 --- a/src/manager.h +++ b/src/manager.h @@ -33,6 +33,7 @@ struct EG25Manager { gboolean use_libusb; guint usb_vid; guint usb_pid; + gulong poweron_delay; int at_fd; guint at_source;