Skip to content

Power, Charging & Brownout Guard

Smartphones running 24/7 as headless Linux servers have unique power behavior: an active OLED panel wastes ~1 W, holding a Li-ion battery at 100% causes cell swelling over months, and plugging a heavy camera/TPU workload into a weak 5 V / 500 mA USB-SDP port silently drains the battery until voltage collapse.

headless-phone ships dedicated, cleanly configurable services to handle all of these out of the box.

Brownout Protection Guard (brownout-guard)

Section titled “Brownout Protection Guard (brownout-guard)”

Available in rootfs images built after v0.2.0, brownout-guard.service (/usr/local/sbin/brownout-guard) monitors battery SOC, battery voltage sag, signed/unsigned discharge current, and weak-charger conditions (USB-SDP, <= 500 mA input current limit, pd_partner=no) directly from sysfs.

When running sustained workloads (such as Frigate camera capture + Exynos MFC encoding + Tensor Edge TPU) on a 5 V / 500 mA USB-SDP host port — or unplugged on battery — Pixel fuel gauges (max1720x / google_battery) report active net discharge (status=Not charging or Discharging with negative current_now). Without intervention, sustained drain eventually triggers voltage sag, I2C errors, and latched accelerator failures (for example on Mali-G78 OpenCL).

Two independent shedding triggers protect the device regardless of whether a weak USB charger is attached:

  • Sustained low SOC: Active battery discharge (>= DISCHARGE_CURRENT_UA) with capacity <= SHED_SOC (default 15%) sustained for SUSTAINED_SECONDS (default 60 s).
  • Sustained critical voltage sag: Battery voltage <= CRITICAL_VOLTAGE_MV (default 3450 mV) sustained for VOLTAGE_SUSTAINED_SECONDS (default 15 s), even if SOC reads higher.

(Weak-charger detection independently logs rate-limited journal warnings and surfaces reasons in --status whenever active drain occurs while usb_online is true with SDP, <= 500 mA ICL, or pd_partner=no.)

When either shedding trigger fires, the guard stops configured active systemd units (default: frigate-camera.service), records shed state with flock-serialized persistence in /run/headless-phone/brownout-guard-state.json, keeps enforcement active through recovery hysteresis (>= RECOVER_SOC and >= RECOVER_VOLTAGE_MV while charging/stable for RECOVER_SECONDS), and resumes shed units automatically (or manually via --resume).

Terminal window
# Inspect live power telemetry, weak-charger detection, shed state, and effective config
brownout-guard --status
# Machine-readable JSON report
brownout-guard --status --json
# Manually resume shed units and clear shed state
sudo brownout-guard --resume
# Evaluate one cycle without mutating services or state
brownout-guard --once --dry-run

The guard is a standalone systemd service — toggle it anytime without affecting any other subsystem:

Terminal window
# Disable completely
sudo systemctl disable --now brownout-guard.service
# Re-enable anytime
sudo systemctl enable --now brownout-guard.service

Customizing /etc/headless-phone/brownout-guard.conf

Section titled “Customizing /etc/headless-phone/brownout-guard.conf”

Create or edit /etc/headless-phone/brownout-guard.conf using simple KEY=VALUE lines (parsed strictly in Python without shell evaluation; never overwritten by os-upgrade).

Precedence (highest wins): CLI flags > environment variables > /etc/headless-phone/brownout-guard.conf > built-in defaults.

/etc/headless-phone/brownout-guard.conf
# Shed active units on sustained drain <= 15% SOC or voltage sag <= 3450 mV
SHED_SOC=15
RECOVER_SOC=25
CRITICAL_VOLTAGE_MV=3450
RECOVER_VOLTAGE_MV=3650
# Hysteresis timers (seconds)
SUSTAINED_SECONDS=60
VOLTAGE_SUSTAINED_SECONDS=15
RECOVER_SECONDS=30
POLL_INTERVAL_SECONDS=15
# Space- or comma-separated systemd unit names to shed when active
SHED_UNITS=frigate-camera.service,my-heavy-worker.service
# Behavior toggles (0 or 1)
RESUME_ON_RECOVER=1
WARN_WEAK_CHARGER=1
# Net discharge current threshold (uA) treated as active battery drain
DISCHARGE_CURRENT_UA=50000
Key CLI Override Default Valid Range / Notes
SHED_SOC --shed-soc 15 5..95 (%). Sustained low-SOC drain threshold before shedding.
RECOVER_SOC --recover-soc 25 > SHED_SOC..100 (%). SOC required before auto-recovery begins.
CRITICAL_VOLTAGE_MV --critical-voltage-mv 3450 3000..4200 (mV). Fast voltage-sag shed trigger.
RECOVER_VOLTAGE_MV --recover-voltage-mv 3650 > CRITICAL_VOLTAGE_MV (mV). Voltage required before auto-recovery.
SUSTAINED_SECONDS --sustained-seconds 60 Seconds low SOC must persist before shedding.
VOLTAGE_SUSTAINED_SECONDS --voltage-sustained-seconds 15 Seconds critical voltage sag must persist before shedding.
RECOVER_SECONDS --recover-seconds 30 Sustained healthy-power duration before resuming shed units.
POLL_INTERVAL_SECONDS --poll-interval-seconds 15 Daemon poll interval in seconds.
SHED_UNITS --shed-units frigate-camera.service Space/comma-separated allowlisted unit names (.service, .timer, .socket, .target, .mount, etc.). Disabled or masked units are skipped on resume.
RESUME_ON_RECOVER --resume-on-recover 1 1 auto-resumes previously active shed units on recovery; 0 leaves them stopped until manual --resume.
WARN_WEAK_CHARGER --warn-weak-charger 1 1 logs a rate-limited journal warning (~every 15 min) when draining on a weak charger.
DISCHARGE_CURRENT_UA --discharge-current-ua 50000 Net discharge current threshold (50 mA) used to confirm active battery drain.

Additional CLI options: --config <PATH>, --sysfs-root <PATH> (or HEADLESS_SYSFS_ROOT), --state-file <PATH>, --once, --dry-run, --status, --json, --resume.

Exit codes: 0 on clean daemon exit, --status, --once, or successful --resume; 1 if manual --resume fails to restart a unit; 2 on invalid configuration (ConfigError).


Battery Charge Capping (charge-limit.service)

Section titled “Battery Charge Capping (charge-limit.service)”

For safe 24/7 plugged-in operation without battery swelling, charge-limit.service runs /usr/local/sbin/charge-limit on boot and configures hardware battery thresholds to 55% start / 70% stop by default.

Create /etc/headless-phone/charge-limit.conf (protected from OTA overwrites; also configurable in the WebUSB Installer):

/etc/headless-phone/charge-limit.conf
CHARGE_START=60
CHARGE_STOP=80

Both values must be integers satisfying 20 <= CHARGE_START < CHARGE_STOP <= 100. Apply immediately without rebooting:

Terminal window
sudo systemctl restart charge-limit.service

How it works under the hood:

  1. Polls sysfs up to HEADLESS_CHARGE_LIMIT_RETRIES seconds (default 15) to handle boot-time ENODATA from fuel gauge drivers.
  2. Probes interfaces in priority order: (a) Pixel google,charger / battery (charge_start_level + charge_stop_level), (b) standard Linux charge_control_start_threshold + charge_control_end_threshold, (c) standard Linux end-only charge_control_end_threshold.
  3. Writes stop before start when raising thresholds (avoiding kernel start >= cur_stop rejection) and performs read-back verification.

16-Rail ODPM Power Telemetry (power-metrics)

Section titled “16-Rail ODPM Power Telemetry (power-metrics)”

Google Tensor SoCs expose 16 hardware power-rail energy accumulators (s2mpg10-odpm and s2mpg11-odpm) through Linux IIO (/sys/bus/iio/devices/iio:device*). /usr/local/sbin/power-metrics samples two snapshots over --interval seconds (default 1.0) to compute exact milliwatt draw per rail alongside Linux battery telemetry.

Terminal window
# Live human-readable power breakdown across all 16 ODPM rails + battery
sudo power-metrics
# Longer averaging window (5 seconds)
sudo power-metrics --interval 5
# Emit Prometheus textfile metrics to stdout
sudo power-metrics --prometheus
# Atomically write a Prometheus node_exporter textfile collector file
sudo power-metrics --prom-file /var/lib/node_exporter/textfile_collector/headless_power.prom
Metric Type Labels / Meaning
headless_phone_rail_energy_microjoules counter {chip, rail, subsystem} — cumulative rail energy in µJ
headless_phone_rail_power_milliwatts gauge {chip, rail, subsystem} — average draw in mW over --interval
headless_phone_battery_capacity_percent gauge Battery state of charge (%)
headless_phone_battery_voltage_volts gauge Battery voltage (V)
headless_phone_battery_power_milliwatts gauge Battery power (mW, negative = discharging)
headless_phone_battery_temperature_celsius gauge Battery pack temperature (°C)

The Pixel bootloader leaves continuous-splash enabled on the OLED panel (~0.8–1.1 W draw and burn-in risk on intact screens). Udev rule /etc/udev/rules.d/90-headless-display-off.rules automatically invokes display-off@card0.service whenever a DRM display card appears.

/usr/local/sbin/display-off uses pure-Python Linux DRM KMS ioctls (no libdrm, no Wayland/X11) to take DRM master ownership with a temporary black dumb buffer, disable every connected CRTC, and drop idle power from ~1.34 W down to 0.22 W (VSYS_PWR_DISPLAY = 0.00 mW).

Terminal window
# Run manually across all /dev/dri/card* nodes or a specific card
sudo display-off
sudo display-off --card /dev/dri/card0

(Note: systemd-backlight@.service is masked in the rootfs so systemd never restores stale backlight brightness.)


Pixels feature a dual-role USB-C port (Host/DFP for Ethernet adapters, USB 3.0 hubs, and PD docks; Device/UFP for a PC recovery serial console). Udev rule /etc/udev/rules.d/90-headless-usb-role.rules triggers usb-role.service on typec and udc events with StartLimitIntervalSec=0 so rapid PD dock negotiation bursts never trip systemd rate limits.

  • In host (or unknown) role: Unbinds /sys/kernel/config/usb_gadget/headless/UDC so xhci-exynos and USB-C Ethernet adapters/docks cleanly own the bus.
  • In device role: Mounts configfs, configures the CDC ACM serial gadget (0525:a4a7, acm.usb0 — chosen to bind Windows inbox usbser.sys cleanly without colliding with Google ADB 18d1:4ee7), applies GS101 DWC3 enumeration knobs (usb_data_enabled=1, force_speed=high-speed, update_sdp_enum_timeout=0x1), and triggers serial-getty@ttyGS0.service.
Terminal window
# Force a specific USB role manually (defaults to auto-detecting /sys/class/typec/port*/data_role)
sudo /usr/local/sbin/usb-role host
sudo /usr/local/sbin/usb-role device

Qi Wireless Charging & Reverse Battery Share

Section titled “Qi Wireless Charging & Reverse Battery Share”

Pixel 6 Pro’s Renesas P9412 Qi wireless coil (p9221 at 8-003c) supports both wireless charging telemetry (RX) and Reverse Wireless Power Share (Battery Share / RTX) via wireless-power:

Terminal window
# Inspect Qi RX voltage/current/alignment/negotiated power & RTX state (unprivileged)
wireless-power status
wireless-power --json status
# Enable Reverse Battery Share TX (refuses if battery SOC < --min-soc, default 20%)
sudo wireless-power rtx on --min-soc 30
# Turn off Reverse Battery Share TX
sudo wireless-power rtx off

Top-level flag: --json (must precede subcommand). rtx {on,off,status} also supports --min-soc <0..100> (default 20) and --force (override SOC guard).