forked from NixOS/mobile-nixos
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pine64-pinephone: Add service to control the modem
- Loading branch information
Showing
2 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
# This, by default, boots the phone with the modem powered down. | ||
# In addition, the systemd service does not, by default, start the modem. | ||
{ | ||
|
||
# Shut down the modem in early boot | ||
mobile.quirks.u-boot.additionalCommands = '' | ||
# Properly shut off EG25 by pulling up PWRKEY. | ||
gpio set 35 | ||
sleep 1 | ||
gpio clear 35 | ||
''; | ||
|
||
# Ensure we have systemd tagging on the modem. | ||
# Probably is not needed. | ||
services.udev.extraRules = | ||
let | ||
path = "/devices/platform/soc/1c1b000.usb/*/net/wwan0"; | ||
in '' | ||
ACTION=="add", DEVPATH=="${path}", TAG+="systemd" | ||
ACTION=="remove", DEVPATH=="${path}", TAG+="systemd" | ||
'' | ||
; | ||
|
||
# This service, which by default is not "wantedBy" multi-user.target, allows | ||
# the user to start the modem using a systemd service. | ||
# In addition, the service status always reflects the current status of the | ||
# modem; whether it has been turned off or on using systemd or not. | ||
systemd.services = | ||
let | ||
dotDeviceName = "sys-devices-platform-soc-1c1b000.usb-usb3-3\\x2d1-3\\x2d1:1.4-net-wwan0.device"; | ||
in { | ||
"modem-control" = { | ||
bindsTo = [ dotDeviceName ]; | ||
wantedBy = lib.mkForce [ dotDeviceName ]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
RemainAfterExit = true; | ||
|
||
ExecStart = pkgs.writeShellScript "start-modem" '' | ||
echo 'Powering modem on...' | ||
echo 1 > /sys/class/modem-power/modem-power/device/powered | ||
''; | ||
|
||
ExecStop = pkgs.writeShellScript "stop-modem" '' | ||
echo 'Powering modem off...' | ||
echo 0 > /sys/class/modem-power/modem-power/device/powered | ||
''; | ||
}; | ||
}; | ||
}; | ||
} |