Commit Graph

136 Commits

Author SHA1 Message Date
Arnaud Ferraris
f978b775e0 src: fix issues reported by clang-tidy
Some of those are simply ignored as they're false positives.
2024-11-12 13:10:43 +01:00
Arnaud Ferraris
9f6178dafd src: format using clang-format 2024-10-30 12:01:46 +01:00
Aren Moynihan
99aa7e2bf7 gpio: remove handling of W_DISABLE pin
The PinePhone has circuitry that makes this pin active-high, but the
PinePhone Pro doesn't appear to, which means we would need read active
high / active low from the config file. Since the modem works fine
without setting this pin, remove the logic to handle the W_DISBALE pin.
2024-10-28 16:08:37 -04:00
Aren Moynihan
ce0fc25892 at: don't clear the resetting state on sequence end
If the reset sequence fails, we don't want to transition to the powered
state, instead we should stay in the resetting state so we eventually
timeout and try a gpio reset. If the reset command succeeds the modem
will eventually send RDY and transition the state to STARTED.

Since this might take longer to change the modem state, add 15 seconds
(for a total of 45) to the at reset timeout just in case. It looks like
the modem typically takes about 20 between sending "AT+CFUN=1,1" and
receiving "RDY", so this should be plenty.
2024-10-28 12:48:08 -04:00
Aren Moynihan
ec96153b0f at: fix indentation
A few tabs slipped in here, convert them to spaces.
2024-10-28 12:47:24 -04:00
Aren Moynihan
541aa00198 gpio: disable airplane mode when starting the modem
I'm not sure why this was being done when disabling the modem, move it
to the powerup sequence for more consistency.
2024-10-21 16:54:58 -04:00
Aren Moynihan
b53702ad0b manager: modem_reset: fix file descriptor leek
fd wasn't being closed if the write failed. Theoretically if a system
with an unstable modem ran for long enough, this could bring down
eg25-manager.
2024-10-21 16:54:58 -04:00
Aren Moynihan
1482899888 manager: reset using gpio pins if the mode is unresponsive
If the modem doesn't respond to the at reboot sequence, this will
attempt reboot the modem using both the power pin and then the reset pin
in case that doesn't work.
2024-10-21 16:54:58 -04:00
Aren Moynihan
c4b3b75047 manager: always set the reset line when exiting
This splits the logic from gpio_check_poweroff into two separate
functions, allowing the caller more control over when the reset line is
asserted to force the modem to turn off.

Previously if the modem didn't respond to the power key sequence in
quit_app, gpio_check_poweroff wouldn't set the reset pin, and
eg25-manager could leave the modem running after exiting.
2024-10-04 17:11:26 -04:00
Aren Moynihan
3c5d455f20 gpio: toggle the RESET_N pin before booting the modem to ensure it is actually off 2024-10-04 17:08:45 -04:00
Arnaud Ferraris
1acd15ca2f src: gnss: fix build on 32-bit architectures
It seems `off_t` is now 64-bits wide on 32-bit architectures, so using
`glong` causes a build failure in this case. Switch to using the correct
type from the `sendfile()` prototype to fix this.
2024-08-27 11:01:08 +02:00
Arnaud Ferraris
40623d1572 src: gpio: small cleanups following the port to libgpiod 2.x 2024-08-27 09:44:52 +02:00
marcin
bc5a25b17e gpio: libgpiod 2.0: port gpiod_line_{get,set}_value 2024-05-13 23:16:35 +02:00
marcin
b1bb871eb7 gpio: libgpiod 2.0: port gpiod_chip_num_lines 2024-05-13 23:16:35 +02:00
marcin
88e85ae7c2 gpio: libgpiod 2.0: port gpio_get_{input,output}_line 2024-05-13 23:16:27 +02:00
marcin
b8ff1ef3d4 gpio: libgpiod 2.0: port gpiod_chip_open_by_label 2024-05-13 23:02:58 +02:00
Arnaud Ferraris
0e2311fb36 Rename executable to eg25-manager
This brings more consistency with how other components are named
(repo, package, service file, manpages...).
2022-02-19 15:17:27 +01:00
Arnaud Ferraris
19eb488e29 gpio: fix init for BH edition PinePhone
BH PinePhone don't have the modem's `STATUS` pin connected to the SoC,
and as such require using `libusb` for checking the modem power state.
We didn't handle this case previously due to lack of on-device testing,
causing BH phones to fail with newer versions.

This patch ignores the `status` GPIO for devices relying on `libusb`,
which are only pre-CE PinePhones.
2022-02-19 13:50:41 +00:00
Arnaud Ferraris
97b1878ebc manager: disable reset timers once reset sequence starts
`modem_reset()` can be called from multiple places, both tied to a
specific timer. In order to prevent calling this function multiple times
in a row, disable all related timers as soon as we enter this function.
2022-02-07 12:43:49 +01:00
Arnaud Ferraris
9e6bccdf37 udev: use USB vendor/product ID to determine behavior
When going into firmware upgrade mode, the modem comes back with
different IDs than in normal use. We should make sure we cancel the
reset sequence when that happens, and not start a new one.
2022-02-07 12:43:49 +01:00
Arnaud Ferraris
df79247821 manager: populate USB vendor/product ID's with default values
We'll need those in the `udev` module, but never made it a mandatory
config option. This commit makes sure those values are properly filled
in.
2022-01-04 15:24:01 +01:00
Dylan Van Assche
61c89a003a udev: cancel reset if modem is already back
Cancel reset if modem is back before reset sequence is started.
When upgrading the modem through fwupd, it will enter fastboot.
Therefore, it disappears from the USB bus for a few ms.
However, the eg25-manager considers this as an issue and
resets the modem a bit later during the upgrade process.
To avoid this, cancel the reset sequence if the modem is already
back before the reset sequence is started. This will take less than 3
seconds.
2022-01-04 14:41:54 +01:00
Arnaud Ferraris
fedce7298b manager: start udev monitoring module conditionally
The problem addressed by monitoring the modem status through udev seems
tied to the specific USB controller used by the A64. On RK3399 devices,
this quirk is apparently unneeded, and actually harmful as it resets the
modem USB connection while ModemManager is already configuring it.

This commit adds an optional config parameter for disabling this module
(enabled by default).
2021-12-24 15:14:43 +00:00
Rafael Diniz
8665f8a4a6 Fix compile error when not using Modem Manager. 2021-12-23 21:12:24 +03:00
Kai Lüke
88c68b9933 suspend: actually check if the modem is found before resetting
The timeout was meant to give more time to find the modem, yet the
callback didn't actually check if it came back but blindly issued a
reset.
Add a check to the callback to see if the modem was found and only
reset if not.

Fixes https://gitlab.com/mobian1/devices/eg25-manager/-/issues/28
2021-12-15 22:47:40 +00:00
Arnaud Ferraris
b21c4b0fa4 data: add PinePhone Pro config
The PinePhone Pro uses the same EG25 modem as the OG PinePhone, but with
a different SoC. It also uses an ALC5616 audio codec directly hooked up
to the modem (which is I2S master in this case).

The config is therefore almost identical to the PinePhone rev1.2 except
for the gpios, UART port used and `AT+QDAI` config (to account for the
different audio setup).
2021-11-27 13:12:17 +01:00
Arnaud Ferraris
abf60b793a gpio: make more generic
Instead of assuming we're running on the PinePhone (and therefore
hardcoding gpiochip labels and line numbers), make all of those
configurable. Legacy config files will still be parsed as long as they
lack the `chips` key.

Existing config files are also updated to match the new config format.
2021-11-24 01:34:14 +01:00
Arnaud Ferraris
f8b3e28434 config: add config_get_table helper function 2021-11-24 01:20:54 +01:00
ArenM
a06360f4c8 at: break before overflow when receiving messages
Previously this code checked if the buffer was full after writing to it,
which meant that the buffer could overflow.

This checks for an overflow before copying into the buffer and only
copies the data that will fit.
2021-11-06 19:59:22 -04:00
Arnaud Ferraris
deeb60fa6a gnss: warn if ftruncate() fails 2021-10-07 11:11:30 +02:00
Arnaud Ferraris
af4d5ca1c1 udev: don't reset immediately
Executing a reset each time the modem is unbound is a bit too extreme:
the modem sometimes recovers by itself and only needs a "soft" reset
sequence (unbind/bind).

This commit introduces a short timer (2s) so we the modem can settle in.
If reset fails after this time, the modem is probably completely broken,
or already rebooting, so we can safely issue a reset AT command.
2021-10-06 22:35:36 +02:00
Arnaud Ferraris
25dd46bb30 manager: make modem_reset more reliable
`modem_reset()` could previously either fail silently, or fall back to
using AT commands without indicating what happened. This commit adds
informative messages and makes sure we fall back to resetting using AT
commands whenever we encounter an error.
2021-10-06 22:25:39 +02:00
Arnaud Ferraris
86978e18a6 at: fix more typos 2021-10-06 02:17:21 +02:00
Arnaud Ferraris
bcdc839abb gnss: don't overload the modem during upload
By instructing sendfile() to send the whole content of the assistance
data at once results in a big data transfer (> 4kb) first followed by a
huge amount of small transfers (64 or 128b). This "overloads" the modem
which needs to process smaller chunks of data and have more time to do
so (experimentation shows that 1kb need 100ms for processing, or the
upload will subsequently fail).

This commit sets the transfer size to 256b and increase the timeout
between each transfer to 25ms.
2021-10-06 01:54:30 +02:00
Arnaud Ferraris
73868260a2 gnss: wait for the modem to confirm upload success
If we clear QFUPL right after we finished the file transfer, we will
execute the following commands right away, leading to interleaved
replies from the modem (i.e. the reply to QGPSXTRATIME being received
with the notification of upload completion).

Keeping the command in the queue allows us to use the callback a second
time once the upload is complete and resume assistance data processing
accordingly.
2021-10-06 01:54:30 +02:00
Arnaud Ferraris
66073cdd21 at: get rid of compiler warning 2021-10-06 01:54:30 +02:00
Arnaud Ferraris
cfd7ebf156 at: ensure we don't skip steps
After the modem send "RDY", other messages are received. With the
current implementation, this causes eg25-manager to mark the modem as
configured before it is even picked up by ModemManager. Adding an
additional status check helps preventing this issue.
2021-10-06 01:54:30 +02:00
Arnaud Ferraris
f03f086fcb src: fix typo 2021-10-05 23:45:33 +02:00
Arnaud Ferraris
f68af6405d manager: honor --version option
Fixes #22
2021-10-05 23:45:27 +02:00
Arnaud Ferraris
68349c9f58 Merge branch 'fix-config-crash' into 'master'
Don't crash on incomplete config files

Closes #23

See merge request mobian1/devices/eg25-manager!31
2021-10-05 20:34:28 +00:00
Arnaud Ferraris
3d9456c0e7 Merge branch 'wip/a-wai/clear-command-queue' into 'master'
at: clear command queue before configuring modem

Closes #24

See merge request mobian1/devices/eg25-manager!34
2021-10-05 20:34:12 +00:00
Arnaud Ferraris
87a7a6c9e9 Merge branch 'at_logging' into 'master'
Fix logging of at commands (was preventing sending them)

See merge request mobian1/devices/eg25-manager!36
2021-10-05 20:33:55 +00:00
ArenM
aec8135ad4 at: escape non text characters in modem response logs 2021-10-05 12:09:12 -04:00
Arnaud Ferraris
fcf3832f52 gpio: don't execute soft wake sequence if already woken up
This add an unnecessary 200ms delay and pollute logs.
2021-10-05 11:23:06 +02:00
Arnaud Ferraris
4c6625a38d src: don't crash on incomplete user-edited config file
If a user created a custom config file and we added new fields in a
newer version, `eg25-manager` will crash by assuming all config files
are complete and up-to-date.

Moreover, creating a custom config, even to change only one option,
required copying a complete default config file and then editing the
relevant field(s). This could lead to issues when upgrading, as default
values of fields unrelated to the user change could be modified and not
applied to the user config.

This patch addresses both these issues by:
* making sure at least one config file exists
* requiring only the "default" config file (the one under `/usr/share`)
  to include all the required fields
* trying to use user config for each field, falling back to the default
  config file if the field isn't present in the user config
* exiting with a meaningful error message in case the default config
  file is missing a required field or section

That way, it will be possible to have a minimal user config file
containing only the field(s) needing a different value than the default
one, falling back to the values in the default config file.

Fixes #23
2021-10-05 11:19:35 +02:00
Arnaud Ferraris
55ed2dc39c src: add helper functions for reading config files 2021-10-05 11:19:35 +02:00
ArenM
89b7dfda2f at: remove call to g_strstrip before sending commando
This log statement called g_strstrip before sending the command, which
caused it to fail because it doesn't send the newline required to run
it.
2021-10-04 23:26:16 -04:00
Arnaud Ferraris
0f3e51cd06 at: clear command queue before configuring modem
In some cases, there might be an issue with `eg25-manager` trying to
reset the modem while it's being configured. This leads to infinite boot
loops where the modem is constantly reset soon after it booted.

Fixes #24
2021-10-04 18:20:46 +02:00
Xavier Del Campo
6b2f0e8fbd at.c: fix misleading g_message 2021-10-02 13:59:22 +02:00
Arnaud Ferraris
082cf996d1 Use a more meaningful message on AT send failure 2021-10-02 13:58:32 +02:00