Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/omamobile-device-tegu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ packaged yet. What is here is what runs on in-tree drivers.
| `bin/omamobile-tegu-aoc-start` + `vendor/systemd/system/omamobile-tegu-aoc.service` + `vendor/modprobe.d/omamobile-tegu-aoc.conf` | `/usr/bin`, `/usr/lib/systemd/system` (not enabled), `/usr/lib/modprobe.d` | Boots the AoC (audio and sensor DSP) hang-safe: Trusty, the GSA, the AoC drivers, `aoc-tegu.bin`, then waits for its 93 services. Ships disabled: see below |
| `bin/omamobile-bt-addr` + `vendor/systemd/system/omamobile-bt-addr@.service` + `vendor/udev/rules.d/80-omamobile-bt-addr.rules` | `/usr/bin`, `/usr/lib/systemd/system`, `/usr/lib/udev/rules.d` | Gives the BCM4383 its real Bluetooth address from the bootloader's device tree when the controller appears, powering it on once first (set on a never-powered controller, the kernel withdraws the index for good). The Pixel 7 Pro's script, with the extra waits the 9a needed |
| `bin/omamobile-tegu-usb-rescue` + `src/tegu-tcpc-switch.c` + `vendor/systemd/system/omamobile-tegu-usb-rescue.service` | `/usr/bin`, `/usr/lib/systemd/system` (enabled by a vendor wants link) | Closes the MAX77779's USB data switch after a cable replug while no Type-C driver owns the chip; with one loaded it exits. The helper reads the chip's identity and VBUS before its one write and never forces an address a driver holds |
| `bin/omamobile-tegu-charge-limit` + `vendor/udev/rules.d/75-omamobile-tegu-charger.rules` | `/usr/bin`, `/usr/lib/udev/rules.d` | Applies `/etc/omamobile/charge-limit` (a percentage, say `80`) to the charger when it appears; charging stops there and starts again 5 below. No file: charge to 100 % |
| `bin/omamobile-tegu-charge-limit` + `vendor/udev/rules.d/75-omamobile-tegu-charger.rules` | `/usr/bin`, `/usr/lib/udev/rules.d` | Applies `/etc/omamobile/charge-limit` (a percentage, say `80`): charging stops there and starts again 5 below. With the kernel's `max77779-charger` driver, which has charge inhibit and no end threshold, udev runs it on every battery change and it switches `charge_behaviour` between `inhibit-charge` and `auto` by the battery's capacity. No file: charge to 100 % |
| `vendor/systemd/system-sleep/omamobile-tegu-wifi` | `/usr/lib/systemd/system-sleep` | Keeps Wi-Fi loaded across s2idle when `/etc/omamobile/wifi-keep-across-sleep` exists (the chip reloads its firmware on resume and iwd reconnects), otherwise unloads and reloads brcmfmac around the sleep; after a sleep that lost Wi-Fi it unloads for the rest of the boot. It reloads the in-tree `brcmfmac`; a phone still running an out-of-tree build of it keeps its own hook until the Wi-Fi series lands |
| `vendor/systemd/system-sleep/omamobile-tegu-nfc` | `/usr/lib/systemd/system-sleep` | Stops neard's poll loop before a sleep (polling through s2idle reset the palmtop; with it stopped, 35 of 35 cycles woke), reads `Polling` back and logs it, and starts the loop again after the wake if it was on. Powering the ST54L off as well, the workaround for a controller that did not answer on I2C after a wake (issue #132; fixed by linux-omarchy-mobile #131), runs only while `/etc/omamobile/nfc-power-off-across-sleep` exists: off by default, since its record is one wake that needed the power key and one that worked. Log: `/var/log/omamobile/nfc-sleep.log` |
| `vendor/systemd/system/linux-modules-cleanup.service.d/10-omamobile-tegu.conf` | `/usr/lib/systemd/system` | Holds off Arch's old-module cleanup: our kernels come as module tarballs, not pacman packages, and the next-boot and rollback trees must stay |
Expand Down
64 changes: 52 additions & 12 deletions packages/omamobile-device-tegu/bin/omamobile-tegu-charge-limit
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,65 @@
# SPDX-License-Identifier: MIT
# Pixel 9a charge limit: /etc/omamobile/charge-limit holds the percentage at
# which charging stops (say 80); the charger starts again 5 below it. No
# file, or not a number from 1 to 100: charge to 100 %. Run by udev when the
# MAX77779 charger appears (75-omamobile-tegu-charger.rules), and by hand
# after editing the file.
# file, or not a number from 1 to 100: charge to 100 %.
#
# A charger with charge_control_end_threshold takes the limit itself. The
# kernel's max77779-charger driver offers charge_behaviour instead, so for
# it this script holds charging off (inhibit-charge) from the limit and lets
# it run again (auto) 5 below, by the battery's capacity. udev runs it when
# the charger appears and on every battery change
# (75-omamobile-tegu-charger.rules); run it by hand after editing the file.
set -uo pipefail

root=${OMAMOBILE_TEGU_ROOT:-}
if [[ -n $root ]]; then
[[ $root == /* && $root != / && -d $root ]] || exit 2
fi
file=$root/etc/omamobile/charge-limit
threshold=$root/sys/class/power_supply/max77779-charger/charge_control_end_threshold
supply=$root/sys/class/power_supply
threshold=$supply/max77779-charger/charge_control_end_threshold
behaviour=$supply/max77779-charger/charge_behaviour
capacity=$supply/max77779-battery/capacity
log() { echo "omamobile-tegu-charge-limit: $*"; }

[[ -s $file ]] || exit 0
[[ -w $threshold ]] || { log "no charger threshold to set"; exit 0; }
limit=$(tr -d ' \t\n' < "$file")
if [[ ! $limit =~ ^[0-9]+$ ]] || (( 10#$limit < 1 || 10#$limit > 100 )); then
log "$file is not a percentage from 1 to 100; no limit"
exit 1
limit=100
if [[ -s $file ]]; then
limit=$(tr -d ' \t\n' < "$file")
if [[ ! $limit =~ ^[0-9]+$ ]] || (( 10#$limit < 1 || 10#$limit > 100 )); then
log "$file is not a percentage from 1 to 100; no limit"
[[ -w $behaviour ]] && echo auto > "$behaviour"
exit 1
fi
limit=$((10#$limit))
fi
echo "$((10#$limit))" > "$threshold" || { log "the charger refused $limit"; exit 1; }
log "charge limit $(cat "$threshold") %"

if [[ -w $threshold ]]; then
[[ -s $file ]] || exit 0
echo "$limit" > "$threshold" || { log "the charger refused $limit"; exit 1; }
log "charge limit $(cat "$threshold") %"
exit 0
fi

if [[ ! -w $behaviour ]]; then
[[ -s $file ]] && log "no charger to limit"
exit 0
fi
want=
if (( limit >= 100 )); then
want=auto
elif [[ -r $capacity ]]; then
level=$(tr -d ' \t\n' < "$capacity")
[[ $level =~ ^[0-9]+$ ]] || { log "the battery reports no capacity"; exit 0; }
if (( level >= limit )); then want=inhibit-charge
elif (( level <= limit - 5 )); then want=auto
fi
else
log "no battery capacity; charging left as it is"
exit 0
fi
[[ -n $want ]] || exit 0
current=$(grep -o '\[[a-z-]*\]' "$behaviour" 2>/dev/null | tr -d '[]')
[[ -n $current ]] || current=$(tr -d ' \t\n' < "$behaviour")
[[ $current == "$want" ]] && exit 0
echo "$want" > "$behaviour" || { log "the charger refused $want"; exit 1; }
log "charge limit $limit %: $want"
17 changes: 17 additions & 0 deletions packages/omamobile-device-tegu/test/charge-limit
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,20 @@ rm -f "$threshold"
echo 80 > "$file"
"$script" >/dev/null || fail "a missing charger is an error"
echo 'ok - charge-limit: percentages only, the charger otherwise untouched'

# The kernel's driver: no threshold, charge_behaviour instead, by capacity.
b=$OMAMOBILE_TEGU_ROOT/sys/class/power_supply/max77779-charger/charge_behaviour
c=$OMAMOBILE_TEGU_ROOT/sys/class/power_supply/max77779-battery/capacity
mkdir -p "${c%/*}"
level() { echo "$1" > "$c"; "$script" >/dev/null || fail "capacity $1 failed"; }
echo '[auto] inhibit-charge force-discharge' > "$b"; echo 80 > "$file"
level 79; [[ $(cat "$b") == '[auto] inhibit-charge force-discharge' ]] || fail "79 of 80 changed the charger"
level 80; [[ $(cat "$b") == inhibit-charge ]] || fail "80 of 80 did not inhibit"
level 77; [[ $(cat "$b") == inhibit-charge ]] || fail "77 of 80 resumed inside the 5-point band"
level 75; [[ $(cat "$b") == auto ]] || fail "75 of 80 did not resume"
rm -f "$file"; echo inhibit-charge > "$b"; level 90
[[ $(cat "$b") == auto ]] || fail "no file left charging inhibited"
echo abc > "$file"; echo inhibit-charge > "$b"; echo 90 > "$c"
"$script" >/dev/null 2>&1 && fail "abc was accepted"
[[ $(cat "$b") == auto ]] || fail "a bad file left charging inhibited"
echo 'ok - charge-limit: charge_behaviour holds charging off from the limit to 5 below'
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# SPDX-License-Identifier: MIT
# Omarchy Mobile: apply /etc/omamobile/charge-limit when the MAX77779 charger
# appears (omamobile-tegu-charge-limit).
# appears, and on every battery change: the kernel's charger driver limits by
# charge inhibit, so the script follows the battery's capacity
# (omamobile-tegu-charge-limit).
ACTION=="add", SUBSYSTEM=="power_supply", KERNEL=="max77779-charger", RUN+="/usr/bin/omamobile-tegu-charge-limit"
ACTION=="change", SUBSYSTEM=="power_supply", KERNEL=="max77779-battery", RUN+="/usr/bin/omamobile-tegu-charge-limit"
2 changes: 1 addition & 1 deletion packages/omamobile-device-tegu/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.2.1