mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 15:22:20 +02:00
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.
72 lines
2.0 KiB
C
72 lines
2.0 KiB
C
/*
|
|
* Copyright (C) 2020 Arnaud Ferraris <arnaud.ferraris@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <glib.h>
|
|
#include <gpiod.h>
|
|
#include <gudev/gudev.h>
|
|
#include <libmm-glib.h>
|
|
|
|
#include "toml.h"
|
|
|
|
enum EG25State {
|
|
EG25_STATE_INIT = 0,
|
|
EG25_STATE_POWERED, // Power-on sequence has been executed, but the modem isn't on yet
|
|
EG25_STATE_STARTED, // Modem has been started and declared itdata ready
|
|
EG25_STATE_ACQUIRED, // Modem has been probed by ModemManager
|
|
EG25_STATE_CONFIGURED, // Modem has been configured through AT commands
|
|
EG25_STATE_SUSPENDING, // System is going into suspend
|
|
EG25_STATE_RESUMING, // System is being resumed, waiting for modem to come back
|
|
EG25_STATE_REGISTERED, // Modem is unlocked and registered to a network provider
|
|
EG25_STATE_CONNECTED, // Modem is connected (data connection active)
|
|
EG25_STATE_RESETTING, // Something went wrong, we're restarting the modem
|
|
EG25_STATE_FINISHING
|
|
};
|
|
|
|
struct EG25Manager {
|
|
GMainLoop *loop;
|
|
guint reset_timer;
|
|
gboolean use_libusb;
|
|
guint usb_vid;
|
|
guint usb_pid;
|
|
gulong poweron_delay;
|
|
|
|
int at_fd;
|
|
guint at_source;
|
|
GList *at_cmds;
|
|
|
|
enum EG25State modem_state;
|
|
gchar *modem_usb_id;
|
|
|
|
guint mm_watch;
|
|
MMManager *mm_manager;
|
|
MMModem *mm_modem;
|
|
|
|
GDBusProxy *suspend_proxy;
|
|
int suspend_delay_fd;
|
|
int suspend_block_fd;
|
|
|
|
guint modem_recovery_timer;
|
|
guint modem_recovery_timeout;
|
|
guint modem_boot_timer;
|
|
guint modem_boot_timeout;
|
|
|
|
GUdevClient *udev;
|
|
|
|
struct gpiod_chip *gpiochip[2];
|
|
struct gpiod_line *gpio_out[5];
|
|
struct gpiod_line *gpio_in[2];
|
|
};
|
|
|
|
void modem_configure(struct EG25Manager *data);
|
|
void modem_reset(struct EG25Manager *data);
|
|
void modem_suspend_pre(struct EG25Manager *data);
|
|
void modem_suspend_post(struct EG25Manager *data);
|
|
void modem_resume_pre(struct EG25Manager *data);
|
|
void modem_resume_post(struct EG25Manager *data);
|
|
void modem_update_state(struct EG25Manager *data, MMModemState state);
|