Fix deep-sleep battery drainers, enable MD1 mem suspend, and update docs
This commit is contained in:
1 parent
180d0a91e6
commit
29314ca9e6
20 files changed
+989
-68
No files matched your search
@@ -21,6 +21,7 @@ Vanilla Linux `7.3.5` builds from [patches/kernel/](patches/kernel/) with `CONFI
|
|||||||
| `0011-gemini-lid-sync-filter-and-debounce.patch` | Hall `GPIO66` synchronous lid filtering, `1 ms` Hall / `10 ms` keypad debounce, touch inhibit |
|
| `0011-gemini-lid-sync-filter-and-debounce.patch` | Hall `GPIO66` synchronous lid filtering, `1 ms` Hall / `10 ms` keypad debounce, touch inhibit |
|
||||||
| `0012-gemini-lid-wake-and-fg-taper-fix.patch` | `PM_POST_SUSPEND` + raw-GPIO lid reconciliation and `mt6351`+`bq25890` zero-current OCV/taper fuel gauge |
|
| `0012-gemini-lid-wake-and-fg-taper-fix.patch` | `PM_POST_SUSPEND` + raw-GPIO lid reconciliation and `mt6351`+`bq25890` zero-current OCV/taper fuel gauge |
|
||||||
| `0013-gemini-pmic-wake-and-spm-safety.patch` | Moves `mt6397_irq_suspend`/`resume` to `LATE_SYSTEM_SLEEP_PM_OPS` and adds SPM `WAKE_PCM_WDT` + `5000 ms` `cntp` backstop |
|
| `0013-gemini-pmic-wake-and-spm-safety.patch` | Moves `mt6397_irq_suspend`/`resume` to `LATE_SYSTEM_SLEEP_PM_OPS` and adds SPM `WAKE_PCM_WDT` + `5000 ms` `cntp` backstop |
|
||||||
|
| `0014-gemini-deep-sleep-power-drainers.patch` | PMIC sleep modes (`pmic_modes=1`, `0.700 V` VCORE clamp), MD1-active SPM `mem` suspend (`allow_md1=1`, `CCIF0`/`CLDMA`/`MD1_WDT` wakes, RF LDO low-IQ), Panfrost `VGPU`/LDO/`MFGPLL` suspend rail-off, and MD1 stage-0 clock/PLL gating |
|
||||||
|
|
||||||
- **Graphics & Radios**: `mediatek-drm` + `SSD2092` DSI/touch, early `simpledrm` (`DRM_SIMPLEDRM=y` + rotated `TER16x32` console), Mali-T880 `panfrost`, `sii902x` HDMI bridge, and `mt6797_wlan_core`/`btmt6797` CONSYS.
|
- **Graphics & Radios**: `mediatek-drm` + `SSD2092` DSI/touch, early `simpledrm` (`DRM_SIMPLEDRM=y` + rotated `TER16x32` console), Mali-T880 `panfrost`, `sii902x` HDMI bridge, and `mt6797_wlan_core`/`btmt6797` CONSYS.
|
||||||
- **Modem / eSIM / IMS**: `mt6797-ccci-cldma` exposes `/dev/ccci_*`, `/dev/ttyC0..3`, and `ccmni*` via `struct mt6797_ccci_header` ([mt6797_ccci.h](prebuilt/kernel/include/linux/mt6797_ccci.h)). [geminux-ccci-fs.c](src/geminux-daemons/geminux-ccci-fs.c) serves MD1 boot HS v2 / NVRAM / RPC; [geminux-cellctl.c](src/geminux-daemons/geminux-cellctl.c) manages SIM/ST33 eUICC (`lpac`) & `ccmni*` PDNs; [geminux-imsd.c](src/geminux-daemons/geminux-imsd.c) implements VoLTE/VoWiFi (`strongswan` `SWu`), MILENAGE AKA, XFRM `ipsec-3gpp`, SIP, `RP-DATA` SMS, and 20 ms RTP.
|
- **Modem / eSIM / IMS**: `mt6797-ccci-cldma` exposes `/dev/ccci_*`, `/dev/ttyC0..3`, and `ccmni*` via `struct mt6797_ccci_header` ([mt6797_ccci.h](prebuilt/kernel/include/linux/mt6797_ccci.h)). [geminux-ccci-fs.c](src/geminux-daemons/geminux-ccci-fs.c) serves MD1 boot HS v2 / NVRAM / RPC; [geminux-cellctl.c](src/geminux-daemons/geminux-cellctl.c) manages SIM/ST33 eUICC (`lpac`) & `ccmni*` PDNs; [geminux-imsd.c](src/geminux-daemons/geminux-imsd.c) implements VoLTE/VoWiFi (`strongswan` `SWu`), MILENAGE AKA, XFRM `ipsec-3gpp`, SIP, `RP-DATA` SMS, and 20 ms RTP.
|
||||||
|
|||||||
+1
-1
@@ -99,4 +99,4 @@ Geminux claims user-writable eMMC past `LBA 0x70000` (`0x0E000000`), replacing A
|
|||||||
- [ ] **Anodized** default theme, `geminux-dark.png` default wallpaper, interactive theme editor, and `geminux-apply-wallpaper` restore cleanly.
|
- [ ] **Anodized** default theme, `geminux-dark.png` default wallpaper, interactive theme editor, and `geminux-apply-wallpaper` restore cleanly.
|
||||||
- [ ] Wi-Fi (`geminux-net`), Bluetooth, and PipeWire audio (speaker, 3.5 mm jack, internal mic) function normally.
|
- [ ] Wi-Fi (`geminux-net`), Bluetooth, and PipeWire audio (speaker, 3.5 mm jack, internal mic) function normally.
|
||||||
- [ ] With MD1 firmware present, `/dev/ccci_md_ctl`, `/dev/ttyC0`, `doas geminux-cellctl status` (`MD_STATE=READY` + SIM/ST33 eUICC), `geminux-imsd`, `ccmni*` data, voice calls (`geminux-dialer`), and SMS (`geminux-sms`) work.
|
- [ ] With MD1 firmware present, `/dev/ccci_md_ctl`, `/dev/ttyC0`, `doas geminux-cellctl status` (`MD_STATE=READY` + SIM/ST33 eUICC), `geminux-imsd`, `ccmni*` data, voice calls (`geminux-dialer`), and SMS (`geminux-sms`) work.
|
||||||
- [ ] Front camera capture (`geminux-camera`), external `SiI9024` HDMI, `/media/sdcard` automount, `Fn+F` Airplane Mode, lid-close & overnight battery deep sleep recovery (`0013`), and `geminux-power-audit` succeed.
|
- [ ] Front camera capture (`geminux-camera`), external `SiI9024` HDMI, `/media/sdcard` automount, `Fn+F` Airplane Mode, lid-close & overnight battery deep sleep recovery (`0013`–`0014`), and `geminux-power-audit` (`pmic_modes=Y`, `allow_md1=Y`, `gpu_rail_suspends`, standby draw in Airplane Mode ON and OFF) succeed.
|
||||||
@@ -101,7 +101,8 @@ doas geminux-cellctl esim-enable <#idx|iccid> # or esim-disable / esim-delete
|
|||||||
### Connectivity, Airplane Mode, Media & System Apps
|
### Connectivity, Airplane Mode, Media & System Apps
|
||||||
|
|
||||||
- **`geminux-net`**: Wi-Fi (`nmcli`, active WLAN pinned top + Disconnect), Cellular/eSIM, Bluetooth (`bluetoothctl`/`rfkill`), `SiI9024` HDMI (`xrandr`), and **DNS** tab (`geminux-dnsctl`: router/Cloudflare/Google/RadicalDNS/Quad9/custom + lookup test).
|
- **`geminux-net`**: Wi-Fi (`nmcli`, active WLAN pinned top + Disconnect), Cellular/eSIM, Bluetooth (`bluetoothctl`/`rfkill`), `SiI9024` HDMI (`xrandr`), and **DNS** tab (`geminux-dnsctl`: router/Cloudflare/Google/RadicalDNS/Quad9/custom + lookup test).
|
||||||
- **Hardware Airplane Mode**: `Fn + F`, `geminux-control`, `geminux-net`, or `doas geminux-power-ctl airplane on|off|toggle|status` unloads CONSYS Wi-Fi/BT modules and sets MD1 to `AT+CFUN=4` across reboots while leaving `usb0` up.
|
- **Hardware Airplane Mode**: `Fn + F`, `geminux-control`, `geminux-net`, or `doas geminux-power-ctl airplane on|off|toggle|status` stops `modemmanager`/`bluetooth`, powers down `MD1` (`stage=0`), and unloads CONSYS Wi-Fi/BT modules across reboots while leaving `usb0` up.
|
||||||
|
- **Closed-lid standby**: Closing the lid on battery locks and blanks the screen (`DPMSModeOff`), unloads Wi-Fi/BT, powers down GPU rails (`rt5735_vgpu`/`MFGPLL`), and enters hardware `mem` suspend—keeping 4G calls and SMS wakeable when Airplane Mode is off (check live stats with `geminux-power-audit`; see [POWER-OPTIMIZATION.md](POWER-OPTIMIZATION.md)).
|
||||||
- **`geminux-audio`, `geminux-datetime`, `geminux-camera`**: PipeWire routing/volumes (`wpctl`), Chrony NTP + timezone (`geminux-tzctl`), and V4L2 10-bit Bayer ISP camera saving JPEG stills (`~/Pictures/`) and MJPEG-AVI (`~/Videos/`).
|
- **`geminux-audio`, `geminux-datetime`, `geminux-camera`**: PipeWire routing/volumes (`wpctl`), Chrony NTP + timezone (`geminux-tzctl`), and V4L2 10-bit Bayer ISP camera saving JPEG stills (`~/Pictures/`) and MJPEG-AVI (`~/Videos/`).
|
||||||
- **`geminux-control`, `geminux-leds`, `geminux-lock`**: Brightness, volume, CPU profiles (`eco`, `balanced`, `performance`), AW9120 RGB LEDs (`/run/geminux/leds.sock`, off idle/full, amber charging LED, manual presets), and `doas` lockscreen.
|
- **`geminux-control`, `geminux-leds`, `geminux-lock`**: Brightness, volume, CPU profiles (`eco`, `balanced`, `performance`), AW9120 RGB LEDs (`/run/geminux/leds.sock`, off idle/full, amber charging LED, manual presets), and `doas` lockscreen.
|
||||||
|
|
||||||
|
|||||||
+44
-23
@@ -1,44 +1,59 @@
|
|||||||
# Power optimization
|
# Power optimization
|
||||||
|
|
||||||
Battery endurance and reliable deep-sleep recovery span kernel configuration, suspend/wake IRQ handling, zero-poll daemons, CPU cluster gating, audio, radios, and storage in Geminux.
|
Geminux tunes the kernel, hardware power rails, radios, and daemons for cool idle operation and multi-day closed-lid standby on the Gemini PDA's `4268 mAh` battery.
|
||||||
|
|
||||||
|
## Standby modes and targets
|
||||||
|
|
||||||
|
| Mode (lid closed on battery) | Endurance target (max avg draw) | Active hardware & wake path |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| **Airplane Mode ON** | **>= 72 h** (`<= 59 mA` avg) | `MD1` powered off (`stage=0`), CONSYS Wi-Fi/BT unloaded, Panfrost `VGPU`/LDOs/`MFGPLL` off, TCXO gated in SPM `mem` sleep; wakes on Hall lid switch (`SW_LID`), power key, USB attach, or internal `600 s` PCM timer rollover |
|
||||||
|
| **Airplane Mode OFF** | **>= 48 h** (`<= 89 mA` avg) | CONSYS unloaded, GPU rails off, 4G `MD1` stays in LTE DRX idle while AP enters SPM `mem` sleep (`allow_md1=1`); RF LDOs (`VTCXO28`, `VRF18`, `VRF12`) use `SRCLKEN0` low-IQ mode; incoming calls/SMS/SIP INVITEs wake AP via `CCIF0`/`CLDMA`/`MD1_WDT` |
|
||||||
|
|
||||||
|
*Actual standby life depends on physical cell health, signal strength / carrier LTE DRX interval, and SIM configuration.*
|
||||||
|
|
||||||
## Kernel-level optimizations
|
## Kernel-level optimizations
|
||||||
|
|
||||||
Built into `7.3.5-geminux` via [kernel/configs/geminux-mt6797x.config](kernel/configs/geminux-mt6797x.config):
|
Built into `7.3.5-geminux` via [kernel/configs/geminux-mt6797x.config](kernel/configs/geminux-mt6797x.config):
|
||||||
|
|
||||||
- **`CONFIG_HZ_100=y` & `CONFIG_RCU_LAZY=y`**: Cuts timer interrupt overhead vs. 250/1000 Hz kernels and batches idle RCU callbacks for deeper CPU C-state residency.
|
- **`CONFIG_HZ_100=y` & `CONFIG_RCU_LAZY=y`**: Cuts periodic timer interrupts compared to 250/1000 Hz kernels and batches idle RCU callbacks for deeper CPU C-state residency.
|
||||||
- **`CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL=y`**: Enables `schedutil` DVFS via `clk-mt6797-mcusys` + `cpufreq-dt` loaded by [geminux-hwinit](overlay/rootfs/etc/init.d/geminux-hwinit) (`GEMINUX_ENABLE_CPUFREQ="yes"` in [conf.d/geminux-hwinit](overlay/rootfs/etc/conf.d/geminux-hwinit)), scaling `policy0` (`221..897 MHz`) and `policy4` (`325..1209 MHz`) independently of Cortex-A72 bring-up (`GEMINUX_ENABLE_A72="no"`).
|
- **`CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL=y`**: Drives `schedutil` DVFS via `clk-mt6797-mcusys` + `cpufreq-dt` loaded by [geminux-hwinit](overlay/rootfs/etc/init.d/geminux-hwinit) (`GEMINUX_ENABLE_CPUFREQ="yes"` in [conf.d/geminux-hwinit](overlay/rootfs/etc/conf.d/geminux-hwinit)), scaling `policy0` (`221..897 MHz`) and `policy4` (`325..1209 MHz`) without waking the Cortex-A72 cluster (`GEMINUX_ENABLE_A72="no"`).
|
||||||
- **`mt6797-gate-unused`**: Gates ~25 unused bootloader leaf clocks (`SPI`, `UART`, `PWM`, `IRTX`, `ICUSB`, `ANC_MD32`, etc.) left on by `clk_ignore_unused`.
|
- **`mt6797-gate-unused`**: Gates ~25 unused bootloader leaf clocks (`SPI`, `UART`, `PWM`, `IRTX`, `ICUSB`, `ANC_MD32`, etc.) left running under `clk_ignore_unused`.
|
||||||
- **Sensor IR LED gating**: Blacklists `stk3310` in [modprobe.d/geminux.conf](overlay/rootfs/etc/modprobe.d/geminux.conf) (`GEMINUX_ENABLE_SENSORS="no"`) to stop unconsumed ALS/proximity IR polling.
|
- **Sensor IR LED gating**: Blacklists `stk3310` in [modprobe.d/geminux.conf](overlay/rootfs/etc/modprobe.d/geminux.conf) (`GEMINUX_ENABLE_SENSORS="no"`) to prevent unconsumed ALS/proximity IR polling.
|
||||||
- **`CONFIG_ZRAM_DEF_COMP_LZ4=y` & `CONFIG_CRYPTO_AES_ARM64_CE_BLK=y`**: `2 GiB` LZ4 `zram` (`vm.swappiness=100`) avoids eMMC flash swap writes; ARMv8 AES-CE accelerates optional LUKS2 (`--allow-discards`).
|
- **`CONFIG_ZRAM_DEF_COMP_LZ4=y` & `CONFIG_CRYPTO_AES_ARM64_CE_BLK=y`**: Uses `2 GiB` LZ4 `zram` (`vm.swappiness=100`) instead of eMMC flash swap, with ARMv8 AES-CE acceleration for optional LUKS2 (`--allow-discards`).
|
||||||
|
|
||||||
## Deep sleep (`mem`) and wakeup reliability
|
## Deep sleep (`mem`) and wakeup reliability
|
||||||
|
|
||||||
`CONFIG_SUSPEND=y` drives Suspend-to-RAM (`mem`) through `mt6797-spm-sleep` (`sodi_idle=0 pmic_modes=0 timer_sec=600` in [modprobe.d/geminux.conf](overlay/rootfs/etc/modprobe.d/geminux.conf)):
|
`CONFIG_SUSPEND=y` drives Suspend-to-RAM (`mem`) through `mt6797-spm-sleep` (`sodi_idle=0 pmic_modes=1 allow_md1=1 timer_sec=600` in [modprobe.d/geminux.conf](overlay/rootfs/etc/modprobe.d/geminux.conf)):
|
||||||
|
|
||||||
- **`pmic_modes=0`**: Prevents `MT6351` from dropping `VCORE` to `0.600 V` while CPU0 remains in `WFI`.
|
- **PMIC sleep modes & TCXO hardware gating (`0014`)**: Re-enables `pmic_modes=1` so `TOP_CON` BIT(6) gates the 26 MHz TCXO whenever `SRCLKEN0` drops low, bucks (`VCORE`/`VGPU`/`VS1`/`VS2`) step down via `VSLEEP_EN`, and six LDOs enter SRCLKEN0 low-IQ mode—while clamping `VCORE` slot `s.slots[7]` (`MT6351_VCORE_CON6`) to `0x10` (`0.700 V`) so CPU0 never browns out in `WFI`.
|
||||||
- **SPM & wake IRQ hardening (`0008`)**: Bounds `spm_enter()` PCM timer rollovers without `.suspend_again`, clears `mtk-eint` debounce on edge wakeups (`SW_LID`/`EINT5`), and fires `pm_wakeup_event()` from `mtk-pmic-keys`.
|
- **MD1 cellular `mem` suspend (`0014`)**: Enables `allow_md1=1` so closed-lid standby enters true SPM `mem` sleep even while 4G `MD1` is booted (SODI still refuses active MD1):
|
||||||
- **Hall lid filtering & debounce (`0011`)**: Applies `1 ms` Hall EINT / `10 ms` keypad debounce, synchronously filtering spurious inputs and inhibiting keypad + touch when closed.
|
- Arms `WAKE_CCIF0` (`BIT(8)`), `WAKE_MD1_WDT` (`BIT(25)`), and `WAKE_CLDMA` (`BIT(26)`) dynamically when `MD1` is active, and exposes the latest wakeup bitmask via `last_wake_r12`.
|
||||||
- **Lid resume & fuel gauge (`0012`)**: Reconciles `gemini-lid` state via `PM_POST_SUSPEND` + raw-GPIO rechecks (preventing stuck `BL_CORE_SUSPENDED`/input lockouts), and improves `mt6351-fuel-gauge` + `bq25890` zero-current boot OCV, CV-taper validation, `+1%` step caps, and `180 mV` `ADC21` sag tolerance.
|
- Enables `MT6351_LDO_MODE_CTRL_BIT` (`SRCLKEN0` low-IQ mode) on `VTCXO28`/`VRF18`/`VRF12` without cutting RF transceiver power.
|
||||||
- **PMIC wake IRQ order & SPM backstops (`0013`)**: Moves `mt6397_irq_suspend`/`mt6397_irq_resume` from `PM_SUSPEND_PREPARE` into `LATE_SYSTEM_SLEEP_PM_OPS` so child `enable_irq_wake()` settings arm cleanly before deep sleep, and adds `WAKE_PCM_WDT`, `pcm_wdt`, `im_wait` (`1000 us`), and a `5000 ms` `cntp` physical timer backstop (`100 ms` on `s.sodi`) on `mt6797-spm-sleep` `s.sleep` to prevent unrecoverable overnight hangs.
|
- Guards pending `rx_work` and unread RX GPDs in `mt6797_ccci_suspend()`, restores/restarts RX `SO` rings in `mt6797_ccci_resume()`, and raises `pm_wakeup_event()` to `3000 ms` on CLDMA/CCIF interrupts.
|
||||||
|
- **Panfrost VGPU / LDO / MFGPLL suspend rail-off (`0014`)**: Once all four GPU core domains are runtime-suspended, `panfrost_device_suspend()` releases OPP/regulator references alongside `mt->vgpu` (shutting off external `rt5735_vgpu`), clears `MT6797_GPULDO_EN` (`0x1ff -> 0`), and parks `mfg-sel` on `clk26m` to power off `MFGPLL`, restoring in vendor LDO → `vgpu` → `clk_set_rate` → OPP order on resume.
|
||||||
|
- **CCCI MD1 cold-boot & flight-mode gating (`0014`)**: `mt6797_ccci_power_off()` and cold-boot `stage=0` re-gate `INFRA_CG0_MD_MASK`/`INFRA_CG1_MD_MASK`, set `C2K_LTE_LS_ISO_BIT` and `MD1_EXT_BUCK_ISO_BIT`, clear `MDPLL1` 26 MHz clock bits, and ensure `SPM_MD1_PWR_CON` is powered down so Airplane Mode leaks zero modem power.
|
||||||
|
- **SPM, Hall lid, PMIC IRQ & fuel-gauge hardening (`0008`, `0011`, `0012`, `0013`)**: Bounds `spm_enter()` PCM rollovers, clears `mtk-eint` debounce across wakeups, debounces Hall `SW_LID` (`1 ms`) / keypad (`10 ms`), reconciles `gemini-lid` on `PM_POST_SUSPEND`, moves `mt6397_irq_suspend`/`resume` to `LATE_SYSTEM_SLEEP_PM_OPS`, adds `WAKE_PCM_WDT` + a `5000 ms` `cntp` safety backstop, and stabilizes `mt6351-fuel-gauge` + `bq25890` zero-current OCV/taper calibration.
|
||||||
|
|
||||||
## Zero-poll userspace daemons
|
## Zero-poll userspace daemons
|
||||||
|
|
||||||
### `geminux-powerd`
|
### `geminux-powerd`
|
||||||
|
|
||||||
Sleeps in `epoll_wait()` over `/dev/input/event*` (`SW_LID`, `KEY_POWER`, `mtk-pmic-keys` `KEY_ESC`), filtered `KOBJECT_UEVENT` netlink (`input`, `power_supply`, `drm`), `/run/geminux/powerd.sock`, and a lazy `timerfd`:
|
Starts `after modules geminux-hwinit geminux-ccci` and waits in `epoll_wait()` over `/dev/input/event*` (`SW_LID`, `KEY_POWER`, `mtk-pmic-keys` `KEY_ESC`), filtered `KOBJECT_UEVENT` netlink (`input`, `power_supply`, `drm`), `/run/geminux/powerd.sock`, and a lazy `timerfd`:
|
||||||
|
|
||||||
- **USB/AC policy (`inhibit_ac_lid`)**: Locks/blanks without unloading CONSYS or invoking `/sys/power/state`, keeping `bq25890`'s `40 s` watchdog fed without `-EBUSY` suspend thrash.
|
- **USB/AC policy (`inhibit_ac_lid`)**: Locks and blanks (`bl_power=4` + `DPMSModeOff`) without unloading CONSYS or invoking `/sys/power/state`, keeping `bq25890`'s `40 s` watchdog fed without `-EBUSY` thrash.
|
||||||
- **Battery `mem` vs. `low_power_standby`**: Unloads `mt6797_consys` (+ dependents) and offlines `cpu1..9` before `mem` sleep; if 4G `MD1` blocks `mem`, holds zero-thrash `low_power_standby` (`cpu0 @ 221 MHz` `powersave`, never `freeze`/`s2idle`).
|
- **Battery `mem` & standby backoff**: Enters `mem` suspend whenever `md1/stage == 0` or `allow_md1=Y` (falling back to `low_power_standby` for active MD1 only if `allow_md1=N`). Before suspending, it reaps any in-flight `radio_worker_pid`, unloads CONSYS, and ensures `md1/stage == 0` when Airplane Mode is enabled; transient `-EBUSY` results trigger exponential retries (`3s -> 10s -> 30s -> 60s`) and immediate `SIGCHLD` re-arming when `radio_worker_pid` completes.
|
||||||
- **Wakeup filtering & quiet open-lid re-suspend**: Polls post-resume events (`90 ms`) even with the lid open so only `closed -> open` lid events, genuine `EV_KEY`/`EV_REL`/`EV_ABS` activity, or USB/AC attach wake the session; internal timer wakes during open-lid `IDLE_STAGE_LOCKED_BLANK` re-suspend quietly (`quiet_timer_resleep`) without reloading CONSYS or waking the backlight.
|
- **Wakeup filtering & modem-wake grace**: Polls post-resume input events (`90 ms`) BEFORE onlining secondary CPUs and checks `/sys/module/mt6797_spm_sleep/parameters/last_wake_r12`:
|
||||||
- **X11 DPMS wake & lock sync**: Unblanking runs `DPMSForceLevel(..., DPMSModeOn)` + `XResetScreenSaver()` in a privilege-dropped child so X11/HDMI outputs never stay blanked across S3 or lid events; pre-suspend locking waits up to `1800 ms` for `geminux-lock` to draw, grab input, and publish `_GEMINUX_LOCK_READY`.
|
- Internal `600 s` PCM timer rollovers (`quiet_timer_resleep`) keep `cpu1..7` offline and re-enter `mem` sleep after `300 ms` without waking Xorg or reloading CONSYS.
|
||||||
- **Persisted state & caching**: Persists Airplane Mode (`/var/lib/geminux/airplane-mode`) and caches CPUfreq/profile writes.
|
- Modem wakes (`CCIF0`/`MD1_WDT`/`CLDMA`) grant a `3500 ms` closed-lid grace window so `ModemManager`/`geminux-modem-ctl`/`geminux-imsd` can assert `inhibit add call`; once the call ends (`inhibit del`), suspend re-arms after `1000 ms`.
|
||||||
|
- Only `closed -> open` lid transitions, genuine user input, or AC attach wake the session.
|
||||||
|
- **X11 DPMS blank/wake & lock sync**: Blanking sets `brightness=0`, `bl_power=4`, and `DPMSModeOff`; unblanking calls `DPMSForceLevel(..., DPMSModeOn)` + `XResetScreenSaver()` in a `500 ms` timeout-capped privilege-dropped child; pre-suspend locking waits up to `1800 ms` for `geminux-lock` to publish `_GEMINUX_LOCK_READY`.
|
||||||
|
|
||||||
### Supporting daemons & X11 efficiency
|
### Supporting daemons & X11 efficiency
|
||||||
|
|
||||||
- **`geminux-statusd`**: `epoll` (`signalfd`, netlink, filtered uevents, `inotify`, minute-aligned `timerfd`); deduplicates `WM_NAME` updates with zero shell forks.
|
- **`geminux-statusd`**: Event-driven `epoll` (`signalfd`, netlink, filtered uevents, `inotify`, minute-aligned `timerfd`); deduplicates `WM_NAME` updates with zero shell forks.
|
||||||
- **Display & `st`**: `ShadowFB` + `TearFree` (`AccelMethod "none"` in [10-geminux-gpu.conf](overlay/rootfs/etc/X11/xorg.conf.d/10-geminux-gpu.conf)) eliminates Glamor spin-waits; `st` stops cursor blink timers when unfocused.
|
- **`geminux-modem-ctl`**: Sleeps in `epoll_wait(..., -1)` via `inotify` on `/run/geminux` (`airplane-mode`, `ims-state`) with no `dbus-monitor` or retry timer while Airplane Mode is active.
|
||||||
- **Input, Audio, Modem, LEDs & Lock**: `geminux-touchd`, `geminux-ccci-daemon`, `geminux-modem-ctl`, `geminux-imsd` (20 ms RTP `timerfd` armed only mid-call), `geminux-bt-obex`, `geminux-leds` (AW9120 strip `0 mA` idle/100%, `rgb:indicator-6` while charging), and `geminux-lock` (`15 s` refresh, diff-checked).
|
- **Display & `st`**: `ShadowFB` + `TearFree` (`AccelMethod "none"` in [10-geminux-gpu.conf](overlay/rootfs/etc/X11/xorg.conf.d/10-geminux-gpu.conf)) avoids Glamor spin-waits; `st` pauses cursor blink timers when unfocused.
|
||||||
|
- **Input, Audio, Modem, LEDs & Lock**: `geminux-touchd`, `geminux-ccci-daemon`, `geminux-imsd` (`20 ms` RTP `timerfd` armed only mid-call), `geminux-bt-obex`, `geminux-leds` (AW9120 strip `0 mA` idle/100%, amber `rgb:indicator-6` while charging), and `geminux-lock` (`15 s` clock refresh, diff-checked).
|
||||||
|
|
||||||
## Cluster gating and profiles
|
## Cluster gating and profiles
|
||||||
|
|
||||||
@@ -59,11 +74,17 @@ Idle timers count strictly from the last user input (`CLOCK_MONOTONIC`), ignorin
|
|||||||
- **Wi-Fi & NTP**: `wifi.powersave = 2` prevents associated CONSYS key/DNS stalls; Chrony uses `maxsources 2`, `minpoll 10 maxpoll 14` ([10-geminux.sources](overlay/rootfs/etc/chrony/sources.d/10-geminux.sources)) + offline dispatch ([30-geminux-chrony](overlay/rootfs/etc/NetworkManager/dispatcher.d/30-geminux-chrony)).
|
- **Wi-Fi & NTP**: `wifi.powersave = 2` prevents associated CONSYS key/DNS stalls; Chrony uses `maxsources 2`, `minpoll 10 maxpoll 14` ([10-geminux.sources](overlay/rootfs/etc/chrony/sources.d/10-geminux.sources)) + offline dispatch ([30-geminux-chrony](overlay/rootfs/etc/NetworkManager/dispatcher.d/30-geminux-chrony)).
|
||||||
- **Toolkits & Storage**: `NO_AT_BRIDGE=1` ([10-geminux-env.sh](overlay/rootfs/etc/profile.d/10-geminux-env.sh)) avoids idle AT-SPI daemons; `noatime,commit=60` and `dirty_writeback_centisecs=1500` cut eMMC wakes; `/media/sdcard` mounts `noatime` purely via `eudev` hotplug.
|
- **Toolkits & Storage**: `NO_AT_BRIDGE=1` ([10-geminux-env.sh](overlay/rootfs/etc/profile.d/10-geminux-env.sh)) avoids idle AT-SPI daemons; `noatime,commit=60` and `dirty_writeback_centisecs=1500` cut eMMC wakes; `/media/sdcard` mounts `noatime` purely via `eudev` hotplug.
|
||||||
|
|
||||||
## Auditing on device
|
## On-device verification and fallback
|
||||||
|
|
||||||
|
Inspect live power, suspend counters, GPU rail state, and wake reasons at any time:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
geminux-power-audit
|
geminux-power-audit
|
||||||
geminux-power-audit --json
|
geminux-power-audit --json
|
||||||
```
|
```
|
||||||
|
|
||||||
Reports live profile, battery stats, online CPUs, governors, frequency caps, Bluetooth `rfkill` state, ZRAM algorithm, and `/sys/power/mem_sleep`. Actual idle current draw and overnight endurance must be measured on physical hardware.
|
Look for `"spm_pmic_modes":"Y"`, `"spm_allow_md1":"Y"`, incrementing `"suspend_success"` and `"gpu_rail_suspends"`, `"vgpu_state":"disabled"`, `"last_failed_dev":"none"`, and standby current draw (`current_ua`) after a closed-lid battery sleep window. If you ever need to test cellular fallback without MD1 `mem` suspend, disable `allow_md1` at runtime:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
echo 0 | doas tee /sys/module/mt6797_spm_sleep/parameters/allow_md1
|
||||||
|
```
|
||||||
@@ -35,11 +35,11 @@ Geminux is an Alpine Linux (`aarch64`, musl, OpenRC) distribution built for the
|
|||||||
| [INSTALL.md](INSTALL.md) | Release ZIP flashing, source build, firmware extraction, LUKS2 FDE, and hardware checklist |
|
| [INSTALL.md](INSTALL.md) | Release ZIP flashing, source build, firmware extraction, LUKS2 FDE, and hardware checklist |
|
||||||
| [MANUAL.md](MANUAL.md) | Keyboard map, DWM shortcuts, gestures, themes, wallpapers, apps, and `apk upgrade` safety |
|
| [MANUAL.md](MANUAL.md) | Keyboard map, DWM shortcuts, gestures, themes, wallpapers, apps, and `apk upgrade` safety |
|
||||||
| [ARCHITECTURE.md](ARCHITECTURE.md) | Kernel patches, XLibre/suckless hardening, theming/wallpaper engine, daemons, APKs, and flasher internals |
|
| [ARCHITECTURE.md](ARCHITECTURE.md) | Kernel patches, XLibre/suckless hardening, theming/wallpaper engine, daemons, APKs, and flasher internals |
|
||||||
| [POWER-OPTIMIZATION.md](POWER-OPTIMIZATION.md) | Suspend/wakeup fixes, zero-poll daemons, cluster profiles, and `geminux-power-audit` |
|
| [POWER-OPTIMIZATION.md](POWER-OPTIMIZATION.md) | Deep-sleep standby (`72 h+` Airplane / `48 h+` cellular targets), zero-poll daemons, cluster profiles, and `geminux-power-audit` |
|
||||||
|
|
||||||
## Repository layout
|
## Repository layout
|
||||||
|
|
||||||
- [kernel/](kernel/) & [patches/kernel/](patches/kernel/) — Kernel manifest, MT6797X config, and Linux `7.3.5` patches (`0001`–`0013`)
|
- [kernel/](kernel/) & [patches/kernel/](patches/kernel/) — Kernel manifest, MT6797X config, and Linux `7.3.5` patches (`0001`–`0014`)
|
||||||
- [src/](src/) — Initramfs, `st`, `dwm`, `dmenu`, `dunst-notify`, `bantam`, `webarchy`, `gtkTtk`, `libgemui`, 11 apps, and daemons
|
- [src/](src/) — Initramfs, `st`, `dwm`, `dmenu`, `dunst-notify`, `bantam`, `webarchy`, `gtkTtk`, `libgemui`, 11 apps, and daemons
|
||||||
- [overlay/rootfs/](overlay/rootfs/) & [artwork/](artwork/) — OpenRC units, XKB/keymap, Xorg configs, 22 `.xth` themes, stock wallpapers, and scripts
|
- [overlay/rootfs/](overlay/rootfs/) & [artwork/](artwork/) — OpenRC units, XKB/keymap, Xorg configs, 22 `.xth` themes, stock wallpapers, and scripts
|
||||||
- [scripts/](scripts/) — Cross-compile builders, APK/ZIP packagers, verification suite, and 9 Python unit test suites
|
- [scripts/](scripts/) — Cross-compile builders, APK/ZIP packagers, verification suite, and 9 Python unit test suites
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ command="/usr/sbin/geminux-powerd"
|
|||||||
|
|
||||||
depend() {
|
depend() {
|
||||||
need localmount udev
|
need localmount udev
|
||||||
after modules
|
after modules geminux-hwinit geminux-ccci
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# Enforce MT6797X safe hardware initialization order
|
# Enforce MT6797X safe hardware initialization order
|
||||||
options mt6797_spm_sleep sodi_idle=0 pmic_modes=0 timer_sec=600
|
options mt6797_spm_sleep sodi_idle=0 pmic_modes=1 allow_md1=1 timer_sec=600
|
||||||
options mt6797_wlan power_save=0
|
options mt6797_wlan power_save=0
|
||||||
softdep cpufreq_dt pre: clk_mt6797_mcusys
|
softdep cpufreq_dt pre: clk_mt6797_mcusys
|
||||||
softdep mtk_cci_devfreq pre: clk_mt6797_mcusys
|
softdep mtk_cci_devfreq pre: clk_mt6797_mcusys
|
||||||
|
|||||||
@@ -0,0 +1,551 @@
|
|||||||
|
--- a/drivers/gpu/drm/panfrost/panfrost_device.c 2026-11-28 08:07:33.574741240 +0000
|
||||||
|
+++ b/drivers/gpu/drm/panfrost/panfrost_device.c 2026-11-28 08:08:01.499786780 +0000
|
||||||
|
@@ -541,6 +541,12 @@
|
||||||
|
struct panfrost_device *pfdev = dev_get_drvdata(dev);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
+ if (pfdev->comp->platform_ops && pfdev->comp->platform_ops->resume_rail) {
|
||||||
|
+ ret = pfdev->comp->platform_ops->resume_rail(pfdev);
|
||||||
|
+ if (ret)
|
||||||
|
+ return ret;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
if (pfdev->comp->pm_features & BIT(GPU_PM_VREG_OFF)) {
|
||||||
|
unsigned long freq = pfdev->pfdevfreq.fast_rate;
|
||||||
|
struct dev_pm_opp *opp;
|
||||||
|
@@ -587,6 +593,10 @@
|
||||||
|
struct panfrost_device *pfdev = dev_get_drvdata(dev);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
+ if (pfdev->comp->platform_ops && pfdev->comp->platform_ops->suspend_rail &&
|
||||||
|
+ !pm_runtime_status_suspended(dev))
|
||||||
|
+ (void)pm_runtime_suspend(dev);
|
||||||
|
+
|
||||||
|
ret = pm_runtime_force_suspend(dev);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
@@ -601,6 +611,9 @@
|
||||||
|
if (pfdev->comp->pm_features & BIT(GPU_PM_VREG_OFF))
|
||||||
|
dev_pm_opp_set_opp(dev, NULL);
|
||||||
|
|
||||||
|
+ if (pfdev->comp->platform_ops && pfdev->comp->platform_ops->suspend_rail)
|
||||||
|
+ pfdev->comp->platform_ops->suspend_rail(pfdev);
|
||||||
|
+
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
--- a/drivers/gpu/drm/panfrost/panfrost_device.h 2026-11-28 08:07:33.574534421 +0000
|
||||||
|
+++ b/drivers/gpu/drm/panfrost/panfrost_device.h 2026-11-28 08:08:01.499643079 +0000
|
||||||
|
@@ -100,6 +100,9 @@
|
||||||
|
void (*unpower_early)(struct panfrost_device *pfdev);
|
||||||
|
/* After the domains are off. */
|
||||||
|
void (*unpower_late)(struct panfrost_device *pfdev);
|
||||||
|
+ /* System suspend/resume rail power-down after all domains are off. */
|
||||||
|
+ void (*suspend_rail)(struct panfrost_device *pfdev);
|
||||||
|
+ int (*resume_rail)(struct panfrost_device *pfdev);
|
||||||
|
/* Whether runtime suspend must not power the domains off. */
|
||||||
|
bool (*keep_powered)(void);
|
||||||
|
/* Whether to use the OPP table, with devfreq and cooling. */
|
||||||
|
--- a/drivers/gpu/drm/panfrost/panfrost_mt6797.c 2026-11-28 08:07:33.574997533 +0000
|
||||||
|
+++ b/drivers/gpu/drm/panfrost/panfrost_mt6797.c 2026-11-28 08:08:01.499948594 +0000
|
||||||
|
@@ -21,6 +21,8 @@
|
||||||
|
#include <linux/math.h>
|
||||||
|
#include <linux/mfd/syscon.h>
|
||||||
|
#include <linux/module.h>
|
||||||
|
+#include <linux/pm_opp.h>
|
||||||
|
+#include <linux/pm_runtime.h>
|
||||||
|
#include <linux/regmap.h>
|
||||||
|
#include <linux/regulator/consumer.h>
|
||||||
|
#include <linux/reset.h>
|
||||||
|
@@ -94,12 +96,19 @@
|
||||||
|
module_param_named(mt6797_idle_off, mt6797_idle_off, bool, 0444);
|
||||||
|
MODULE_PARM_DESC(mt6797_idle_off, "MT6797: power the GPU domains off when idle (default on)");
|
||||||
|
|
||||||
|
+static unsigned long mt6797_rail_suspends;
|
||||||
|
+module_param_named(mt6797_rail_suspends, mt6797_rail_suspends, ulong, 0444);
|
||||||
|
+MODULE_PARM_DESC(mt6797_rail_suspends, "MT6797: system suspends that powered off VGPU, LDOs, and MFGPLL");
|
||||||
|
+
|
||||||
|
struct panfrost_mt6797 {
|
||||||
|
struct regulator *vgpu;
|
||||||
|
struct clk *sel;
|
||||||
|
struct clk *park;
|
||||||
|
+ struct clk *parent;
|
||||||
|
struct regmap *infracfg;
|
||||||
|
struct regmap *mfg;
|
||||||
|
+ unsigned long saved_rate;
|
||||||
|
+ bool rail_suspended;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int mt6797_check_temperature(struct device *dev)
|
||||||
|
@@ -138,6 +147,7 @@
|
||||||
|
parent = mt6797_parent == 1 ? devm_clk_get(dev, "mfg-syspll-d3") : mt->park;
|
||||||
|
if (IS_ERR(parent))
|
||||||
|
return PTR_ERR(parent);
|
||||||
|
+ mt->parent = parent;
|
||||||
|
sel_52m = devm_clk_get(dev, "mfg-52m-sel");
|
||||||
|
if (IS_ERR(sel_52m))
|
||||||
|
return PTR_ERR(sel_52m);
|
||||||
|
@@ -387,6 +397,9 @@
|
||||||
|
{
|
||||||
|
struct panfrost_mt6797 *mt = pfdev->platform_data;
|
||||||
|
|
||||||
|
+ if (!mt || mt->rail_suspended)
|
||||||
|
+ return;
|
||||||
|
+
|
||||||
|
regulator_disable(mt->vgpu);
|
||||||
|
regmap_write(mt->infracfg, MT6797_GPULDO_EN, 0);
|
||||||
|
|
||||||
|
@@ -399,6 +412,108 @@
|
||||||
|
dev_warn(pfdev->base.dev, "mt6797: GPU clock not parked\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
+static void mt6797_suspend_rail(struct panfrost_device *pfdev)
|
||||||
|
+{
|
||||||
|
+ struct panfrost_mt6797 *mt = pfdev->platform_data;
|
||||||
|
+ struct device *dev = pfdev->base.dev;
|
||||||
|
+ int i;
|
||||||
|
+
|
||||||
|
+ if (!mt || mt->rail_suspended)
|
||||||
|
+ return;
|
||||||
|
+
|
||||||
|
+ for (i = 0; i < ARRAY_SIZE(pfdev->pm_domain_devs); i++) {
|
||||||
|
+ if (pfdev->pm_domain_devs[i] &&
|
||||||
|
+ !pm_runtime_status_suspended(pfdev->pm_domain_devs[i])) {
|
||||||
|
+ dev_dbg(dev, "mt6797: skipping VGPU rail-off, domain %d active\n", i);
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ mt->saved_rate = pfdev->pfdevfreq.current_frequency ?:
|
||||||
|
+ (MT6797_DVFS_START_KHZ * 1000UL);
|
||||||
|
+
|
||||||
|
+ /* Drop the OPP/generic supply ref alongside mt->vgpu so RT5735 powers off */
|
||||||
|
+ if (pfdev->pfdevfreq.opp_of_table_added)
|
||||||
|
+ dev_pm_opp_set_opp(dev, NULL);
|
||||||
|
+ else if (pfdev->regulators)
|
||||||
|
+ regulator_bulk_disable(pfdev->comp->num_supplies, pfdev->regulators);
|
||||||
|
+
|
||||||
|
+ mt6797_unpower_late(pfdev);
|
||||||
|
+ mt->rail_suspended = true;
|
||||||
|
+ mt6797_rail_suspends++;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static int mt6797_resume_rail(struct panfrost_device *pfdev)
|
||||||
|
+{
|
||||||
|
+ struct panfrost_mt6797 *mt = pfdev->platform_data;
|
||||||
|
+ struct device *dev = pfdev->base.dev;
|
||||||
|
+ struct dev_pm_opp *opp = NULL;
|
||||||
|
+ unsigned long freq;
|
||||||
|
+ int ret;
|
||||||
|
+
|
||||||
|
+ if (!mt || !mt->rail_suspended)
|
||||||
|
+ return 0;
|
||||||
|
+
|
||||||
|
+ ret = mt6797_setup_ldos(dev, mt);
|
||||||
|
+ if (ret)
|
||||||
|
+ return ret;
|
||||||
|
+
|
||||||
|
+ ret = regmap_write(mt->infracfg, MT6797_GPULDO_EN, MT6797_GPULDO_EN_ALL);
|
||||||
|
+ if (ret)
|
||||||
|
+ return ret;
|
||||||
|
+
|
||||||
|
+ ret = regulator_enable(mt->vgpu);
|
||||||
|
+ if (ret)
|
||||||
|
+ goto err_ldo;
|
||||||
|
+
|
||||||
|
+ if (pfdev->pfdevfreq.opp_of_table_added) {
|
||||||
|
+ freq = mt->saved_rate ?: (MT6797_DVFS_START_KHZ * 1000UL);
|
||||||
|
+ opp = dev_pm_opp_find_freq_ceil(dev, &freq);
|
||||||
|
+ if (IS_ERR(opp))
|
||||||
|
+ opp = dev_pm_opp_find_freq_floor(dev, &freq);
|
||||||
|
+ if (IS_ERR(opp)) {
|
||||||
|
+ ret = PTR_ERR(opp);
|
||||||
|
+ goto err_vgpu;
|
||||||
|
+ }
|
||||||
|
+ /* Reparent mfg-sel onto MFGPLL before OPP checks/enables its leaf clock */
|
||||||
|
+ ret = clk_set_rate(mt->sel, freq);
|
||||||
|
+ if (ret) {
|
||||||
|
+ dev_pm_opp_put(opp);
|
||||||
|
+ goto err_vgpu;
|
||||||
|
+ }
|
||||||
|
+ ret = dev_pm_opp_set_opp(dev, opp);
|
||||||
|
+ dev_pm_opp_put(opp);
|
||||||
|
+ if (ret)
|
||||||
|
+ goto err_vgpu;
|
||||||
|
+ } else {
|
||||||
|
+ if (pfdev->regulators) {
|
||||||
|
+ ret = regulator_bulk_enable(pfdev->comp->num_supplies,
|
||||||
|
+ pfdev->regulators);
|
||||||
|
+ if (ret)
|
||||||
|
+ goto err_vgpu;
|
||||||
|
+ }
|
||||||
|
+ if (mt6797_khz == 442500 || mt6797_khz == 520000)
|
||||||
|
+ ret = clk_set_rate(mt->sel, mt6797_khz * 1000UL);
|
||||||
|
+ else if (mt->parent)
|
||||||
|
+ ret = clk_set_parent(mt->sel, mt->parent);
|
||||||
|
+ if (ret)
|
||||||
|
+ goto err_bulk;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ mt->rail_suspended = false;
|
||||||
|
+ return 0;
|
||||||
|
+
|
||||||
|
+err_bulk:
|
||||||
|
+ if (pfdev->regulators)
|
||||||
|
+ regulator_bulk_disable(pfdev->comp->num_supplies, pfdev->regulators);
|
||||||
|
+err_vgpu:
|
||||||
|
+ regulator_disable(mt->vgpu);
|
||||||
|
+ clk_set_parent(mt->sel, mt->park);
|
||||||
|
+err_ldo:
|
||||||
|
+ regmap_write(mt->infracfg, MT6797_GPULDO_EN, 0);
|
||||||
|
+ return ret;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
static bool mt6797_keep_powered(void)
|
||||||
|
{
|
||||||
|
return !mt6797_idle_off;
|
||||||
|
@@ -427,6 +542,8 @@
|
||||||
|
.power_late = mt6797_power_late,
|
||||||
|
.unpower_early = mt6797_unpower_early,
|
||||||
|
.unpower_late = mt6797_unpower_late,
|
||||||
|
+ .suspend_rail = mt6797_suspend_rail,
|
||||||
|
+ .resume_rail = mt6797_resume_rail,
|
||||||
|
.keep_powered = mt6797_keep_powered,
|
||||||
|
.use_opps = mt6797_use_opps,
|
||||||
|
.log_rates = mt6797_logs_rates,
|
||||||
|
--- a/drivers/soc/mediatek/mt6797-ccci-cldma.c 2026-11-28 08:07:33.575470324 +0000
|
||||||
|
+++ b/drivers/soc/mediatek/mt6797-ccci-cldma.c 2026-11-28 08:09:08.110394843 +0000
|
||||||
|
@@ -56,7 +56,9 @@
|
||||||
|
#define DRV_NAME "mt6797-ccci-cldma"
|
||||||
|
|
||||||
|
/* INFRA_AO registers (from MT6797 cldma_reg.h & clk-mt6797.c) */
|
||||||
|
+#define INFRA_CG0_SET 0x0080
|
||||||
|
#define INFRA_CG0_CLR 0x0084
|
||||||
|
+#define INFRA_CG1_SET 0x0088
|
||||||
|
#define INFRA_CG1_CLR 0x008c
|
||||||
|
#define INFRA_CG0_MD_MASK (BIT(2) | BIT(27) | BIT(28) | BIT(29))
|
||||||
|
#define INFRA_CG1_MD_MASK (BIT(0) | BIT(3) | BIT(7) | BIT(12) | \
|
||||||
|
@@ -1017,11 +1019,14 @@
|
||||||
|
|
||||||
|
if (!on) {
|
||||||
|
regmap_update_bits(cdev->pmic_regmap, MT6351_LDO_VRF12_CON0,
|
||||||
|
- MT6351_LDO_EN_BIT | MT6351_LDO_ON_CTRL_BIT, 0);
|
||||||
|
+ MT6351_LDO_EN_BIT | MT6351_LDO_MODE_CTRL_BIT |
|
||||||
|
+ MT6351_LDO_ON_CTRL_BIT, 0);
|
||||||
|
regmap_update_bits(cdev->pmic_regmap, MT6351_LDO_VRF18_CON0,
|
||||||
|
- MT6351_LDO_EN_BIT | MT6351_LDO_ON_CTRL_BIT, 0);
|
||||||
|
+ MT6351_LDO_EN_BIT | MT6351_LDO_MODE_CTRL_BIT |
|
||||||
|
+ MT6351_LDO_ON_CTRL_BIT, 0);
|
||||||
|
regmap_update_bits(cdev->pmic_regmap, MT6351_LDO_VTCXO28_CON0,
|
||||||
|
- MT6351_LDO_EN_BIT | MT6351_LDO_ON_CTRL_BIT, 0);
|
||||||
|
+ MT6351_LDO_EN_BIT | MT6351_LDO_MODE_CTRL_BIT |
|
||||||
|
+ MT6351_LDO_ON_CTRL_BIT, 0);
|
||||||
|
/* Keep shared MT6351 VA18 (FGADC, AUXADC, audio) enabled */
|
||||||
|
regmap_update_bits(cdev->pmic_regmap, MT6351_LDO_VA18_CON0,
|
||||||
|
MT6351_LDO_EN_BIT | MT6351_LDO_ON_CTRL_BIT, MT6351_LDO_EN_BIT);
|
||||||
|
@@ -1074,14 +1079,17 @@
|
||||||
|
MT6351_LDO_SRCLK_EN_MASK,
|
||||||
|
MT6351_LDO_EN_BIT | MT6351_LDO_ON_CTRL_BIT);
|
||||||
|
regmap_update_bits(cdev->pmic_regmap, MT6351_LDO_VTCXO28_CON0,
|
||||||
|
- MT6351_LDO_EN_BIT | MT6351_LDO_ON_CTRL_BIT,
|
||||||
|
- MT6351_LDO_EN_BIT);
|
||||||
|
+ MT6351_LDO_EN_BIT | MT6351_LDO_MODE_CTRL_BIT |
|
||||||
|
+ MT6351_LDO_ON_CTRL_BIT | MT6351_LDO_SRCLK_MODE_MASK,
|
||||||
|
+ MT6351_LDO_EN_BIT | MT6351_LDO_MODE_CTRL_BIT);
|
||||||
|
regmap_update_bits(cdev->pmic_regmap, MT6351_LDO_VRF18_CON0,
|
||||||
|
- MT6351_LDO_EN_BIT | MT6351_LDO_ON_CTRL_BIT,
|
||||||
|
- MT6351_LDO_EN_BIT);
|
||||||
|
+ MT6351_LDO_EN_BIT | MT6351_LDO_MODE_CTRL_BIT |
|
||||||
|
+ MT6351_LDO_ON_CTRL_BIT | MT6351_LDO_SRCLK_MODE_MASK,
|
||||||
|
+ MT6351_LDO_EN_BIT | MT6351_LDO_MODE_CTRL_BIT);
|
||||||
|
regmap_update_bits(cdev->pmic_regmap, MT6351_LDO_VRF12_CON0,
|
||||||
|
- MT6351_LDO_EN_BIT | MT6351_LDO_ON_CTRL_BIT,
|
||||||
|
- MT6351_LDO_EN_BIT);
|
||||||
|
+ MT6351_LDO_EN_BIT | MT6351_LDO_MODE_CTRL_BIT |
|
||||||
|
+ MT6351_LDO_ON_CTRL_BIT | MT6351_LDO_SRCLK_MODE_MASK,
|
||||||
|
+ MT6351_LDO_EN_BIT | MT6351_LDO_MODE_CTRL_BIT);
|
||||||
|
|
||||||
|
/* VSRAM_MD=1.10V (0x50), VMODEM=1.00V (0x40), then switch to HW VOSEL control */
|
||||||
|
regmap_update_bits(cdev->pmic_regmap, MT6351_BUCK_VSRAM_MD_CON5,
|
||||||
|
@@ -2805,7 +2813,7 @@
|
||||||
|
}
|
||||||
|
|
||||||
|
if (risr & CLDMA_BM_INT_DONE) {
|
||||||
|
- pm_wakeup_event(cdev->dev, 1000);
|
||||||
|
+ pm_wakeup_event(cdev->dev, 3000);
|
||||||
|
schedule_work(&cdev->rx_work);
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -2823,7 +2831,7 @@
|
||||||
|
writel(rch, cdev->ap_ccif0 + APCCIF_ACK);
|
||||||
|
}
|
||||||
|
if (rch & BIT(AP_MD_PEER_WAKEUP))
|
||||||
|
- pm_wakeup_event(cdev->dev, 1500);
|
||||||
|
+ pm_wakeup_event(cdev->dev, 3000);
|
||||||
|
if (rch & BIT(D2H_EXCEPTION_INIT)) {
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
|
@@ -3420,9 +3428,52 @@
|
||||||
|
cdev->mux_registered = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
-static void mt6797_ccci_power_off(struct mt6797_ccci_dev *cdev)
|
||||||
|
+static void mt6797_ccci_spm_md1_off(struct mt6797_ccci_dev *cdev)
|
||||||
|
{
|
||||||
|
u32 prot = 0, pwr1 = 0, pwr2 = 0;
|
||||||
|
+
|
||||||
|
+ if (!cdev->infracfg || !cdev->spm)
|
||||||
|
+ return;
|
||||||
|
+
|
||||||
|
+ regmap_write(cdev->spm, SPM_POWERON_CONFIG_EN, SPM_POWERON_CONFIG_MAGIC);
|
||||||
|
+ regmap_set_bits(cdev->infracfg, INFRA_TOPAXI_PROTECTEN, MD1_PROT_MASK);
|
||||||
|
+ (void)regmap_read_poll_timeout(cdev->infracfg, INFRA_TOPAXI_PROTECTSTA1,
|
||||||
|
+ prot, (prot & MD1_PROT_MASK) == MD1_PROT_MASK,
|
||||||
|
+ 10, 50000);
|
||||||
|
+ regmap_set_bits(cdev->spm, SPM_MD1_PWR_CON, MD1_SRAM_PDN_BIT);
|
||||||
|
+ regmap_set_bits(cdev->spm, SPM_MD1_PWR_CON, PWR_ISO_BIT);
|
||||||
|
+ regmap_set_bits(cdev->spm, SPM_MD1_PWR_CON, PWR_CLK_DIS_BIT);
|
||||||
|
+ regmap_clear_bits(cdev->spm, SPM_MD1_PWR_CON, PWR_RST_B_BIT);
|
||||||
|
+ regmap_clear_bits(cdev->spm, SPM_MD1_PWR_CON, PWR_ON_BIT);
|
||||||
|
+ regmap_clear_bits(cdev->spm, SPM_MD1_PWR_CON, PWR_ON_2ND_BIT);
|
||||||
|
+ (void)regmap_read_poll_timeout(cdev->spm, SPM_PWR_STATUS, pwr1,
|
||||||
|
+ (pwr1 & PWR_STATUS_MD1) == 0,
|
||||||
|
+ 10, 50000);
|
||||||
|
+ (void)regmap_read_poll_timeout(cdev->spm, SPM_PWR_STATUS_2ND, pwr2,
|
||||||
|
+ (pwr2 & PWR_STATUS_MD1) == 0,
|
||||||
|
+ 10, 50000);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static void mt6797_ccci_gate_idle_clocks(struct mt6797_ccci_dev *cdev)
|
||||||
|
+{
|
||||||
|
+ if (cdev->spm) {
|
||||||
|
+ regmap_set_bits(cdev->spm, SPM_C2K_SPM_CTRL, C2K_LTE_LS_ISO_BIT);
|
||||||
|
+ regmap_set_bits(cdev->spm, SPM_MD_EXT_BUCK_ISO, MD1_EXT_BUCK_ISO_BIT);
|
||||||
|
+ regmap_update_bits(cdev->spm, SPM_MDBSI_CON, 0x7U, 0x2U);
|
||||||
|
+ }
|
||||||
|
+ if (cdev->infracfg) {
|
||||||
|
+ regmap_write(cdev->infracfg, INFRA_CG0_SET, INFRA_CG0_MD_MASK);
|
||||||
|
+ regmap_write(cdev->infracfg, INFRA_CG1_SET, INFRA_CG1_MD_MASK);
|
||||||
|
+ regmap_update_bits(cdev->infracfg, INFRA_AO_MD_SRCCLKENA, 0xff, 0x00);
|
||||||
|
+ }
|
||||||
|
+ if (cdev->apmixed) {
|
||||||
|
+ md_clr_bits32(cdev->apmixed, MDPLL1_CON0, BIT(0));
|
||||||
|
+ md_clr_bits32(cdev->apmixed, AP_PLL_CON0, BIT(1));
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+static void mt6797_ccci_power_off(struct mt6797_ccci_dev *cdev)
|
||||||
|
+{
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
|
spin_lock_irqsave(&cdev->smu_lock, flags);
|
||||||
|
@@ -3435,30 +3486,9 @@
|
||||||
|
cancel_work_sync(&cdev->rx_work);
|
||||||
|
mt6797_ccci_free_rings(cdev);
|
||||||
|
|
||||||
|
- if (cdev->infracfg && cdev->spm && cdev->active_stage >= 1) {
|
||||||
|
- regmap_write(cdev->spm, SPM_POWERON_CONFIG_EN, SPM_POWERON_CONFIG_MAGIC);
|
||||||
|
- regmap_set_bits(cdev->infracfg, INFRA_TOPAXI_PROTECTEN, MD1_PROT_MASK);
|
||||||
|
- (void)regmap_read_poll_timeout(cdev->infracfg, INFRA_TOPAXI_PROTECTSTA1,
|
||||||
|
- prot, (prot & MD1_PROT_MASK) == MD1_PROT_MASK,
|
||||||
|
- 10, 50000);
|
||||||
|
- regmap_set_bits(cdev->spm, SPM_MD1_PWR_CON, MD1_SRAM_PDN_BIT);
|
||||||
|
- regmap_set_bits(cdev->spm, SPM_MD1_PWR_CON, PWR_ISO_BIT);
|
||||||
|
- regmap_set_bits(cdev->spm, SPM_MD1_PWR_CON, PWR_CLK_DIS_BIT);
|
||||||
|
- regmap_clear_bits(cdev->spm, SPM_MD1_PWR_CON, PWR_RST_B_BIT);
|
||||||
|
- regmap_clear_bits(cdev->spm, SPM_MD1_PWR_CON, PWR_ON_BIT);
|
||||||
|
- regmap_clear_bits(cdev->spm, SPM_MD1_PWR_CON, PWR_ON_2ND_BIT);
|
||||||
|
- (void)regmap_read_poll_timeout(cdev->spm, SPM_PWR_STATUS, pwr1,
|
||||||
|
- (pwr1 & PWR_STATUS_MD1) == 0,
|
||||||
|
- 10, 50000);
|
||||||
|
- (void)regmap_read_poll_timeout(cdev->spm, SPM_PWR_STATUS_2ND, pwr2,
|
||||||
|
- (pwr2 & PWR_STATUS_MD1) == 0,
|
||||||
|
- 10, 50000);
|
||||||
|
- regmap_set_bits(cdev->spm, SPM_MD_EXT_BUCK_ISO, MD1_EXT_BUCK_ISO_BIT);
|
||||||
|
- }
|
||||||
|
- if (cdev->spm)
|
||||||
|
- regmap_update_bits(cdev->spm, SPM_MDBSI_CON, 0x7U, 0x2U);
|
||||||
|
- if (cdev->infracfg)
|
||||||
|
- regmap_update_bits(cdev->infracfg, INFRA_AO_MD_SRCCLKENA, 0xff, 0x00);
|
||||||
|
+ if (cdev->active_stage >= 1)
|
||||||
|
+ mt6797_ccci_spm_md1_off(cdev);
|
||||||
|
+ mt6797_ccci_gate_idle_clocks(cdev);
|
||||||
|
mt6797_ccci_pmic_md1(cdev, false);
|
||||||
|
cdev->last_boot_stats0 = 0;
|
||||||
|
cdev->last_boot_stats1 = 0;
|
||||||
|
@@ -3674,9 +3704,15 @@
|
||||||
|
mutex_lock(&cdev->state_lock);
|
||||||
|
mt6797_ccci_apply_stage(cdev, clamp_t(u32, stage, 0, 3));
|
||||||
|
mutex_unlock(&cdev->state_lock);
|
||||||
|
- } else if (cdev->infracfg) {
|
||||||
|
- regmap_update_bits(cdev->infracfg, INFRA_AO_MD_SRCCLKENA,
|
||||||
|
- 0xff, 0x00);
|
||||||
|
+ } else {
|
||||||
|
+ u32 pwr_con = 0;
|
||||||
|
+
|
||||||
|
+ if (cdev->spm &&
|
||||||
|
+ regmap_read(cdev->spm, SPM_MD1_PWR_CON, &pwr_con) == 0 &&
|
||||||
|
+ (pwr_con & 0x1f) != 0x12)
|
||||||
|
+ mt6797_ccci_spm_md1_off(cdev);
|
||||||
|
+ mt6797_ccci_gate_idle_clocks(cdev);
|
||||||
|
+ mt6797_ccci_pmic_md1(cdev, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_info(&pdev->dev,
|
||||||
|
@@ -3723,11 +3759,42 @@
|
||||||
|
static int mt6797_ccci_suspend(struct device *dev)
|
||||||
|
{
|
||||||
|
struct mt6797_ccci_dev *cdev = dev_get_drvdata(dev);
|
||||||
|
+ int q;
|
||||||
|
+
|
||||||
|
+ if (cdev->active_stage >= 2 && cdev->cldma_started &&
|
||||||
|
+ cdev->md_state != MT6797_MD_STATE_GATED &&
|
||||||
|
+ cdev->md_state != MT6797_MD_STATE_RESET) {
|
||||||
|
+ if (work_busy(&cdev->rx_work)) {
|
||||||
|
+ pm_wakeup_event(cdev->dev, 3000);
|
||||||
|
+ return -EBUSY;
|
||||||
|
+ }
|
||||||
|
+ for (q = 0; q < MT6797_CCCI_NUM_QUEUES; q++) {
|
||||||
|
+ struct mt6797_cldma_ring *rx;
|
||||||
|
+ unsigned long flags;
|
||||||
|
+ bool pending;
|
||||||
|
+
|
||||||
|
+ if (!(MT6797_CCCI_ACTIVE_QMASK & BIT(q)))
|
||||||
|
+ continue;
|
||||||
|
+ rx = &cdev->rx_rings[q];
|
||||||
|
+ spin_lock_irqsave(&rx->lock, flags);
|
||||||
|
+ rmb();
|
||||||
|
+ pending = rx->rgpd &&
|
||||||
|
+ !(rx->rgpd[rx->head].gpd_flags & GPD_FLAGS_HWO);
|
||||||
|
+ spin_unlock_irqrestore(&rx->lock, flags);
|
||||||
|
+ if (pending) {
|
||||||
|
+ schedule_work(&cdev->rx_work);
|
||||||
|
+ pm_wakeup_event(cdev->dev, 3000);
|
||||||
|
+ return -EBUSY;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
|
||||||
|
if (device_may_wakeup(dev) && cdev->irq_ccif_on && cdev->irq_ccif > 0)
|
||||||
|
enable_irq_wake(cdev->irq_ccif);
|
||||||
|
if (device_may_wakeup(dev) && cdev->irq_cldma_on && cdev->irq_cldma > 0)
|
||||||
|
enable_irq_wake(cdev->irq_cldma);
|
||||||
|
+ if (device_may_wakeup(dev) && cdev->irq_wdt_on && cdev->irq_md_wdt > 0)
|
||||||
|
+ enable_irq_wake(cdev->irq_md_wdt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -3741,6 +3808,8 @@
|
||||||
|
disable_irq_wake(cdev->irq_ccif);
|
||||||
|
if (device_may_wakeup(dev) && cdev->irq_cldma_on && cdev->irq_cldma > 0)
|
||||||
|
disable_irq_wake(cdev->irq_cldma);
|
||||||
|
+ if (device_may_wakeup(dev) && cdev->irq_wdt_on && cdev->irq_md_wdt > 0)
|
||||||
|
+ disable_irq_wake(cdev->irq_md_wdt);
|
||||||
|
|
||||||
|
if (cdev->active_stage >= 2 && cdev->cldma_started &&
|
||||||
|
cdev->md_state != MT6797_MD_STATE_GATED &&
|
||||||
|
@@ -3762,16 +3831,31 @@
|
||||||
|
writel(bk, cdev->cldma_ap_pdn + CLDMA_AP_UL_START_ADDR(q));
|
||||||
|
writel(bk, cdev->cldma_ap_ao + CLDMA_AP_UL_START_ADDR_BK(q));
|
||||||
|
}
|
||||||
|
+ for (q = 0; q < MT6797_CCCI_NUM_QUEUES; q++) {
|
||||||
|
+ u32 so_cur = readl(cdev->cldma_ap_ao + CLDMA_AP_SO_CURRENT_ADDR(q));
|
||||||
|
+
|
||||||
|
+ if (!so_cur)
|
||||||
|
+ so_cur = lower_32_bits(cdev->rx_rings[q].gpd_dma +
|
||||||
|
+ cdev->rx_rings[q].head *
|
||||||
|
+ sizeof(*cdev->rx_rings[q].rgpd));
|
||||||
|
+ writel(so_cur, cdev->cldma_ap_ao + CLDMA_AP_SO_START_ADDR(q));
|
||||||
|
+ }
|
||||||
|
wmb();
|
||||||
|
cdev->txq_started = false;
|
||||||
|
+ writel(MT6797_CCCI_ACTIVE_QMASK,
|
||||||
|
+ cdev->cldma_ap_pdn + CLDMA_AP_SO_START_CMD);
|
||||||
|
+ (void)readl(cdev->cldma_ap_pdn + CLDMA_AP_SO_START_CMD);
|
||||||
|
writel(CLDMA_BM_INT_DONE | CLDMA_BM_INT_ERROR,
|
||||||
|
cdev->cldma_ap_pdn + CLDMA_AP_L2TIMCR0);
|
||||||
|
+ writel(CLDMA_BM_INT_DONE | CLDMA_BM_INT_ERROR,
|
||||||
|
+ cdev->cldma_ap_ao + CLDMA_AP_L2RIMCR0);
|
||||||
|
writel(0xffffffff, cdev->cldma_ap_pdn + CLDMA_AP_L3TIMCR0);
|
||||||
|
writel(0xffffffff, cdev->cldma_ap_pdn + CLDMA_AP_L3TIMCR1);
|
||||||
|
writel(0xffffffff, cdev->cldma_ap_pdn + CLDMA_AP_L3RIMCR0);
|
||||||
|
writel(0xffffffff, cdev->cldma_ap_pdn + CLDMA_AP_L3RIMCR1);
|
||||||
|
spin_unlock_irqrestore(&cdev->cldma_lock, flags);
|
||||||
|
}
|
||||||
|
+ schedule_work(&cdev->rx_work);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
--- a/drivers/soc/mediatek/mt6797-spm-sleep.c 2026-11-28 08:07:33.573202661 +0000
|
||||||
|
+++ b/drivers/soc/mediatek/mt6797-spm-sleep.c 2026-11-28 08:09:01.264308509 +0000
|
||||||
|
@@ -182,6 +182,10 @@
|
||||||
|
|
||||||
|
/* Wake sources: PCM timer, EINT, and PCM watchdog safety wake */
|
||||||
|
#define S1_WAKE_SRC (BIT(0) | BIT(6) | WAKE_PCM_WDT)
|
||||||
|
+#define WAKE_CCIF0 BIT(8)
|
||||||
|
+#define WAKE_MD1_WDT BIT(25)
|
||||||
|
+#define WAKE_CLDMA BIT(26)
|
||||||
|
+#define S1_MD1_WAKE_SRC (WAKE_CCIF0 | WAKE_MD1_WDT | WAKE_CLDMA)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The vendor's MT6797 SODI wake sources (WAKE_SRC_FOR_SODI, D4): PCM timer,
|
||||||
|
@@ -493,6 +497,14 @@
|
||||||
|
module_param(pmic_modes, bool, 0644);
|
||||||
|
MODULE_PARM_DESC(pmic_modes, "Set the static PMIC sleep modes for each suspend");
|
||||||
|
|
||||||
|
+static bool allow_md1 = true;
|
||||||
|
+module_param(allow_md1, bool, 0644);
|
||||||
|
+MODULE_PARM_DESC(allow_md1, "Allow mem suspend while MD1 cellular modem is powered");
|
||||||
|
+
|
||||||
|
+static unsigned int last_wake_r12;
|
||||||
|
+module_param(last_wake_r12, uint, 0444);
|
||||||
|
+MODULE_PARM_DESC(last_wake_r12, "SPM wake source bitmask (r12) from the last mem suspend");
|
||||||
|
+
|
||||||
|
static bool gic_mask = true;
|
||||||
|
module_param(gic_mask, bool, 0644);
|
||||||
|
MODULE_PARM_DESC(gic_mask, "Disable every SPI but the SPM's at the GIC while CPU0 waits");
|
||||||
|
@@ -655,7 +667,8 @@
|
||||||
|
s.slots[4] = (struct spm_slot){ MT6351_VCORE_CON5, 0x36 };
|
||||||
|
s.slots[5] = (struct spm_slot){ MT6351_VCORE_CON5, 0x33 };
|
||||||
|
s.slots[6] = (struct spm_slot){ MT6351_VCORE_CON5, 0x30 };
|
||||||
|
- s.slots[7] = (struct spm_slot){ MT6351_VCORE_CON6, 0x00 };
|
||||||
|
+ /* Clamp VCORE sleep slot to 0.700 V (matching P3) so pmic_modes=1 keeps CPU0 in WFI */
|
||||||
|
+ s.slots[7] = (struct spm_slot){ MT6351_VCORE_CON6, 0x10 };
|
||||||
|
s.slots[8] = (struct spm_slot){ MT6351_SMPS_ANA_CON9, ana9 | 0x300 };
|
||||||
|
s.slots[9] = (struct spm_slot){ MT6351_VCORE_CON5, 0x1c };
|
||||||
|
s.slots[10] = (struct spm_slot){ vsram, 0x40 };
|
||||||
|
@@ -921,7 +934,9 @@
|
||||||
|
if ((spm_rd(PCM_FSM_STA) & 0x7fffff) != PCM_FSM_STA_DEF ||
|
||||||
|
spm_rd(PCM_REG1_DATA) == 1)
|
||||||
|
return -EBUSY;
|
||||||
|
- if (!spm_off(MD1_PWR_CON) || !spm_off(C2K_PWR_CON))
|
||||||
|
+ if (!spm_off(C2K_PWR_CON))
|
||||||
|
+ return -EBUSY;
|
||||||
|
+ if (!spm_off(MD1_PWR_CON) && !(sc->slots && allow_md1))
|
||||||
|
return -EBUSY;
|
||||||
|
|
||||||
|
/*
|
||||||
|
@@ -1360,11 +1375,15 @@
|
||||||
|
{
|
||||||
|
int ret, pass;
|
||||||
|
|
||||||
|
+ s.entered = false;
|
||||||
|
if (state != PM_SUSPEND_MEM)
|
||||||
|
return -EINVAL;
|
||||||
|
if (!spm_off(CONN_PWR_CON))
|
||||||
|
return -EBUSY;
|
||||||
|
s.sleep.ticks = timer_sec * 32768;
|
||||||
|
+ s.sleep.wake_src = S1_WAKE_SRC;
|
||||||
|
+ if (allow_md1 && !spm_off(MD1_PWR_CON))
|
||||||
|
+ s.sleep.wake_src |= S1_MD1_WAKE_SRC;
|
||||||
|
for (pass = 0; pass < 6; pass++) {
|
||||||
|
ret = spm_run(&s.sleep);
|
||||||
|
if (ret || !s.entered || !s.wake.returned || s.wake.backstop)
|
||||||
|
@@ -1407,6 +1426,7 @@
|
||||||
|
disable_irq_wake(s.irq);
|
||||||
|
disable_irq(s.irq);
|
||||||
|
spm_pmic_finish();
|
||||||
|
+ last_wake_r12 = s.entered ? s.wake.r12 : 0;
|
||||||
|
if (!s.entered || !s.wake.returned || s.wake.backstop ||
|
||||||
|
s.wake.r12 != BIT(0))
|
||||||
|
spm_log_wake("wake");
|
||||||
@@ -11,3 +11,4 @@
|
|||||||
0011-gemini-lid-sync-filter-and-debounce.patch
|
0011-gemini-lid-sync-filter-and-debounce.patch
|
||||||
0012-gemini-lid-wake-and-fg-taper-fix.patch
|
0012-gemini-lid-wake-and-fg-taper-fix.patch
|
||||||
0013-gemini-pmic-wake-and-spm-safety.patch
|
0013-gemini-pmic-wake-and-spm-safety.patch
|
||||||
|
0014-gemini-deep-sleep-power-drainers.patch
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -673,9 +673,12 @@ def main():
|
|||||||
os.path.join(overlay_dir, "etc", "modprobe.d", "geminux.conf"): (
|
os.path.join(overlay_dir, "etc", "modprobe.d", "geminux.conf"): (
|
||||||
"blacklist stk3310",
|
"blacklist stk3310",
|
||||||
"softdep cpufreq_dt pre: clk_mt6797_mcusys",
|
"softdep cpufreq_dt pre: clk_mt6797_mcusys",
|
||||||
"options mt6797_spm_sleep sodi_idle=0 pmic_modes=0 timer_sec=600",
|
"options mt6797_spm_sleep sodi_idle=0 pmic_modes=1 allow_md1=1 timer_sec=600",
|
||||||
"options mt6797_wlan power_save=0",
|
"options mt6797_wlan power_save=0",
|
||||||
),
|
),
|
||||||
|
os.path.join(overlay_dir, "etc", "init.d", "geminux-powerd"): (
|
||||||
|
"after modules geminux-hwinit geminux-ccci",
|
||||||
|
),
|
||||||
os.path.join(overlay_dir, "etc", "X11", "xorg.conf.d", "10-geminux-gpu.conf"): (
|
os.path.join(overlay_dir, "etc", "X11", "xorg.conf.d", "10-geminux-gpu.conf"): (
|
||||||
'Option "TearFree" "true"',
|
'Option "TearFree" "true"',
|
||||||
'Option "ShadowFB" "true"',
|
'Option "ShadowFB" "true"',
|
||||||
@@ -684,6 +687,7 @@ def main():
|
|||||||
"0009-mt6797-wlan-drop-free-stability.patch",
|
"0009-mt6797-wlan-drop-free-stability.patch",
|
||||||
"0012-gemini-lid-wake-and-fg-taper-fix.patch",
|
"0012-gemini-lid-wake-and-fg-taper-fix.patch",
|
||||||
"0013-gemini-pmic-wake-and-spm-safety.patch",
|
"0013-gemini-pmic-wake-and-spm-safety.patch",
|
||||||
|
"0014-gemini-deep-sleep-power-drainers.patch",
|
||||||
),
|
),
|
||||||
os.path.join(overlay_dir, "etc", "profile.d", "10-geminux-env.sh"): (
|
os.path.join(overlay_dir, "etc", "profile.d", "10-geminux-env.sh"): (
|
||||||
"export NO_AT_BRIDGE=1",
|
"export NO_AT_BRIDGE=1",
|
||||||
@@ -730,18 +734,33 @@ def main():
|
|||||||
powerd_dpms_src = handle.read()
|
powerd_dpms_src = handle.read()
|
||||||
for needle in (
|
for needle in (
|
||||||
"wake_x11_display_dpms",
|
"wake_x11_display_dpms",
|
||||||
|
"blank_x11_display_dpms",
|
||||||
"DPMSForceLevel",
|
"DPMSForceLevel",
|
||||||
"DPMSModeOn",
|
"DPMSModeOn",
|
||||||
|
"DPMSModeOff",
|
||||||
|
"bl_power",
|
||||||
|
"standby_retry_ms",
|
||||||
"XResetScreenSaver",
|
"XResetScreenSaver",
|
||||||
"poll(&pf, 1, 1800)",
|
"poll(&pf, 1, 1800)",
|
||||||
):
|
):
|
||||||
if needle not in powerd_dpms_src:
|
if needle not in powerd_dpms_src:
|
||||||
raise AssertionError(f"geminux-powerd.c missing expected DPMS/lock sync token: {needle}")
|
raise AssertionError(f"geminux-powerd.c missing expected DPMS/lock sync token: {needle}")
|
||||||
|
pc_start = powerd_dpms_src.find("static void prepare_consys_for_suspend")
|
||||||
|
pc_end = powerd_dpms_src.find("\nstatic ", pc_start + 1)
|
||||||
|
pc_src = powerd_dpms_src[pc_start:pc_end]
|
||||||
|
if "reap_radio_worker(ctx, true)" not in pc_src:
|
||||||
|
raise AssertionError("prepare_consys_for_suspend must reap radio_worker_pid before suspend")
|
||||||
tb_start = powerd_dpms_src.find("static void toggle_backlight")
|
tb_start = powerd_dpms_src.find("static void toggle_backlight")
|
||||||
tb_end = powerd_dpms_src.find("\nstatic ", tb_start + 1)
|
tb_end = powerd_dpms_src.find("\nstatic ", tb_start + 1)
|
||||||
tb_src = powerd_dpms_src[tb_start:tb_end]
|
tb_src = powerd_dpms_src[tb_start:tb_end]
|
||||||
if "wake_x11_display_dpms()" not in tb_src:
|
if "wake_x11_display_dpms()" not in tb_src or "blank_x11_display_dpms()" not in tb_src:
|
||||||
raise AssertionError("toggle_backlight must invoke wake_x11_display_dpms() when waking display")
|
raise AssertionError("toggle_backlight must invoke DPMS wake/blank helpers")
|
||||||
|
|
||||||
|
with open(os.path.join(DAEMON_DIR, "geminux-modem-ctl.c"), "r", encoding="utf-8") as handle:
|
||||||
|
modem_ctl_src = handle.read()
|
||||||
|
for needle in ("epoll_wait(ctx.epfd, events, 8, -1)", "inotify_init1"):
|
||||||
|
if needle not in modem_ctl_src:
|
||||||
|
raise AssertionError(f"geminux-modem-ctl.c missing zero-poll token: {needle}")
|
||||||
|
|
||||||
lock_path = os.path.join(APPS_DIR, "geminux-lock.c")
|
lock_path = os.path.join(APPS_DIR, "geminux-lock.c")
|
||||||
with open(lock_path, "r", encoding="utf-8") as handle:
|
with open(lock_path, "r", encoding="utf-8") as handle:
|
||||||
@@ -766,6 +785,38 @@ def main():
|
|||||||
if "XPeekEvent(" not in gemui_src:
|
if "XPeekEvent(" not in gemui_src:
|
||||||
raise AssertionError("gemui.c must coalesce consecutive MotionNotify events with XPeekEvent")
|
raise AssertionError("gemui.c must coalesce consecutive MotionNotify events with XPeekEvent")
|
||||||
|
|
||||||
|
patch_0014_path = os.path.join(
|
||||||
|
BASE_DIR, "patches", "kernel", "0014-gemini-deep-sleep-power-drainers.patch"
|
||||||
|
)
|
||||||
|
with open(patch_0014_path, "r", encoding="utf-8") as handle:
|
||||||
|
p14_src = handle.read()
|
||||||
|
for needle in (
|
||||||
|
"allow_md1",
|
||||||
|
"last_wake_r12",
|
||||||
|
"WAKE_CLDMA",
|
||||||
|
"WAKE_CCIF0",
|
||||||
|
"WAKE_MD1_WDT",
|
||||||
|
"CLDMA_AP_SO_START_CMD",
|
||||||
|
"MT6351_LDO_MODE_CTRL_BIT",
|
||||||
|
):
|
||||||
|
if needle not in p14_src:
|
||||||
|
raise AssertionError(f"0014 patch missing expected MD1 mem-sleep token: {needle}")
|
||||||
|
|
||||||
|
for needle in (
|
||||||
|
"read_spm_allow_md1",
|
||||||
|
"read_spm_last_wake_r12",
|
||||||
|
"modem_wake ? 3500 : 300",
|
||||||
|
"arm_timer_ms(ctx->tmr_fd, 1000)",
|
||||||
|
):
|
||||||
|
if needle not in powerd_dpms_src:
|
||||||
|
raise AssertionError(f"geminux-powerd.c missing expected MD1 mem-sleep token: {needle}")
|
||||||
|
|
||||||
|
with open(os.path.join(DAEMON_DIR, "geminux-power-audit.c"), "r", encoding="utf-8") as handle:
|
||||||
|
audit_src = handle.read()
|
||||||
|
for needle in ("spm_allow_md1", "spm_last_wake_r12"):
|
||||||
|
if needle not in audit_src:
|
||||||
|
raise AssertionError(f"geminux-power-audit.c missing expected telemetry token: {needle}")
|
||||||
|
|
||||||
print("[PASS] Zero-poll daemon loops, power/lid policy, and touch gestures verified")
|
print("[PASS] Zero-poll daemon loops, power/lid policy, and touch gestures verified")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
#include <sys/inotify.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/signalfd.h>
|
#include <sys/signalfd.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/timerfd.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
@@ -38,6 +40,10 @@ typedef struct {
|
|||||||
int srv_fd;
|
int srv_fd;
|
||||||
int at_fd;
|
int at_fd;
|
||||||
int dbus_fd;
|
int dbus_fd;
|
||||||
|
int ino_fd;
|
||||||
|
int ino_wd;
|
||||||
|
int retry_tmr_fd;
|
||||||
|
uint64_t dbus_retry_ms;
|
||||||
pid_t dbus_pid;
|
pid_t dbus_pid;
|
||||||
int dbus_event; /* 1=Voice.CallAdded, 2=Messaging.Added */
|
int dbus_event; /* 1=Voice.CallAdded, 2=Messaging.Added */
|
||||||
char dbus_line[512];
|
char dbus_line[512];
|
||||||
@@ -345,8 +351,22 @@ static void open_at_port(modem_ctx_t *ctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void arm_retry_timer(modem_ctx_t *ctx, uint64_t wait_ms) {
|
||||||
|
if (ctx->retry_tmr_fd < 0) return;
|
||||||
|
struct itimerspec its;
|
||||||
|
memset(&its, 0, sizeof(its));
|
||||||
|
if (wait_ms > 0) {
|
||||||
|
its.it_value.tv_sec = (time_t)(wait_ms / 1000ULL);
|
||||||
|
its.it_value.tv_nsec = (long)((wait_ms % 1000ULL) * 1000000ULL);
|
||||||
|
}
|
||||||
|
timerfd_settime(ctx->retry_tmr_fd, 0, &its, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static void start_dbus_monitor(modem_ctx_t *ctx) {
|
static void start_dbus_monitor(modem_ctx_t *ctx) {
|
||||||
if (ctx->dbus_fd >= 0 || access("/usr/bin/dbus-monitor", X_OK) != 0) return;
|
if (is_airplane_active() || ctx->dbus_fd >= 0 ||
|
||||||
|
access("/usr/bin/dbus-monitor", X_OK) != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int pfd[2];
|
int pfd[2];
|
||||||
if (pipe2(pfd, O_NONBLOCK | O_CLOEXEC) != 0) return;
|
if (pipe2(pfd, O_NONBLOCK | O_CLOEXEC) != 0) return;
|
||||||
|
|
||||||
@@ -379,6 +399,8 @@ static void start_dbus_monitor(modem_ctx_t *ctx) {
|
|||||||
ctx->dbus_pid = pid;
|
ctx->dbus_pid = pid;
|
||||||
ctx->dbus_event = 0;
|
ctx->dbus_event = 0;
|
||||||
ctx->dbus_len = 0;
|
ctx->dbus_len = 0;
|
||||||
|
ctx->dbus_retry_ms = 0;
|
||||||
|
arm_retry_timer(ctx, 0);
|
||||||
} else {
|
} else {
|
||||||
close(pfd[0]);
|
close(pfd[0]);
|
||||||
kill(pid, SIGTERM);
|
kill(pid, SIGTERM);
|
||||||
@@ -386,6 +408,19 @@ static void start_dbus_monitor(modem_ctx_t *ctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void schedule_dbus_retry(modem_ctx_t *ctx) {
|
||||||
|
if (is_airplane_active() || ctx->dbus_fd >= 0) {
|
||||||
|
ctx->dbus_retry_ms = 0;
|
||||||
|
arm_retry_timer(ctx, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ctx->dbus_retry_ms < 5000) ctx->dbus_retry_ms = 5000;
|
||||||
|
else if (ctx->dbus_retry_ms < 15000) ctx->dbus_retry_ms = 15000;
|
||||||
|
else if (ctx->dbus_retry_ms < 30000) ctx->dbus_retry_ms = 30000;
|
||||||
|
else ctx->dbus_retry_ms = 60000;
|
||||||
|
arm_retry_timer(ctx, ctx->dbus_retry_ms);
|
||||||
|
}
|
||||||
|
|
||||||
static void stop_dbus_monitor(modem_ctx_t *ctx) {
|
static void stop_dbus_monitor(modem_ctx_t *ctx) {
|
||||||
if (ctx->dbus_fd >= 0) {
|
if (ctx->dbus_fd >= 0) {
|
||||||
epoll_ctl(ctx->epfd, EPOLL_CTL_DEL, ctx->dbus_fd, NULL);
|
epoll_ctl(ctx->epfd, EPOLL_CTL_DEL, ctx->dbus_fd, NULL);
|
||||||
@@ -731,6 +766,9 @@ int main(void) {
|
|||||||
ctx.srv_fd = -1;
|
ctx.srv_fd = -1;
|
||||||
ctx.at_fd = -1;
|
ctx.at_fd = -1;
|
||||||
ctx.dbus_fd = -1;
|
ctx.dbus_fd = -1;
|
||||||
|
ctx.ino_fd = -1;
|
||||||
|
ctx.ino_wd = -1;
|
||||||
|
ctx.retry_tmr_fd = -1;
|
||||||
ctx.dbus_pid = -1;
|
ctx.dbus_pid = -1;
|
||||||
mkdir("/run/geminux", 0755);
|
mkdir("/run/geminux", 0755);
|
||||||
int lock_fd = open("/tmp/geminux-modem-ctl.lock", O_CREAT | O_RDWR | O_CLOEXEC, 0600);
|
int lock_fd = open("/tmp/geminux-modem-ctl.lock", O_CREAT | O_RDWR | O_CLOEXEC, 0600);
|
||||||
@@ -747,10 +785,16 @@ int main(void) {
|
|||||||
ctx.sig_fd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
|
ctx.sig_fd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
|
||||||
|
|
||||||
ctx.srv_fd = bind_modem_socket(&ctx);
|
ctx.srv_fd = bind_modem_socket(&ctx);
|
||||||
|
ctx.retry_tmr_fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
|
||||||
|
ctx.ino_fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
|
||||||
|
if (ctx.ino_fd >= 0) {
|
||||||
|
ctx.ino_wd = inotify_add_watch(ctx.ino_fd, "/run/geminux",
|
||||||
|
IN_CLOSE_WRITE | IN_MOVED_TO | IN_CREATE | IN_DELETE);
|
||||||
|
}
|
||||||
|
|
||||||
ctx.epfd = epoll_create1(EPOLL_CLOEXEC);
|
ctx.epfd = epoll_create1(EPOLL_CLOEXEC);
|
||||||
int fixed[2] = {ctx.sig_fd, ctx.srv_fd};
|
int fixed[4] = {ctx.sig_fd, ctx.srv_fd, ctx.ino_fd, ctx.retry_tmr_fd};
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (fixed[i] >= 0) {
|
if (fixed[i] >= 0) {
|
||||||
struct epoll_event ev = { .events = EPOLLIN, .data.fd = fixed[i] };
|
struct epoll_event ev = { .events = EPOLLIN, .data.fd = fixed[i] };
|
||||||
epoll_ctl(ctx.epfd, EPOLL_CTL_ADD, fixed[i], &ev);
|
epoll_ctl(ctx.epfd, EPOLL_CTL_ADD, fixed[i], &ev);
|
||||||
@@ -758,25 +802,55 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
open_at_port(&ctx);
|
open_at_port(&ctx);
|
||||||
start_dbus_monitor(&ctx);
|
start_dbus_monitor(&ctx);
|
||||||
|
schedule_dbus_retry(&ctx);
|
||||||
write_state(&ctx);
|
write_state(&ctx);
|
||||||
|
|
||||||
struct epoll_event events[8];
|
struct epoll_event events[8];
|
||||||
bool running = true;
|
bool running = true;
|
||||||
while (running) {
|
while (running) {
|
||||||
int n = epoll_wait(ctx.epfd, events, 8, 15000);
|
int n = epoll_wait(ctx.epfd, events, 8, -1);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (errno == EINTR) continue;
|
if (errno == EINTR) continue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (n == 0) {
|
|
||||||
write_state(&ctx);
|
|
||||||
if (ctx.dbus_fd < 0) start_dbus_monitor(&ctx);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
int fd = events[i].data.fd;
|
int fd = events[i].data.fd;
|
||||||
if (fd == ctx.sig_fd) {
|
if (fd == ctx.sig_fd) {
|
||||||
running = false;
|
running = false;
|
||||||
|
} else if (fd == ctx.ino_fd) {
|
||||||
|
char ibuf[1024] __attribute__((aligned(__alignof__(struct inotify_event))));
|
||||||
|
bool relevant = false;
|
||||||
|
ssize_t ir;
|
||||||
|
while ((ir = read(ctx.ino_fd, ibuf, sizeof(ibuf))) > 0) {
|
||||||
|
for (char *ptr = ibuf; ptr < ibuf + ir; ) {
|
||||||
|
const struct inotify_event *ev = (const struct inotify_event *)ptr;
|
||||||
|
if (ev->len > 0 &&
|
||||||
|
(strcmp(ev->name, "airplane-mode") == 0 ||
|
||||||
|
strcmp(ev->name, "ims-state") == 0)) {
|
||||||
|
relevant = true;
|
||||||
|
}
|
||||||
|
ptr += sizeof(*ev) + ev->len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (relevant) {
|
||||||
|
write_state(&ctx);
|
||||||
|
if (is_airplane_active()) {
|
||||||
|
stop_dbus_monitor(&ctx);
|
||||||
|
ctx.dbus_retry_ms = 0;
|
||||||
|
arm_retry_timer(&ctx, 0);
|
||||||
|
} else if (ctx.dbus_fd < 0) {
|
||||||
|
start_dbus_monitor(&ctx);
|
||||||
|
schedule_dbus_retry(&ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (fd == ctx.retry_tmr_fd) {
|
||||||
|
uint64_t exp = 0;
|
||||||
|
while (read(ctx.retry_tmr_fd, &exp, sizeof(exp)) > 0) {}
|
||||||
|
write_state(&ctx);
|
||||||
|
if (!is_airplane_active() && ctx.dbus_fd < 0) {
|
||||||
|
start_dbus_monitor(&ctx);
|
||||||
|
}
|
||||||
|
schedule_dbus_retry(&ctx);
|
||||||
} else if (fd == ctx.srv_fd) {
|
} else if (fd == ctx.srv_fd) {
|
||||||
if (events[i].events & (EPOLLERR | EPOLLHUP)) {
|
if (events[i].events & (EPOLLERR | EPOLLHUP)) {
|
||||||
epoll_ctl(ctx.epfd, EPOLL_CTL_DEL, ctx.srv_fd, NULL);
|
epoll_ctl(ctx.epfd, EPOLL_CTL_DEL, ctx.srv_fd, NULL);
|
||||||
@@ -834,6 +908,7 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
if (dead || (events[i].events & (EPOLLHUP | EPOLLERR))) {
|
if (dead || (events[i].events & (EPOLLHUP | EPOLLERR))) {
|
||||||
stop_dbus_monitor(&ctx);
|
stop_dbus_monitor(&ctx);
|
||||||
|
schedule_dbus_retry(&ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -841,6 +916,8 @@ int main(void) {
|
|||||||
|
|
||||||
stop_hostless_speech(&ctx);
|
stop_hostless_speech(&ctx);
|
||||||
stop_dbus_monitor(&ctx);
|
stop_dbus_monitor(&ctx);
|
||||||
|
if (ctx.retry_tmr_fd >= 0) close(ctx.retry_tmr_fd);
|
||||||
|
if (ctx.ino_fd >= 0) close(ctx.ino_fd);
|
||||||
if (ctx.sock_path[0]) unlink(ctx.sock_path);
|
if (ctx.sock_path[0]) unlink(ctx.sock_path);
|
||||||
close(ctx.epfd);
|
close(ctx.epfd);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
static int read_str(const char *path, char *buf, size_t sz) {
|
static int read_str(const char *path, char *buf, size_t sz) {
|
||||||
FILE *f = fopen(path, "r");
|
FILE *f = fopen(path, "r");
|
||||||
@@ -18,6 +21,44 @@ static int read_str(const char *path, char *buf, size_t sz) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void query_powerd_status(char *buf, size_t sz) {
|
||||||
|
snprintf(buf, sz, "unavailable");
|
||||||
|
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
if (fd < 0) return;
|
||||||
|
struct sockaddr_un addr;
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
addr.sun_family = AF_UNIX;
|
||||||
|
snprintf(addr.sun_path, sizeof(addr.sun_path), "/run/geminux/powerd.sock");
|
||||||
|
if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0) {
|
||||||
|
const char *req = "status\n";
|
||||||
|
if (write(fd, req, strlen(req)) > 0) {
|
||||||
|
shutdown(fd, SHUT_WR);
|
||||||
|
char tmp[256] = {0};
|
||||||
|
ssize_t r = read(fd, tmp, sizeof(tmp) - 1);
|
||||||
|
if (r > 0) {
|
||||||
|
while (r > 0 && (tmp[r - 1] == '\n' || tmp[r - 1] == '\r')) tmp[--r] = '\0';
|
||||||
|
snprintf(buf, sz, "%s", tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void json_escape(const char *in, char *out, size_t out_sz) {
|
||||||
|
size_t j = 0;
|
||||||
|
for (size_t i = 0; in[i] && j + 2 < out_sz; i++) {
|
||||||
|
unsigned char ch = (unsigned char)in[i];
|
||||||
|
if (ch == '"' || ch == '\\') {
|
||||||
|
if (j + 3 >= out_sz) break;
|
||||||
|
out[j++] = '\\';
|
||||||
|
out[j++] = (char)ch;
|
||||||
|
} else if (ch >= 0x20) {
|
||||||
|
out[j++] = (char)ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out[j] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
bool json = (argc > 1 && strcmp(argv[1], "--json") == 0);
|
bool json = (argc > 1 && strcmp(argv[1], "--json") == 0);
|
||||||
|
|
||||||
@@ -27,6 +68,66 @@ int main(int argc, char **argv) {
|
|||||||
read_str("/sys/block/zram0/comp_algorithm", zram_algo, sizeof(zram_algo));
|
read_str("/sys/block/zram0/comp_algorithm", zram_algo, sizeof(zram_algo));
|
||||||
read_str("/run/geminux/power-profile", profile, sizeof(profile));
|
read_str("/run/geminux/power-profile", profile, sizeof(profile));
|
||||||
|
|
||||||
|
char air_raw[16] = "";
|
||||||
|
const char *airplane_mode = "unknown";
|
||||||
|
if (read_str("/run/geminux/airplane-mode", air_raw, sizeof(air_raw)) == 0 && air_raw[0]) {
|
||||||
|
airplane_mode = (atoi(air_raw) != 0) ? "on" : "off";
|
||||||
|
}
|
||||||
|
|
||||||
|
char md1_stage[32] = "absent";
|
||||||
|
read_str("/sys/class/mt6797_ccci/md1/stage", md1_stage, sizeof(md1_stage));
|
||||||
|
|
||||||
|
const char *consys_loaded =
|
||||||
|
(access("/sys/module/mt6797_consys", F_OK) == 0) ? "loaded" : "unloaded";
|
||||||
|
|
||||||
|
char spm_pmic_modes[16] = "unknown", spm_allow_md1[16] = "unknown";
|
||||||
|
char spm_last_wake_r12[32] = "0";
|
||||||
|
read_str("/sys/module/mt6797_spm_sleep/parameters/pmic_modes",
|
||||||
|
spm_pmic_modes, sizeof(spm_pmic_modes));
|
||||||
|
read_str("/sys/module/mt6797_spm_sleep/parameters/allow_md1",
|
||||||
|
spm_allow_md1, sizeof(spm_allow_md1));
|
||||||
|
if (read_str("/sys/module/mt6797_spm_sleep/parameters/last_wake_r12",
|
||||||
|
spm_last_wake_r12, sizeof(spm_last_wake_r12)) != 0 ||
|
||||||
|
!spm_last_wake_r12[0]) {
|
||||||
|
snprintf(spm_last_wake_r12, sizeof(spm_last_wake_r12), "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
char gpu_rail_suspends[32] = "unknown";
|
||||||
|
read_str("/sys/module/panfrost/parameters/mt6797_rail_suspends",
|
||||||
|
gpu_rail_suspends, sizeof(gpu_rail_suspends));
|
||||||
|
|
||||||
|
char suspend_ok[32] = "0", suspend_fail[32] = "0", last_failed_dev[64] = "none";
|
||||||
|
read_str("/sys/power/suspend_stats/success", suspend_ok, sizeof(suspend_ok));
|
||||||
|
read_str("/sys/power/suspend_stats/fail", suspend_fail, sizeof(suspend_fail));
|
||||||
|
if (read_str("/sys/power/suspend_stats/last_failed_dev",
|
||||||
|
last_failed_dev, sizeof(last_failed_dev)) != 0 ||
|
||||||
|
!last_failed_dev[0]) {
|
||||||
|
snprintf(last_failed_dev, sizeof(last_failed_dev), "none");
|
||||||
|
}
|
||||||
|
|
||||||
|
char vgpu_state[32] = "absent", vgpu_uv[32] = "unknown";
|
||||||
|
DIR *rd = opendir("/sys/class/regulator");
|
||||||
|
if (rd) {
|
||||||
|
struct dirent *de;
|
||||||
|
while ((de = readdir(rd)) != NULL) {
|
||||||
|
if (de->d_name[0] == '.') continue;
|
||||||
|
char p[320], name[64] = {0};
|
||||||
|
snprintf(p, sizeof(p), "/sys/class/regulator/%s/name", de->d_name);
|
||||||
|
if (read_str(p, name, sizeof(name)) == 0 &&
|
||||||
|
(strcmp(name, "vgpu") == 0 || strstr(name, "rt5735") != NULL)) {
|
||||||
|
snprintf(p, sizeof(p), "/sys/class/regulator/%s/state", de->d_name);
|
||||||
|
read_str(p, vgpu_state, sizeof(vgpu_state));
|
||||||
|
snprintf(p, sizeof(p), "/sys/class/regulator/%s/microvolts", de->d_name);
|
||||||
|
read_str(p, vgpu_uv, sizeof(vgpu_uv));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(rd);
|
||||||
|
}
|
||||||
|
|
||||||
|
char powerd_status[256];
|
||||||
|
query_powerd_status(powerd_status, sizeof(powerd_status));
|
||||||
|
|
||||||
char bat_cap[32] = "?", bat_status[32] = "Unknown", bat_uv[32] = "?", bat_ua[32] = "?";
|
char bat_cap[32] = "?", bat_status[32] = "Unknown", bat_uv[32] = "?", bat_ua[32] = "?";
|
||||||
DIR *d = opendir("/sys/class/power_supply");
|
DIR *d = opendir("/sys/class/power_supply");
|
||||||
if (d) {
|
if (d) {
|
||||||
@@ -87,25 +188,45 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
|
char pwr_esc[384], dev_esc[128];
|
||||||
|
json_escape(powerd_status, pwr_esc, sizeof(pwr_esc));
|
||||||
|
json_escape(last_failed_dev, dev_esc, sizeof(dev_esc));
|
||||||
printf("{\"profile\":\"%s\",\"battery_pct\":\"%s\",\"battery_status\":\"%s\","
|
printf("{\"profile\":\"%s\",\"battery_pct\":\"%s\",\"battery_status\":\"%s\","
|
||||||
"\"voltage_uv\":\"%s\",\"current_ua\":\"%s\",\"online_cpus\":%d,"
|
"\"voltage_uv\":\"%s\",\"current_ua\":\"%s\",\"online_cpus\":%d,"
|
||||||
"\"a72_online\":%d,\"governor\":\"%s\",\"policy0_max_khz\":\"%s\","
|
"\"a72_online\":%d,\"governor\":\"%s\",\"policy0_max_khz\":\"%s\","
|
||||||
"\"policy4_max_khz\":\"%s\",\"bt_rfkill_soft\":\"%s\","
|
"\"policy4_max_khz\":\"%s\",\"bt_rfkill_soft\":\"%s\","
|
||||||
"\"zram_algo\":\"%s\",\"mem_sleep\":\"%s\"}\n",
|
"\"zram_algo\":\"%s\",\"mem_sleep\":\"%s\","
|
||||||
|
"\"airplane_mode\":\"%s\",\"md1_stage\":\"%s\",\"consys\":\"%s\","
|
||||||
|
"\"spm_pmic_modes\":\"%s\",\"spm_allow_md1\":\"%s\","
|
||||||
|
"\"spm_last_wake_r12\":\"%s\",\"gpu_rail_suspends\":\"%s\","
|
||||||
|
"\"vgpu_state\":\"%s\",\"vgpu_uv\":\"%s\","
|
||||||
|
"\"suspend_success\":\"%s\",\"suspend_fail\":\"%s\","
|
||||||
|
"\"last_failed_dev\":\"%s\",\"powerd_status\":\"%s\"}\n",
|
||||||
profile, bat_cap, bat_status, bat_uv, bat_ua, online_cpus, a72_online,
|
profile, bat_cap, bat_status, bat_uv, bat_ua, online_cpus, a72_online,
|
||||||
gov0, max0, max4, bt_state, zram_algo, mem_sleep);
|
gov0, max0, max4, bt_state, zram_algo, mem_sleep,
|
||||||
|
airplane_mode, md1_stage, consys_loaded, spm_pmic_modes,
|
||||||
|
spm_allow_md1, spm_last_wake_r12, gpu_rail_suspends, vgpu_state,
|
||||||
|
vgpu_uv, suspend_ok, suspend_fail, dev_esc, pwr_esc);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Geminux Power & Efficiency Audit\n");
|
printf("Geminux Power & Efficiency Audit\n");
|
||||||
printf("----------------------------------------\n");
|
printf("----------------------------------------\n");
|
||||||
printf("Power Profile : %s\n", profile);
|
printf("Power Profile : %s\n", profile);
|
||||||
|
printf("Airplane Mode : %s (MD1 stage=%s, CONSYS=%s)\n",
|
||||||
|
airplane_mode, md1_stage, consys_loaded);
|
||||||
printf("Battery Status : %s%% (%s, V=%s uV, I=%s uA)\n", bat_cap, bat_status, bat_uv, bat_ua);
|
printf("Battery Status : %s%% (%s, V=%s uV, I=%s uA)\n", bat_cap, bat_status, bat_uv, bat_ua);
|
||||||
printf("CPUs Online : %d total (%d A72 big cores online)\n", online_cpus, a72_online);
|
printf("CPUs Online : %d total (%d A72 big cores online)\n", online_cpus, a72_online);
|
||||||
printf("CPUfreq Governor : %s\n", gov0);
|
printf("CPUfreq Governor : %s\n", gov0);
|
||||||
printf("CPUfreq Caps : policy0=%s kHz, policy4=%s kHz\n", max0, max4);
|
printf("CPUfreq Caps : policy0=%s kHz, policy4=%s kHz\n", max0, max4);
|
||||||
printf("Bluetooth RFKill : %s\n", bt_state);
|
printf("Bluetooth RFKill : %s\n", bt_state);
|
||||||
printf("ZRAM Compression : %s\n", zram_algo);
|
printf("ZRAM Compression : %s\n", zram_algo);
|
||||||
printf("Suspend Modes : %s\n", mem_sleep);
|
printf("Suspend Modes : %s (pmic_modes=%s, allow_md1=%s, last_wake_r12=%s)\n",
|
||||||
|
mem_sleep, spm_pmic_modes, spm_allow_md1, spm_last_wake_r12);
|
||||||
|
printf("Suspend Stats : ok=%s, fail=%s (last_failed=%s)\n",
|
||||||
|
suspend_ok, suspend_fail, last_failed_dev);
|
||||||
|
printf("GPU VGPU Rail : %s (%s uV, rail_suspends=%s)\n",
|
||||||
|
vgpu_state, vgpu_uv, gpu_rail_suspends);
|
||||||
|
printf("Powerd Status : %s\n", powerd_status);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
#include <sys/signalfd.h>
|
#include <sys/signalfd.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <sys/timerfd.h>
|
#include <sys/timerfd.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@@ -40,6 +41,9 @@
|
|||||||
#define FG_STATE_FILE "/var/lib/geminux/fuel-gauge.state"
|
#define FG_STATE_FILE "/var/lib/geminux/fuel-gauge.state"
|
||||||
#define FG_SYSFS_DIR "/sys/class/power_supply/battery/device"
|
#define FG_SYSFS_DIR "/sys/class/power_supply/battery/device"
|
||||||
#define MAX_EVDEVS 16
|
#define MAX_EVDEVS 16
|
||||||
|
#define SPM_ALLOW_MD1_SYSFS "/sys/module/mt6797_spm_sleep/parameters/allow_md1"
|
||||||
|
#define SPM_WAKE_R12_SYSFS "/sys/module/mt6797_spm_sleep/parameters/last_wake_r12"
|
||||||
|
#define SPM_WAKE_MD1_MASK ((1U << 8) | (1U << 25) | (1U << 26))
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int epfd;
|
int epfd;
|
||||||
@@ -70,6 +74,9 @@ typedef struct {
|
|||||||
bool consys_suspended;
|
bool consys_suspended;
|
||||||
bool suspend_ebusy_on_ac;
|
bool suspend_ebusy_on_ac;
|
||||||
bool low_power_standby;
|
bool low_power_standby;
|
||||||
|
uint32_t suspend_ok_count;
|
||||||
|
uint32_t suspend_fail_count;
|
||||||
|
uint64_t standby_retry_ms;
|
||||||
bool airplane_mode;
|
bool airplane_mode;
|
||||||
bool air_prev_wifi;
|
bool air_prev_wifi;
|
||||||
bool air_prev_bt_loaded;
|
bool air_prev_bt_loaded;
|
||||||
@@ -245,6 +252,7 @@ static void refresh_ac_and_hdmi(powerd_ctx_t *ctx) {
|
|||||||
|
|
||||||
static void lock_x11_session(void);
|
static void lock_x11_session(void);
|
||||||
static void wake_x11_display_dpms(void);
|
static void wake_x11_display_dpms(void);
|
||||||
|
static void blank_x11_display_dpms(void);
|
||||||
static void trigger_suspend(powerd_ctx_t *ctx);
|
static void trigger_suspend(powerd_ctx_t *ctx);
|
||||||
static void restore_cpus_after_resume(powerd_ctx_t *ctx);
|
static void restore_cpus_after_resume(powerd_ctx_t *ctx);
|
||||||
static void exit_low_power_standby(powerd_ctx_t *ctx);
|
static void exit_low_power_standby(powerd_ctx_t *ctx);
|
||||||
@@ -263,19 +271,20 @@ static void toggle_backlight(powerd_ctx_t *ctx, bool on) {
|
|||||||
DIR *d = opendir("/sys/class/backlight");
|
DIR *d = opendir("/sys/class/backlight");
|
||||||
if (!d) {
|
if (!d) {
|
||||||
if (on) wake_x11_display_dpms();
|
if (on) wake_x11_display_dpms();
|
||||||
|
else blank_x11_display_dpms();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
while ((de = readdir(d)) != NULL) {
|
while ((de = readdir(d)) != NULL) {
|
||||||
if (de->d_name[0] == '.') continue;
|
if (de->d_name[0] == '.') continue;
|
||||||
char p[320];
|
char p[320], pwr[320];
|
||||||
snprintf(p, sizeof(p), "/sys/class/backlight/%s/brightness", de->d_name);
|
snprintf(p, sizeof(p), "/sys/class/backlight/%s/brightness", de->d_name);
|
||||||
|
snprintf(pwr, sizeof(pwr), "/sys/class/backlight/%s/bl_power", de->d_name);
|
||||||
if (!on) {
|
if (!on) {
|
||||||
save_active_brightness(ctx, p);
|
save_active_brightness(ctx, p);
|
||||||
write_sysfs_str(p, "0");
|
write_sysfs_str(p, "0");
|
||||||
|
write_sysfs_str(pwr, "4");
|
||||||
} else {
|
} else {
|
||||||
char pwr[320];
|
|
||||||
snprintf(pwr, sizeof(pwr), "/sys/class/backlight/%s/bl_power", de->d_name);
|
|
||||||
write_sysfs_str(pwr, "0");
|
write_sysfs_str(pwr, "0");
|
||||||
char restore[32];
|
char restore[32];
|
||||||
int val = ctx->saved_brightness > 0 ? ctx->saved_brightness : 128;
|
int val = ctx->saved_brightness > 0 ? ctx->saved_brightness : 128;
|
||||||
@@ -286,6 +295,7 @@ static void toggle_backlight(powerd_ctx_t *ctx, bool on) {
|
|||||||
}
|
}
|
||||||
closedir(d);
|
closedir(d);
|
||||||
if (on) wake_x11_display_dpms();
|
if (on) wake_x11_display_dpms();
|
||||||
|
else blank_x11_display_dpms();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dim_backlight(powerd_ctx_t *ctx) {
|
static void dim_backlight(powerd_ctx_t *ctx) {
|
||||||
@@ -539,19 +549,22 @@ static void lock_x11_session(void) {
|
|||||||
close(pfd[0]);
|
close(pfd[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Force X11 DPMS On and reset the X11 screen saver inside a double-forked,
|
/* Force X11 DPMS On/Off inside a synchronous, 500 ms timeout-capped,
|
||||||
* privilege-dropped child so XIOError or display restarts never affect root
|
* privilege-dropped child so XIOError or X restarts never stall powerd,
|
||||||
* powerd, and external HDMI/client DPMS states always wake across S3/lid. */
|
* and blanking cuts CRTC/DSI/LCD scanout before suspend/standby. */
|
||||||
static void wake_x11_display_dpms(void) {
|
static void set_x11_display_dpms(bool on) {
|
||||||
|
if (access("/tmp/.X11-unix/X0", F_OK) != 0) return;
|
||||||
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid < 0) return;
|
if (pid < 0) return;
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
pid_t grand = fork();
|
|
||||||
if (grand < 0) _exit(1);
|
|
||||||
if (grand > 0) _exit(0);
|
|
||||||
|
|
||||||
unblock_signals();
|
unblock_signals();
|
||||||
setsid();
|
signal(SIGALRM, SIG_DFL);
|
||||||
|
struct itimerval it;
|
||||||
|
memset(&it, 0, sizeof(it));
|
||||||
|
it.it_value.tv_usec = 500000;
|
||||||
|
setitimer(ITIMER_REAL, &it, NULL);
|
||||||
|
|
||||||
int devnull = open("/dev/null", O_RDWR);
|
int devnull = open("/dev/null", O_RDWR);
|
||||||
if (devnull >= 0) {
|
if (devnull >= 0) {
|
||||||
dup2(devnull, STDIN_FILENO);
|
dup2(devnull, STDIN_FILENO);
|
||||||
@@ -579,19 +592,32 @@ static void wake_x11_display_dpms(void) {
|
|||||||
|
|
||||||
int ev_base = 0, err_base = 0;
|
int ev_base = 0, err_base = 0;
|
||||||
if (DPMSQueryExtension(dpy, &ev_base, &err_base) && DPMSCapable(dpy)) {
|
if (DPMSQueryExtension(dpy, &ev_base, &err_base) && DPMSCapable(dpy)) {
|
||||||
|
if (on) {
|
||||||
CARD16 power_level = DPMSModeOn;
|
CARD16 power_level = DPMSModeOn;
|
||||||
BOOL dpms_enabled = False;
|
BOOL dpms_enabled = False;
|
||||||
if (DPMSInfo(dpy, &power_level, &dpms_enabled) &&
|
if (DPMSInfo(dpy, &power_level, &dpms_enabled) &&
|
||||||
dpms_enabled && power_level != DPMSModeOn) {
|
dpms_enabled && power_level != DPMSModeOn) {
|
||||||
DPMSForceLevel(dpy, DPMSModeOn);
|
DPMSForceLevel(dpy, DPMSModeOn);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
DPMSEnable(dpy);
|
||||||
|
DPMSForceLevel(dpy, DPMSModeOff);
|
||||||
}
|
}
|
||||||
XResetScreenSaver(dpy);
|
}
|
||||||
|
if (on) XResetScreenSaver(dpy);
|
||||||
XSync(dpy, False);
|
XSync(dpy, False);
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
waitpid(pid, NULL, 0);
|
while (waitpid(pid, NULL, 0) < 0 && errno == EINTR) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wake_x11_display_dpms(void) {
|
||||||
|
set_x11_display_dpms(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void blank_x11_display_dpms(void) {
|
||||||
|
set_x11_display_dpms(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run_cmd_sync(const char *const argv[]) {
|
static int run_cmd_sync(const char *const argv[]) {
|
||||||
@@ -854,7 +880,15 @@ static void unload_consys_stack(bool include_wlan_core) {
|
|||||||
* unloading reverse dependents lets mt6797_consys_remove() power off CONN/VCN rails. */
|
* unloading reverse dependents lets mt6797_consys_remove() power off CONN/VCN rails. */
|
||||||
static void prepare_consys_for_suspend(powerd_ctx_t *ctx) {
|
static void prepare_consys_for_suspend(powerd_ctx_t *ctx) {
|
||||||
reap_consys_restore(ctx, true);
|
reap_consys_restore(ctx, true);
|
||||||
|
reap_radio_worker(ctx, true);
|
||||||
if (ctx->airplane_mode) {
|
if (ctx->airplane_mode) {
|
||||||
|
if (access("/sys/module/mt6797_consys", F_OK) == 0) {
|
||||||
|
unload_consys_stack(true);
|
||||||
|
}
|
||||||
|
char st[16] = {0};
|
||||||
|
if (read_sysfs_line("/sys/class/mt6797_ccci/md1/stage", st, sizeof(st)) == 0 && atoi(st) > 0) {
|
||||||
|
write_sysfs_str("/sys/class/mt6797_ccci/md1/stage", "0");
|
||||||
|
}
|
||||||
ctx->consys_suspended = false;
|
ctx->consys_suspended = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -978,11 +1012,18 @@ static void apply_airplane_mode(powerd_ctx_t *ctx, bool enable) {
|
|||||||
const char *mm_stop[] = {"/sbin/rc-service", "--quiet", "modemmanager", "stop", NULL};
|
const char *mm_stop[] = {"/sbin/rc-service", "--quiet", "modemmanager", "stop", NULL};
|
||||||
run_cmd_sync(mm_stop);
|
run_cmd_sync(mm_stop);
|
||||||
send_unix_line(CCCI_SOCK_PATH, "flight on");
|
send_unix_line(CCCI_SOCK_PATH, "flight on");
|
||||||
|
char md_st[16] = {0};
|
||||||
|
if (read_sysfs_line("/sys/class/mt6797_ccci/md1/stage", md_st, sizeof(md_st)) == 0 &&
|
||||||
|
atoi(md_st) > 0) {
|
||||||
|
write_sysfs_str("/sys/class/mt6797_ccci/md1/stage", "0");
|
||||||
|
}
|
||||||
write_text_file(MODEM_STATE_FILE, "AIRPLANE\n", 0666);
|
write_text_file(MODEM_STATE_FILE, "AIRPLANE\n", 0666);
|
||||||
|
|
||||||
|
const char *bt_stop[] = {"/sbin/rc-service", "--quiet", "bluetooth", "stop", NULL};
|
||||||
const char *nm_off[] = {"/usr/bin/nmcli", "radio", "wifi", "off", NULL};
|
const char *nm_off[] = {"/usr/bin/nmcli", "radio", "wifi", "off", NULL};
|
||||||
const char *rf_w[] = {"/usr/sbin/rfkill", "block", "wifi", NULL};
|
const char *rf_w[] = {"/usr/sbin/rfkill", "block", "wifi", NULL};
|
||||||
const char *rf_b[] = {"/usr/sbin/rfkill", "block", "bluetooth", NULL};
|
const char *rf_b[] = {"/usr/sbin/rfkill", "block", "bluetooth", NULL};
|
||||||
|
run_cmd_sync(bt_stop);
|
||||||
run_cmd_sync(nm_off);
|
run_cmd_sync(nm_off);
|
||||||
run_cmd_sync(rf_w);
|
run_cmd_sync(rf_w);
|
||||||
run_cmd_sync(rf_b);
|
run_cmd_sync(rf_b);
|
||||||
@@ -1144,16 +1185,36 @@ static void restore_cpus_after_resume(powerd_ctx_t *ctx) {
|
|||||||
ctx->policy_applied = false;
|
ctx->policy_applied = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool read_spm_allow_md1(void) {
|
||||||
|
char val[16] = {0};
|
||||||
|
if (read_sysfs_line(SPM_ALLOW_MD1_SYSFS, val, sizeof(val)) != 0) return false;
|
||||||
|
return (val[0] == 'Y' || val[0] == 'y' || val[0] == '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t read_spm_last_wake_r12(void) {
|
||||||
|
char val[32] = {0};
|
||||||
|
if (read_sysfs_line(SPM_WAKE_R12_SYSFS, val, sizeof(val)) != 0 || !val[0]) return 0;
|
||||||
|
return (uint32_t)strtoul(val, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
static bool can_enter_deep_mem_sleep(const powerd_ctx_t *ctx) {
|
static bool can_enter_deep_mem_sleep(const powerd_ctx_t *ctx) {
|
||||||
if (ctx->policy.on_ac_power) return false;
|
if (ctx->policy.on_ac_power) return false;
|
||||||
char st[16] = {0};
|
char st[16] = {0};
|
||||||
if (read_sysfs_line("/sys/class/mt6797_ccci/md1/stage", st, sizeof(st)) == 0 && atoi(st) > 0) {
|
if (read_sysfs_line("/sys/class/mt6797_ccci/md1/stage", st, sizeof(st)) == 0 && atoi(st) > 0) {
|
||||||
return false;
|
return read_spm_allow_md1();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint64_t next_standby_retry_ms(uint64_t cur) {
|
||||||
|
if (cur < 3000) return 3000;
|
||||||
|
if (cur < 10000) return 10000;
|
||||||
|
if (cur < 30000) return 30000;
|
||||||
|
return 60000;
|
||||||
|
}
|
||||||
|
|
||||||
static void exit_low_power_standby(powerd_ctx_t *ctx) {
|
static void exit_low_power_standby(powerd_ctx_t *ctx) {
|
||||||
|
ctx->standby_retry_ms = 0;
|
||||||
if (!ctx->low_power_standby) return;
|
if (!ctx->low_power_standby) return;
|
||||||
ctx->low_power_standby = false;
|
ctx->low_power_standby = false;
|
||||||
restore_cpus_after_resume(ctx);
|
restore_cpus_after_resume(ctx);
|
||||||
@@ -1173,6 +1234,7 @@ static void trigger_suspend(powerd_ctx_t *ctx) {
|
|||||||
toggle_backlight(ctx, false);
|
toggle_backlight(ctx, false);
|
||||||
save_fuel_gauge_state(ctx);
|
save_fuel_gauge_state(ctx);
|
||||||
if (ctx->policy.on_ac_power) {
|
if (ctx->policy.on_ac_power) {
|
||||||
|
ctx->standby_retry_ms = 0;
|
||||||
ctx->suspend_ebusy_on_ac = true;
|
ctx->suspend_ebusy_on_ac = true;
|
||||||
ctx->idle_stage = IDLE_STAGE_LOCKED_BLANK;
|
ctx->idle_stage = IDLE_STAGE_LOCKED_BLANK;
|
||||||
apply_cpu_sysfs(ctx, false);
|
apply_cpu_sysfs(ctx, false);
|
||||||
@@ -1181,7 +1243,6 @@ static void trigger_suspend(powerd_ctx_t *ctx) {
|
|||||||
refresh_lid_state(ctx);
|
refresh_lid_state(ctx);
|
||||||
bool was_lid_closed = ctx->policy.lid_closed;
|
bool was_lid_closed = ctx->policy.lid_closed;
|
||||||
bool prev_ac = ctx->policy.on_ac_power;
|
bool prev_ac = ctx->policy.on_ac_power;
|
||||||
exit_low_power_standby(ctx);
|
|
||||||
prepare_consys_for_suspend(ctx);
|
prepare_consys_for_suspend(ctx);
|
||||||
prepare_cpus_for_suspend();
|
prepare_cpus_for_suspend();
|
||||||
bool can_deep = can_enter_deep_mem_sleep(ctx);
|
bool can_deep = can_enter_deep_mem_sleep(ctx);
|
||||||
@@ -1189,6 +1250,12 @@ static void trigger_suspend(powerd_ctx_t *ctx) {
|
|||||||
if (can_deep) {
|
if (can_deep) {
|
||||||
write_sysfs_str("/sys/power/mem_sleep", "deep");
|
write_sysfs_str("/sys/power/mem_sleep", "deep");
|
||||||
suspended = (write_sysfs_str("/sys/power/state", "mem") == 0);
|
suspended = (write_sysfs_str("/sys/power/state", "mem") == 0);
|
||||||
|
if (suspended) {
|
||||||
|
ctx->suspend_ok_count++;
|
||||||
|
ctx->standby_retry_ms = 0;
|
||||||
|
} else {
|
||||||
|
ctx->suspend_fail_count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!suspended) {
|
if (!suspended) {
|
||||||
refresh_lid_state(ctx);
|
refresh_lid_state(ctx);
|
||||||
@@ -1198,12 +1265,18 @@ static void trigger_suspend(powerd_ctx_t *ctx) {
|
|||||||
(ctx->policy.lid_closed ? geminux_should_suspend_on_lid(&ctx->policy) : true)) {
|
(ctx->policy.lid_closed ? geminux_should_suspend_on_lid(&ctx->policy) : true)) {
|
||||||
ctx->low_power_standby = true;
|
ctx->low_power_standby = true;
|
||||||
ctx->idle_stage = IDLE_STAGE_LOCKED_BLANK;
|
ctx->idle_stage = IDLE_STAGE_LOCKED_BLANK;
|
||||||
|
if (can_enter_deep_mem_sleep(ctx) || ctx->airplane_mode || ctx->radio_worker_pid > 0) {
|
||||||
|
ctx->standby_retry_ms = next_standby_retry_ms(ctx->standby_retry_ms);
|
||||||
|
arm_timer_ms(ctx->tmr_fd, ctx->standby_retry_ms);
|
||||||
|
} else {
|
||||||
|
ctx->standby_retry_ms = 0;
|
||||||
arm_timer_ms(ctx->tmr_fd, 0);
|
arm_timer_ms(ctx->tmr_fd, 0);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx->low_power_standby = false;
|
uint32_t wake_r12 = suspended ? read_spm_last_wake_r12() : 0;
|
||||||
restore_cpus_after_resume(ctx);
|
bool modem_wake = suspended && ((wake_r12 & SPM_WAKE_MD1_MASK) != 0);
|
||||||
bool saw_wake_input = suspended ? wait_post_resume_lid_events(ctx, was_lid_closed, 90)
|
bool saw_wake_input = suspended ? wait_post_resume_lid_events(ctx, was_lid_closed, 90)
|
||||||
: (was_lid_closed && !ctx->policy.lid_closed);
|
: (was_lid_closed && !ctx->policy.lid_closed);
|
||||||
refresh_ac_and_hdmi(ctx);
|
refresh_ac_and_hdmi(ctx);
|
||||||
@@ -1218,6 +1291,14 @@ static void trigger_suspend(powerd_ctx_t *ctx) {
|
|||||||
geminux_should_suspend_on_lid(&ctx->policy);
|
geminux_should_suspend_on_lid(&ctx->policy);
|
||||||
bool quiet_timer_resleep = suspended && !ctx->suspend_ebusy_on_ac &&
|
bool quiet_timer_resleep = suspended && !ctx->suspend_ebusy_on_ac &&
|
||||||
(want_resleep_closed || want_resleep_open);
|
(want_resleep_closed || want_resleep_open);
|
||||||
|
if (!quiet_timer_resleep) {
|
||||||
|
ctx->low_power_standby = false;
|
||||||
|
ctx->standby_retry_ms = 0;
|
||||||
|
restore_cpus_after_resume(ctx);
|
||||||
|
} else {
|
||||||
|
ctx->low_power_standby = true;
|
||||||
|
ctx->standby_retry_ms = 0;
|
||||||
|
}
|
||||||
if (!quiet_timer_resleep &&
|
if (!quiet_timer_resleep &&
|
||||||
(!ctx->policy.lid_closed || !geminux_should_suspend_on_lid(&ctx->policy) ||
|
(!ctx->policy.lid_closed || !geminux_should_suspend_on_lid(&ctx->policy) ||
|
||||||
ctx->suspend_ebusy_on_ac)) {
|
ctx->suspend_ebusy_on_ac)) {
|
||||||
@@ -1230,14 +1311,13 @@ static void trigger_suspend(powerd_ctx_t *ctx) {
|
|||||||
toggle_backlight(ctx, true);
|
toggle_backlight(ctx, true);
|
||||||
apply_cpu_policy(ctx, true);
|
apply_cpu_policy(ctx, true);
|
||||||
evaluate_idle(ctx);
|
evaluate_idle(ctx);
|
||||||
|
} else if (quiet_timer_resleep) {
|
||||||
|
ctx->idle_stage = IDLE_STAGE_LOCKED_BLANK;
|
||||||
|
arm_timer_ms(ctx->tmr_fd, modem_wake ? 3500 : 300);
|
||||||
} else {
|
} else {
|
||||||
toggle_backlight(ctx, false);
|
toggle_backlight(ctx, false);
|
||||||
ctx->idle_stage = IDLE_STAGE_LOCKED_BLANK;
|
ctx->idle_stage = IDLE_STAGE_LOCKED_BLANK;
|
||||||
if (quiet_timer_resleep) {
|
|
||||||
arm_timer_ms(ctx->tmr_fd, 2000);
|
|
||||||
} else {
|
|
||||||
arm_timer_ms(ctx->tmr_fd, 0);
|
arm_timer_ms(ctx->tmr_fd, 0);
|
||||||
}
|
|
||||||
apply_cpu_sysfs(ctx, true);
|
apply_cpu_sysfs(ctx, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1307,6 +1387,9 @@ static void handle_client_cmd(powerd_ctx_t *ctx, int cfd) {
|
|||||||
} else if (strncmp(buf, "inhibit del ", 12) == 0) {
|
} else if (strncmp(buf, "inhibit del ", 12) == 0) {
|
||||||
geminux_policy_del_inhibit(&ctx->policy, buf + 12);
|
geminux_policy_del_inhibit(&ctx->policy, buf + 12);
|
||||||
apply_cpu_policy(ctx, false);
|
apply_cpu_policy(ctx, false);
|
||||||
|
if (ctx->policy.lid_closed && geminux_should_suspend_on_lid(&ctx->policy)) {
|
||||||
|
arm_timer_ms(ctx->tmr_fd, 1000);
|
||||||
|
}
|
||||||
dprintf(cfd, "OK inhibits=%d\n", ctx->policy.inhibit_count);
|
dprintf(cfd, "OK inhibits=%d\n", ctx->policy.inhibit_count);
|
||||||
} else if (strcmp(buf, "lid-suspend on") == 0) {
|
} else if (strcmp(buf, "lid-suspend on") == 0) {
|
||||||
ctx->policy.lid_suspend_enabled = true;
|
ctx->policy.lid_suspend_enabled = true;
|
||||||
@@ -1339,14 +1422,19 @@ static void handle_client_cmd(powerd_ctx_t *ctx, int cfd) {
|
|||||||
apply_airplane_mode(ctx, !ctx->airplane_mode);
|
apply_airplane_mode(ctx, !ctx->airplane_mode);
|
||||||
dprintf(cfd, "OK airplane=%s\n", ctx->airplane_mode ? "on" : "off");
|
dprintf(cfd, "OK airplane=%s\n", ctx->airplane_mode ? "on" : "off");
|
||||||
} else if (strcmp(buf, "status") == 0) {
|
} else if (strcmp(buf, "status") == 0) {
|
||||||
dprintf(cfd, "profile=%s ac=%d hdmi=%d lid_closed=%d lid_suspend=%d inhibits=%d airplane=%d\n",
|
dprintf(cfd,
|
||||||
|
"profile=%s ac=%d hdmi=%d lid_closed=%d lid_suspend=%d inhibits=%d "
|
||||||
|
"airplane=%d standby=%d suspend_ok=%u suspend_fail=%u\n",
|
||||||
geminux_policy_profile_name(ctx->policy.profile),
|
geminux_policy_profile_name(ctx->policy.profile),
|
||||||
ctx->policy.on_ac_power ? 1 : 0,
|
ctx->policy.on_ac_power ? 1 : 0,
|
||||||
ctx->policy.hdmi_connected ? 1 : 0,
|
ctx->policy.hdmi_connected ? 1 : 0,
|
||||||
ctx->policy.lid_closed ? 1 : 0,
|
ctx->policy.lid_closed ? 1 : 0,
|
||||||
ctx->policy.lid_suspend_enabled ? 1 : 0,
|
ctx->policy.lid_suspend_enabled ? 1 : 0,
|
||||||
ctx->policy.inhibit_count,
|
ctx->policy.inhibit_count,
|
||||||
ctx->airplane_mode ? 1 : 0);
|
ctx->airplane_mode ? 1 : 0,
|
||||||
|
ctx->low_power_standby ? 1 : 0,
|
||||||
|
ctx->suspend_ok_count,
|
||||||
|
ctx->suspend_fail_count);
|
||||||
} else {
|
} else {
|
||||||
dprintf(cfd, "ERR unknown command\n");
|
dprintf(cfd, "ERR unknown command\n");
|
||||||
}
|
}
|
||||||
@@ -1470,8 +1558,17 @@ int main(void) {
|
|||||||
struct signalfd_siginfo si;
|
struct signalfd_siginfo si;
|
||||||
while (read(ctx.sig_fd, &si, sizeof(si)) > 0) {
|
while (read(ctx.sig_fd, &si, sizeof(si)) > 0) {
|
||||||
if (si.ssi_signo == SIGCHLD) {
|
if (si.ssi_signo == SIGCHLD) {
|
||||||
|
bool had_radio_worker = (ctx.radio_worker_pid > 0);
|
||||||
reap_consys_restore(&ctx, false);
|
reap_consys_restore(&ctx, false);
|
||||||
reap_radio_worker(&ctx, false);
|
reap_radio_worker(&ctx, false);
|
||||||
|
if (had_radio_worker && ctx.radio_worker_pid < 0 &&
|
||||||
|
ctx.low_power_standby && can_enter_deep_mem_sleep(&ctx) &&
|
||||||
|
!ctx.policy.on_ac_power && !ctx.policy.hdmi_connected &&
|
||||||
|
ctx.policy.inhibit_count == 0 &&
|
||||||
|
(ctx.policy.lid_closed || ctx.idle_stage == IDLE_STAGE_LOCKED_BLANK)) {
|
||||||
|
ctx.standby_retry_ms = 0;
|
||||||
|
arm_timer_ms(ctx.tmr_fd, 500);
|
||||||
|
}
|
||||||
} else if (si.ssi_signo == SIGHUP) {
|
} else if (si.ssi_signo == SIGHUP) {
|
||||||
refresh_ac_and_hdmi(&ctx);
|
refresh_ac_and_hdmi(&ctx);
|
||||||
apply_cpu_policy(&ctx, true);
|
apply_cpu_policy(&ctx, true);
|
||||||
|
|||||||
Reference in new issue
Block a user