Skip to content

Commit

Permalink
pine64-pinephone: Add service to control the modem
Browse files Browse the repository at this point in the history
  • Loading branch information
samueldr committed Oct 18, 2020
1 parent e61bbe9 commit ff78bff
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
9 changes: 4 additions & 5 deletions devices/pine64-pinephone/default.nix
@@ -1,6 +1,10 @@
{ config, lib, pkgs, ... }:

{
imports = [
./modem.nix
];

mobile.device.name = "pine64-pinephone";
mobile.device.identity = {
name = "PinePhone";
Expand Down Expand Up @@ -38,10 +42,5 @@
gpio set 115 # R
gpio set 114 # G
gpio clear 116 # B
# Properly shut off EG25 by pulling up PWRKEY.
gpio set 35
sleep 1
gpio clear 35
'';
}
53 changes: 53 additions & 0 deletions devices/pine64-pinephone/modem.nix
@@ -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
'';
};
};
};
}

0 comments on commit ff78bff

Please sign in to comment.