improve poweroff sequence

When powering off the modem, we must assert the RESET line only when the 
modem has shut down (otherwise it'll cause a hard reset and won't allow 
the modem to shut down properly).

This commit also polls the STATUS pin during poweroff and quits 
immediately once this pin goes high.
This commit is contained in:
Arnaud Ferraris
2020-12-10 17:05:44 +01:00
parent 1170a2c7f7
commit 47b2f71b6f
3 changed files with 27 additions and 8 deletions

View File

@@ -64,11 +64,8 @@ int gpio_sequence_poweron(struct EG25Manager *manager)
int gpio_sequence_shutdown(struct EG25Manager *manager) int gpio_sequence_shutdown(struct EG25Manager *manager)
{ {
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_RESET], 1);
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_DISABLE], 1); gpiod_line_set_value(manager->gpio_out[GPIO_OUT_DISABLE], 1);
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_PWRKEY], 1); gpio_sequence_poweron(manager);
sleep(1);
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_PWRKEY], 0);
g_message("Executed power-off sequence"); g_message("Executed power-off sequence");
@@ -175,6 +172,19 @@ int gpio_init(struct EG25Manager *manager)
return 0; return 0;
} }
gboolean gpio_check_poweroff(struct EG25Manager *manager)
{
if (manager->gpio_in[GPIO_IN_STATUS] &&
gpiod_line_get_value(manager->gpio_in[GPIO_IN_STATUS]) == 1) {
// Asserting RESET line to prevent modem from rebooting
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_RESET], 1);
return TRUE;
}
return FALSE;
}
void gpio_destroy(struct EG25Manager *manager) void gpio_destroy(struct EG25Manager *manager)
{ {
int i; int i;

View File

@@ -15,3 +15,5 @@ int gpio_sequence_poweron(struct EG25Manager *state);
int gpio_sequence_shutdown(struct EG25Manager *state); int gpio_sequence_shutdown(struct EG25Manager *state);
int gpio_sequence_suspend(struct EG25Manager *state); int gpio_sequence_suspend(struct EG25Manager *state);
int gpio_sequence_resume(struct EG25Manager *state); int gpio_sequence_resume(struct EG25Manager *state);
gboolean gpio_check_poweroff(struct EG25Manager *manager);

View File

@@ -25,6 +25,16 @@ static gboolean quit_timeout_cb(struct EG25Manager *manager)
return FALSE; return FALSE;
} }
static gboolean gpio_poll_cb(struct EG25Manager *manager)
{
if (gpio_check_poweroff(manager)) {
quit_timeout_cb(manager);
return FALSE;
}
return TRUE;
}
static gboolean quit_app(struct EG25Manager *manager) static gboolean quit_app(struct EG25Manager *manager)
{ {
g_message("Request to quit..."); g_message("Request to quit...");
@@ -33,10 +43,7 @@ static gboolean quit_app(struct EG25Manager *manager)
g_message("Powering down the modem..."); g_message("Powering down the modem...");
gpio_sequence_shutdown(manager); gpio_sequence_shutdown(manager);
manager->modem_state = EG25_STATE_FINISHING; manager->modem_state = EG25_STATE_FINISHING;
/* g_timeout_add(500, G_SOURCE_FUNC(gpio_poll_cb), manager);
* TODO: add a polling function to check STATUS and RI pins state
* (that way we could reduce the poweroff delay)
*/
g_timeout_add_seconds(30, G_SOURCE_FUNC(quit_timeout_cb), manager); g_timeout_add_seconds(30, G_SOURCE_FUNC(quit_timeout_cb), manager);
} }