Skip to content
Merged
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
104 changes: 103 additions & 1 deletion device/raven/USB-PLAN.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- SPDX-License-Identifier: MIT -->
# Pixel 6 Pro (raven): USB

Status (2026-10-20): USB 2 device mode works (NCM and ACM, SSH at
Status (2026-10-28): charging works at stock limits with the temperature guard (section 4, C0-C5 passed). USB 2 device mode works (NCM and ACM, SSH at
172.16.42.1) with a raven-only DT change that makes dwc3 a USB 2
peripheral and drops `orientation-switch` from the PHY. The PR review of
the boot glue (derekross/linux-omarchy-mobile#2) asked to keep upstream's
Expand Down Expand Up @@ -85,3 +85,105 @@ ls /sys/class/usb_role/ 2>/dev/null; cat /sys/class/usb_role/*/role 2>/dev/null'
- **Result:** if U1 passes, the NOT FOR MERGE USB commit goes away and
#2 needs no USB follow-up. If it fails, the peripheral setup stays a
raven bring-up change, described in this plan.

## 4. Charging: the MAX77759 charger (raven's B3, after cheetah's)

**Why:** with no charger driver the chip runs on the bootloader's settings.
A wall charger charges (1.1-1.6 A into the battery, 2026-10-27 and -28),
but there is no battery temperature guard from Linux, the float voltage
is 4.35 V where stock goes to 4.45 V (cheetah's stopped at 93 % this way),
and the fast charge current is 1.93 A where stock's table allows 0.3 C at
10-20 degC. A laptop port doesn't keep up with the phone's load.

**What exists:** our kernel's `max77759_charger` has cheetah's
`default_ilim_ua` and `temp_guard` (USB-C-PLAN section 3, B3g). The MFD
creates the charger cell on raven too; it only lacked a battery
description. Kernel `omamobile-gs101-charging` (`83a07fa16` label the
PMIC, `75a486ca3` the battery: 4905 mAh, 4.45 V, 1466730 uA, from stock's
`google,battery`/`google,charger` in `dtbo_idx` 6), cherry-picked onto
`omamobile-gs101-int-power`; upstream as
derekross/linux-omarchy-mobile#112. checkpatch clean, W=1 device trees with no
new warning, dt-validate with no new finding (raven's one finding,
`soc_id`, is the base's). The package side (C4) adds
`omamobile-charge-guard` (cheetah's) and loads the charger at boot.
The guard's bands are raven's own, not only cheetah's: raven's stock
`google,chg-temp-limits`, `chg-cv-limits` and `chg-cc-limits` (`dtbo_idx` 6)
are identical to the table in the charger's temperature guard (checked in
review, derekross/linux-omarchy-mobile#112).

**C0 (2026-10-28, `g97f09c8cfada`, read-only, on the wall charger at
21 %): passed.** `i2cget -f -y 2` (bus `i2c-2`, `10d50000.i2c`):

| Reg | Value | Meaning |
|---|---|---|
| 0x69/0xb9 CHG_CNFG_00 | 0x05 | mode 5, charger and buck on |
| 0x69/0xbd CHG_CNFG_04 | 0x23 | float voltage 4350 mV |
| 0x69/0xbb CHG_CNFG_02 | 0x1d | fast charge 1933 mA |
| 0x69/0xc2 CHG_CNFG_09 | 0x13 | input limit 500 mA, NO_AUTOIBUS clear |
| 0x69/0xbf CHG_CNFG_06 | 0x0c | protected registers unlocked |
| 0x69/0xc5 CHG_CNFG_12 | 0x6a | CHGINSEL 1 |
| 0x69/0xcb CHG_CNFG_18 | 0x00 | no charger watchdog |
| 0x69/0xb5 CHG_DETAILS_00 | 0x60 | VBUS valid |
| 0x69/0xb6 CHG_DETAILS_01 | 0xb1 | CC phase, battery OK |
| 0x25/0x00-01 | 0x6a 0x0b | Maxim |
| 0x25/0x93 USBSW_CTRL | 0x09 | data switch closed |

The battery charged at 823 mA then (1.1-1.4 A earlier) with a 500 mA
input limit: with NO_AUTOIBUS clear the chip sets the input current from
its own charger detection. The driver writes only CHGIN_ILIM (bits 6:0)
and leaves that bit, so with `default_ilim_ua=500000` (the value already
there) a wall charger should still charge at the chip's own rate. C2
checks it.

**Runbook (each step the owner's go; the phone on the wall charger, the
session over Wi-Fi: the charger doesn't touch the USB data path,
USB-C-PLAN section 2):**

| Step | What | Expect / pass | Stop | Rollback | Risk |
|---|---|---|---|---|---|
| C1 | push the kernel with the battery description (`omamobile-gs101-int-power` + the two commits), reboot | boots as before; `/proc/device-tree/.../pmic@66/monitored-battery` present; `max77759_charger` still not loaded; charging as in C0 | boot failure | slot A, or the previous images | low |
| C2 | by hand: `modprobe max77759_charger default_ilim_ua=500000 temp_guard=1`, then the C0 dump and `omamobile-charge-guard status` | a `max77759-charger` power supply; CNFG_04 0x2d (4.45 V), CNFG_02 0x16 (1467 mA), CNFG_00 mode 5 within seconds, CNFG_09 0x13 with bit 7 clear; the battery still charging at about 1 A or more; the guard reading the gauge | mode not 5 after 30 s, the battery discharging on the wall charger, any driver error | reboot (the bootloader sets mode 5 again) | low-medium |
| C3 | G2 as cheetah: `modprobe -r max17042_battery` with the guard on | within 30 s the guard logs no reading and stops charging (mode 4); after reloading the gauge, charging comes back | charging continues without a reading | reload the gauge, or reboot | low |
| C4 | device-raven: drop the blacklist, `options max77759_charger default_ilim_ua=500000 temp_guard=1` and the gauge softdep, as cheetah's `omamobile-charger.conf`; reboot | the charger loads at boot; C2's readings | as C2 | blacklist again | low |
| C5 | attended, on the wall charger to full | CV phase, then done at 100 % (not 93 %) | battery over 45 degC | unplug | low |

**C1 (2026-10-28, `g3ba8c15c89b8`): passed.** Pushed from the build
checkout with the phone's own inputs (raven's `kernel.config`, its overlay
list, the splash file: 1809 modules, as before). Boot check `ok`;
`pmic@66` has `monitored-battery`; `max77759_charger` not loaded,
CHG_CNFG_00 still 0x05; haptics loaded. On the laptop port the battery
discharged at about 600 mA, as before.


**C2 (2026-10-28, `g3ba8c15c89b8`, on the wall charger at 26 %, 22 degC):
passed.** `modprobe max77759_charger default_ilim_ua=500000 temp_guard=1`:
`found: mode 0x5, float voltage 4350 mV, fast charge 1933420 uA, input
limit 500000 uA`, then `probed: mode 0x5, float voltage 4450 mV, fast
charge 1466730 uA`, `temperature guard on (max170xx_battery)`, `battery
22.0 C, 3834 mV: band 20-42 C, float 4450 mV, charge 1466730 uA`.
Registers: CNFG_00 0x05, CNFG_04 0x23 -> 0x2d, CNFG_02 0x1d -> 0x16,
CNFG_09 0x13 (bit 7 clear) unchanged, CNFG_06 0x0c -> 0x00 (locked),
CNFG_18 0x00. The battery charged at 1195-1438 mA over the next 30 s
(charger `Charging`, `Fast`, online): the chip's own input detection still
sets the input on a wall charger with the driver loaded.

**C3 (2026-10-28, the same boot, on the wall charger): passed.**
`modprobe -r max17042_battery` with the guard on: 25 s later (its next
30 s check) `no reading from max170xx_battery: charging inhibited`,
CNFG_00 0x05 -> 0x04 (buck only), DETAILS_01 0xb1 -> 0xb8, charger
`Discharging`. After `modprobe max17042_battery`, within 10 s CNFG_00
0x05 and the battery charging at 1440 mA, `band 20-42 C, float 4450 mV,
charge 1466730 uA`.

**C4 (2026-10-28, `g3ba8c15c89b8`, device-raven 0.1.23.3): passed.** The
charger loads at boot from `omamobile-charger.conf` (the blacklist
dropped): a minute after boot `omamobile-charge-guard status` showed the
guard on, 22 degC, `Charging (Fast, health Good)`, float 4450 mV, fast
charge 1466 mA, input limit 500 mA, and 1345 mA into the battery on the
wall charger; CNFG_00/04/02/09 0x05/0x2d/0x16/0x13. **Next: C5**, a full
charge on the wall charger (expect CV, then done at 100 %, not 93 %).

**C5 (2026-10-28, `gdd5e1655ef91`, on the wall charger): passed.** The
battery reached 100 % (not the 93 % the bootloader's 4.35 V stopped at), at
4411 mV and 22 degC, the charger then topping off in CV (`DETAILS_01` 0xb2,
873 mA).
48 changes: 48 additions & 0 deletions packages/omamobile-device-raven/bin/omamobile-charge-guard
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
# SPDX-License-Identifier: MIT
# The charger's battery temperature guard (max77759_charger temp_guard,
# device/cheetah/USB-C-PLAN.md gate B3g; on raven device/raven/USB-PLAN.md
# section 4): stock's step-charging policy,
# no charge outside 0-55 C. Off unless turned on here or by modprobe option.
# omamobile-charge-guard status what the guard sees and what it set
# omamobile-charge-guard on|off switch it at runtime (root)
set -euo pipefail

param=/sys/module/max77759_charger/parameters/temp_guard
bat=/sys/class/power_supply/max170xx_battery
chg=/sys/class/power_supply/max77759-charger

read_or() { cat "$1" 2>/dev/null || echo "${2-?}"; } # an empty default stays empty

status() {
if [[ -r $param ]]; then
echo "guard: $(read_or $param)"
else
echo "guard: max77759_charger not loaded"
fi
local t; t=$(read_or "$bat/temp" "")
if [[ -n $t ]]; then
printf 'battery temp: %d.%d C\n' $((t / 10)) $(((t < 0 ? -t : t) % 10))
else
echo "battery temp: no reading"
fi
echo "battery voltage: $(( $(read_or "$bat/voltage_now" 0) / 1000 )) mV"
echo "battery current: $(( $(read_or "$bat/current_now" 0) / 1000 )) mA"
echo "charger status: $(read_or "$chg/status") ($(read_or "$chg/charge_type"), health $(read_or "$chg/health"))"
# this driver reports the float voltage in mV, the currents in uA
echo "float voltage: $(read_or "$chg/constant_charge_voltage_max") mV"
echo "fast charge: $(( $(read_or "$chg/constant_charge_current_max" 0) / 1000 )) mA"
echo "input limit: $(( $(read_or "$chg/input_current_limit" 0) / 1000 )) mA"
echo "last guard messages:"
journalctl -k -b --no-pager -o cat 2>/dev/null | grep -E "max77759-charger.*(guard|band|inhibit|no reading)" | tail -5 | sed 's/^/ /' || true
}

case "${1:-status}" in
status) status ;;
on|off)
[[ -w $param ]] || { echo "max77759_charger not loaded, or not root" >&2; exit 1; }
[[ $1 == on ]] && echo 1 > "$param" || echo 0 > "$param"
echo "temp_guard=$(cat $param); applied within 30 s"
;;
*) echo "Usage: omamobile-charge-guard [status|on|off]" >&2; exit 1 ;;
esac
16 changes: 12 additions & 4 deletions packages/omamobile-device-raven/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ for f in usr/bin/omamobile-bootctl usr/bin/reboot-to usr/bin/omamobile-boot-succ
usr/lib/systemd/system/plymouth-quit.service.d/10-omamobile-retain-splash.conf usr/bin/omamobile-boot-check \
usr/lib/systemd/system/omamobile-boot-success.service usr/lib/systemd/system/omamobile-usb-rescue.service \
usr/lib/systemd/system/sddm.service.d/omamobile-raven-bluetooth.conf \
usr/lib/modprobe.d/omamobile-raven.conf usr/lib/tmpfiles.d/omamobile-raven-cpufreq.conf \
usr/lib/modprobe.d/omamobile-raven.conf usr/lib/modprobe.d/omamobile-charger.conf \
usr/lib/tmpfiles.d/omamobile-raven-cpufreq.conf usr/bin/omamobile-charge-guard \
usr/lib/udev/rules.d/20-omamobile-display.rules \
usr/lib/NetworkManager/conf.d/omamobile-raven-wifi-powersave.conf \
usr/bin/omamobile-sleep usr/bin/omamobile-sleepd usr/lib/systemd/user/omamobile-sleepd.service \
Expand Down Expand Up @@ -86,14 +87,21 @@ grep -q 'omarchy-toggle-enabled omamobile-sleep ||' bin/omamobile-sleepd || fail
pass "sleep policy"

# Policy that keeps the phone safe at boot
for m in max77759_charger tcpci_maxim gpio_max77759; do
for m in tcpci_maxim gpio_max77759; do
grep -qx "blacklist $m" vendor/modprobe.d/omamobile-raven.conf || fail "$m stays blacklisted"
done
grep -qE '^(options|install) .*max77759_charger' vendor/modprobe.d/omamobile-raven.conf && fail "nothing loads the charger"
# The charger loads, but only with both options: without default_ilim_ua it
# turns charging off at probe, without temp_guard nothing watches the
# battery's temperature (USB-PLAN C2, C3).
! grep -rqx 'blacklist max77759_charger' vendor/modprobe.d || fail "the charger is no longer blacklisted"
grep -qx 'options max77759_charger default_ilim_ua=500000 temp_guard=1' vendor/modprobe.d/omamobile-charger.conf \
|| fail "the charger loads with its input limit and the temperature guard"
grep -qx 'softdep max77759_charger pre: max17042_battery' vendor/modprobe.d/omamobile-charger.conf \
|| fail "the gauge loads before the charger"
# usb-rescue's only write: USBSW_CTRL (0x93) back to 0x09
writes=$(grep -E 'i2cset .*"\$bus" \$tcpc 0x[0-9a-f]+ 0x' bin/omamobile-usb-rescue || true)
[[ $writes == *'0x93 0x09' && $(wc -l <<<"$writes") == 1 ]] || fail "usb-rescue writes only USBSW_CTRL = 0x09"
pass "the charger and the TCPC stay off; usb-rescue writes one register"
pass "the charger loads with its guard, the TCPC stays off; usb-rescue writes one register"
for m in pcie_gs201_cp cpif shm_ipc boot_device_spi; do
grep -qx "blacklist $m" vendor/modprobe.d/omamobile-raven-modem.conf || fail "$m stays blacklisted (modem bring-up)"
done
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: MIT
# Charging policy for max77759_charger, loaded at boot since
# device/raven/USB-PLAN.md C2 and C3 passed (2026-10-28), as on cheetah
# (omamobile-device-cheetah's file of the same name). Both options belong
# together:
# - default_ilim_ua: without a Type-C source (tcpci_maxim stays blacklisted)
# the upstream driver turns charging off at probe; this keeps it on at a
# 500 mA input limit instead. On a wall charger the chip still sets the
# input itself (NO_AUTOIBUS stays clear): 1.2-1.4 A into the battery in C2;
# - temp_guard: stock's step-charging bands from the gauge's temperature
# and voltage, every 30 s; no reading or out of range stops charging.
# The float voltage (4.45 V) and fast charge current (1.47 A) come from the
# battery node in raven's device tree.
# The gauge loads first, so the guard's first reading succeeds.
options max77759_charger default_ilim_ua=500000 temp_guard=1
softdep max77759_charger pre: max17042_battery
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
# per device/raven/BRINGUP-M1.md until each has passed on the phone).
#
# The MAX77759: init loads its core, nvmem and nvmem-reboot-mode itself
# (INITRAMFS_MODULES). Its charger turns charging off at probe (cheetah's
# omamobile-max77759.conf); its TCPC driver would take over the USB-C port
# and the role and orientation of the USB link we run on.
blacklist max77759_charger
# (INITRAMFS_MODULES). Its charger loads at boot (omamobile-charger.conf;
# device/raven/USB-PLAN.md C2, C3); its TCPC driver would take over the
# USB-C port and the role and orientation of the USB link we run on.
blacklist tcpci_maxim
blacklist gpio_max77759
# The Mali-G78 (panfrost) loads at boot: it needs the AArch64 page-table
Expand Down