Fix SPM sleep im_wait failure, defer lid-closed touch wake, and harden powerd
This commit is contained in:
1 parent
a015ef64ef
commit
efc5c0a548
13 files changed
+275
-23
No files matched your search
@@ -22,6 +22,7 @@ Vanilla Linux `7.3.5` builds from [patches/kernel/](patches/kernel/) with `CONFI
|
||||
| `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 |
|
||||
| `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 |
|
||||
| `0015-gemini-spm-im-wait-and-touch-sleep-fix.patch` | Defaults `mt6797-spm-sleep` `sleep_im_wait=0` (`s.sleep.im_wait = false`), defers `SSD2092` touch wake while lid-inhibited until `input->open()`, and triggers Panfrost cold-boot `pm_runtime_autosuspend()` |
|
||||
|
||||
- **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.
|
||||
|
||||
@@ -32,7 +32,7 @@ Built into `7.3.5-geminux` via [kernel/configs/geminux-mt6797x.config](kernel/co
|
||||
- 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.
|
||||
- **SPM, Hall lid, PMIC IRQ & fuel-gauge hardening (`0008`, `0011`, `0012`, `0013`, `0015`)**: 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, disables `s.sleep.im_wait` by default (`sleep_im_wait=0`, preventing `-ETIMEDOUT` aborts before `PCM_KICK_L`), defers `SSD2092` touch MCU wake while lid-inhibited until `input->open()`, triggers cold-boot `pm_runtime_autosuspend()` on Panfrost, and stabilizes `mt6351-fuel-gauge` + `bq25890` zero-current OCV/taper calibration.
|
||||
|
||||
## Zero-poll userspace daemons
|
||||
|
||||
@@ -40,10 +40,10 @@ Built into `7.3.5-geminux` via [kernel/configs/geminux-mt6797x.config](kernel/co
|
||||
|
||||
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 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` & 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.
|
||||
- **USB/AC policy (`inhibit_ac_lid`)**: Refreshes AC/HDMI state directly on `SW_LID` close; 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` & 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` failures or short `< 5 s` non-modem sleep cycles trigger exponential retries (`3s -> 10s -> 30s -> 60s`), `SIGCHLD` re-arms immediately when `radio_worker_pid` completes, and `last_errno` / `last_sleep_ms` are reported in `powerd` status.
|
||||
- **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`:
|
||||
- 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.
|
||||
- Internal `600 s` PCM timer rollovers (`quiet_timer_resleep`) and any spurious `EV_KEY`/`EV_ABS` while `SW_LID` remains closed keep `cpu1..7` offline and re-enter `mem` sleep after `300 ms` without waking Xorg or reloading CONSYS.
|
||||
- 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`.
|
||||
@@ -83,7 +83,7 @@ geminux-power-audit
|
||||
geminux-power-audit --json
|
||||
```
|
||||
|
||||
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:
|
||||
Look for `"spm_pmic_modes":"Y"`, `"spm_allow_md1":"Y"`, `"spm_sleep_im_wait":"N"`, incrementing `"suspend_success"` and `"gpu_rail_suspends"`, `"vgpu_state":"disabled"`, `"last_failed_dev":"none"`, `"last_failed_errno":"0"`, 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
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
--- a/drivers/soc/mediatek/mt6797-spm-sleep.c
|
||||
+++ b/drivers/soc/mediatek/mt6797-spm-sleep.c
|
||||
@@ -505,6 +505,10 @@
|
||||
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 sleep_im_wait;
|
||||
+module_param(sleep_im_wait, bool, 0644);
|
||||
+MODULE_PARM_DESC(sleep_im_wait, "Sleep: refuse mem suspend if IM fetch FSM does not return to reset state before kick");
|
||||
+
|
||||
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");
|
||||
@@ -1381,6 +1385,7 @@
|
||||
if (!spm_off(CONN_PWR_CON))
|
||||
return -EBUSY;
|
||||
s.sleep.ticks = timer_sec * 32768;
|
||||
+ s.sleep.im_wait = READ_ONCE(sleep_im_wait);
|
||||
s.sleep.wake_src = S1_WAKE_SRC;
|
||||
if (allow_md1 && !spm_off(MD1_PWR_CON))
|
||||
s.sleep.wake_src |= S1_MD1_WAKE_SRC;
|
||||
@@ -2124,7 +2129,7 @@
|
||||
s.sleep.wake_src = S1_WAKE_SRC;
|
||||
s.sleep.slots = true;
|
||||
s.sleep.pcm_wdt = true;
|
||||
- s.sleep.im_wait = true;
|
||||
+ s.sleep.im_wait = false;
|
||||
s.sleep.im_wait_us = SLEEP_IM_WAIT_US;
|
||||
s.sleep.backstop_ms = 5000;
|
||||
ret = spm_load_program(&s.pdev->dev, SPM_FW_NAME, spm_fw_sha256, 0, &s.sleep);
|
||||
--- a/drivers/input/touchscreen/novatek-nt36xxx.c
|
||||
+++ b/drivers/input/touchscreen/novatek-nt36xxx.c
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <linux/mfd/mt6351/registers.h>
|
||||
#include <linux/mfd/mt6397/core.h>
|
||||
#include <linux/module.h>
|
||||
+#include <linux/mutex.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/of_platform.h>
|
||||
@@ -79,8 +80,10 @@
|
||||
u16 pid;
|
||||
u16 last_fw_touch;
|
||||
u16 last_fw_disp;
|
||||
+ struct mutex irq_lock;
|
||||
bool is_ssd2092;
|
||||
bool irq_disabled;
|
||||
+ bool resume_deferred;
|
||||
struct delayed_work resume_work;
|
||||
};
|
||||
|
||||
@@ -761,6 +764,26 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static void ssd2092_disable_irq(struct nvt36xxx_data *data)
|
||||
+{
|
||||
+ mutex_lock(&data->irq_lock);
|
||||
+ if (!data->irq_disabled) {
|
||||
+ disable_irq(data->client->irq);
|
||||
+ data->irq_disabled = true;
|
||||
+ }
|
||||
+ mutex_unlock(&data->irq_lock);
|
||||
+}
|
||||
+
|
||||
+static void ssd2092_enable_irq(struct nvt36xxx_data *data)
|
||||
+{
|
||||
+ mutex_lock(&data->irq_lock);
|
||||
+ if (data->irq_disabled) {
|
||||
+ data->irq_disabled = false;
|
||||
+ enable_irq(data->client->irq);
|
||||
+ }
|
||||
+ mutex_unlock(&data->irq_lock);
|
||||
+}
|
||||
+
|
||||
static void ssd2092_resume_work_fn(struct work_struct *work)
|
||||
{
|
||||
struct nvt36xxx_data *data =
|
||||
@@ -769,6 +792,12 @@
|
||||
int ret = -EIO;
|
||||
int attempt;
|
||||
|
||||
+ if (data->input && READ_ONCE(data->input->inhibited)) {
|
||||
+ WRITE_ONCE(data->resume_deferred, true);
|
||||
+ return;
|
||||
+ }
|
||||
+ WRITE_ONCE(data->resume_deferred, false);
|
||||
+
|
||||
if (!data->vcc_reg)
|
||||
ssd2092_enable_pmic_vldo28();
|
||||
|
||||
@@ -786,10 +815,27 @@
|
||||
dev_warn(dev, "SSD2092 resume init failed: %d\n", ret);
|
||||
}
|
||||
|
||||
- if (data->irq_disabled) {
|
||||
- data->irq_disabled = false;
|
||||
- enable_irq(data->client->irq);
|
||||
+ ssd2092_enable_irq(data);
|
||||
+}
|
||||
+
|
||||
+static int ssd2092_input_open(struct input_dev *input)
|
||||
+{
|
||||
+ struct nvt36xxx_data *data = input_get_drvdata(input);
|
||||
+
|
||||
+ if (READ_ONCE(data->resume_deferred) || READ_ONCE(data->irq_disabled)) {
|
||||
+ WRITE_ONCE(data->resume_deferred, false);
|
||||
+ mod_delayed_work(system_wq, &data->resume_work,
|
||||
+ msecs_to_jiffies(120));
|
||||
}
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static void ssd2092_input_close(struct input_dev *input)
|
||||
+{
|
||||
+ struct nvt36xxx_data *data = input_get_drvdata(input);
|
||||
+
|
||||
+ if (cancel_delayed_work_sync(&data->resume_work))
|
||||
+ WRITE_ONCE(data->resume_deferred, true);
|
||||
}
|
||||
|
||||
static void ssd2092_cancel_resume_work(void *arg)
|
||||
@@ -819,6 +865,7 @@
|
||||
return -EINVAL;
|
||||
data->orig_irq_type = dt_trig;
|
||||
|
||||
+ mutex_init(&data->irq_lock);
|
||||
data->is_ssd2092 = true;
|
||||
INIT_DELAYED_WORK(&data->resume_work, ssd2092_resume_work_fn);
|
||||
ret = ssd2092_setup_power_and_reset(data);
|
||||
@@ -870,6 +917,8 @@
|
||||
|
||||
data->input = input;
|
||||
input_set_drvdata(input, data);
|
||||
+ input->open = ssd2092_input_open;
|
||||
+ input->close = ssd2092_input_close;
|
||||
ret = input_register_device(input);
|
||||
if (ret)
|
||||
return ret;
|
||||
@@ -995,10 +1044,8 @@
|
||||
return 0;
|
||||
|
||||
cancel_delayed_work_sync(&data->resume_work);
|
||||
- if (!data->irq_disabled) {
|
||||
- disable_irq(data->client->irq);
|
||||
- data->irq_disabled = true;
|
||||
- }
|
||||
+ WRITE_ONCE(data->resume_deferred, false);
|
||||
+ ssd2092_disable_irq(data);
|
||||
memset(data->slots, 0, sizeof(data->slots));
|
||||
ssd2092_report_slots(data);
|
||||
return 0;
|
||||
@@ -1011,6 +1058,10 @@
|
||||
if (!data->is_ssd2092)
|
||||
return;
|
||||
|
||||
+ if (data->input && READ_ONCE(data->input->inhibited)) {
|
||||
+ WRITE_ONCE(data->resume_deferred, true);
|
||||
+ return;
|
||||
+ }
|
||||
schedule_delayed_work(&data->resume_work, msecs_to_jiffies(60));
|
||||
}
|
||||
|
||||
--- a/drivers/gpu/drm/panfrost/panfrost_drv.c
|
||||
+++ b/drivers/gpu/drm/panfrost/panfrost_drv.c
|
||||
@@ -1020,6 +1020,9 @@
|
||||
if (err)
|
||||
goto err_out2;
|
||||
|
||||
+ if (!panfrost_keep_powered(pfdev))
|
||||
+ pm_runtime_autosuspend(pfdev->base.dev);
|
||||
+
|
||||
return 0;
|
||||
|
||||
err_out2:
|
||||
@@ -12,3 +12,4 @@
|
||||
0012-gemini-lid-wake-and-fg-taper-fix.patch
|
||||
0013-gemini-pmic-wake-and-spm-safety.patch
|
||||
0014-gemini-deep-sleep-power-drainers.patch
|
||||
0015-gemini-spm-im-wait-and-touch-sleep-fix.patch
|
||||
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.
@@ -688,6 +688,7 @@ def main():
|
||||
"0012-gemini-lid-wake-and-fg-taper-fix.patch",
|
||||
"0013-gemini-pmic-wake-and-spm-safety.patch",
|
||||
"0014-gemini-deep-sleep-power-drainers.patch",
|
||||
"0015-gemini-spm-im-wait-and-touch-sleep-fix.patch",
|
||||
),
|
||||
os.path.join(overlay_dir, "etc", "profile.d", "10-geminux-env.sh"): (
|
||||
"export NO_AT_BRIDGE=1",
|
||||
@@ -802,18 +803,47 @@ def main():
|
||||
if needle not in p14_src:
|
||||
raise AssertionError(f"0014 patch missing expected MD1 mem-sleep token: {needle}")
|
||||
|
||||
patch_0015_path = os.path.join(
|
||||
BASE_DIR, "patches", "kernel", "0015-gemini-spm-im-wait-and-touch-sleep-fix.patch"
|
||||
)
|
||||
with open(patch_0015_path, "r", encoding="utf-8") as handle:
|
||||
p15_src = handle.read()
|
||||
for needle in (
|
||||
"sleep_im_wait",
|
||||
"s.sleep.im_wait = false",
|
||||
"ssd2092_input_open",
|
||||
"resume_deferred",
|
||||
"pm_runtime_autosuspend",
|
||||
):
|
||||
if needle not in p15_src:
|
||||
raise AssertionError(f"0015 patch missing expected fix 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)",
|
||||
"CLOCK_BOOTTIME",
|
||||
"last_suspend_errno",
|
||||
"last_sleep_ms=",
|
||||
):
|
||||
if needle not in powerd_dpms_src:
|
||||
raise AssertionError(f"geminux-powerd.c missing expected MD1 mem-sleep token: {needle}")
|
||||
|
||||
hlc_start = powerd_dpms_src.find("static void handle_lid_closed")
|
||||
hlc_end = powerd_dpms_src.find("\nstatic ", hlc_start + 1)
|
||||
hlc_src = powerd_dpms_src[hlc_start:hlc_end]
|
||||
if "refresh_ac_and_hdmi(ctx)" not in hlc_src:
|
||||
raise AssertionError("handle_lid_closed must call refresh_ac_and_hdmi(ctx)")
|
||||
|
||||
wrc_start = trig_src.find("bool want_resleep_closed")
|
||||
wrc_end = trig_src.find(";", wrc_start)
|
||||
if wrc_start < 0 or wrc_end < 0 or "saw_wake_input" in trig_src[wrc_start:wrc_end]:
|
||||
raise AssertionError("want_resleep_closed must not be disabled by saw_wake_input while lid is closed")
|
||||
|
||||
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"):
|
||||
for needle in ("spm_allow_md1", "spm_last_wake_r12", "spm_sleep_im_wait", "last_failed_errno"):
|
||||
if needle not in audit_src:
|
||||
raise AssertionError(f"geminux-power-audit.c missing expected telemetry token: {needle}")
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ static void query_powerd_status(char *buf, size_t sz) {
|
||||
const char *req = "status\n";
|
||||
if (write(fd, req, strlen(req)) > 0) {
|
||||
shutdown(fd, SHUT_WR);
|
||||
char tmp[256] = {0};
|
||||
char tmp[384] = {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';
|
||||
@@ -81,11 +81,14 @@ int main(int argc, char **argv) {
|
||||
(access("/sys/module/mt6797_consys", F_OK) == 0) ? "loaded" : "unloaded";
|
||||
|
||||
char spm_pmic_modes[16] = "unknown", spm_allow_md1[16] = "unknown";
|
||||
char spm_sleep_im_wait[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));
|
||||
read_str("/sys/module/mt6797_spm_sleep/parameters/sleep_im_wait",
|
||||
spm_sleep_im_wait, sizeof(spm_sleep_im_wait));
|
||||
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]) {
|
||||
@@ -97,6 +100,7 @@ int main(int argc, char **argv) {
|
||||
gpu_rail_suspends, sizeof(gpu_rail_suspends));
|
||||
|
||||
char suspend_ok[32] = "0", suspend_fail[32] = "0", last_failed_dev[64] = "none";
|
||||
char last_failed_errno[32] = "0";
|
||||
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",
|
||||
@@ -104,6 +108,11 @@ int main(int argc, char **argv) {
|
||||
!last_failed_dev[0]) {
|
||||
snprintf(last_failed_dev, sizeof(last_failed_dev), "none");
|
||||
}
|
||||
if (read_str("/sys/power/suspend_stats/last_failed_errno",
|
||||
last_failed_errno, sizeof(last_failed_errno)) != 0 ||
|
||||
!last_failed_errno[0]) {
|
||||
snprintf(last_failed_errno, sizeof(last_failed_errno), "0");
|
||||
}
|
||||
|
||||
char vgpu_state[32] = "absent", vgpu_uv[32] = "unknown";
|
||||
DIR *rd = opendir("/sys/class/regulator");
|
||||
@@ -125,7 +134,7 @@ int main(int argc, char **argv) {
|
||||
closedir(rd);
|
||||
}
|
||||
|
||||
char powerd_status[256];
|
||||
char powerd_status[384];
|
||||
query_powerd_status(powerd_status, sizeof(powerd_status));
|
||||
|
||||
char bat_cap[32] = "?", bat_status[32] = "Unknown", bat_uv[32] = "?", bat_ua[32] = "?";
|
||||
@@ -188,9 +197,10 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
if (json) {
|
||||
char pwr_esc[384], dev_esc[128];
|
||||
char pwr_esc[512], dev_esc[128], errno_esc[64];
|
||||
json_escape(powerd_status, pwr_esc, sizeof(pwr_esc));
|
||||
json_escape(last_failed_dev, dev_esc, sizeof(dev_esc));
|
||||
json_escape(last_failed_errno, errno_esc, sizeof(errno_esc));
|
||||
printf("{\"profile\":\"%s\",\"battery_pct\":\"%s\",\"battery_status\":\"%s\","
|
||||
"\"voltage_uv\":\"%s\",\"current_ua\":\"%s\",\"online_cpus\":%d,"
|
||||
"\"a72_online\":%d,\"governor\":\"%s\",\"policy0_max_khz\":\"%s\","
|
||||
@@ -198,15 +208,17 @@ int main(int argc, char **argv) {
|
||||
"\"zram_algo\":\"%s\",\"mem_sleep\":\"%s\","
|
||||
"\"airplane_mode\":\"%s\",\"md1_stage\":\"%s\",\"consys\":\"%s\","
|
||||
"\"spm_pmic_modes\":\"%s\",\"spm_allow_md1\":\"%s\","
|
||||
"\"spm_sleep_im_wait\":\"%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",
|
||||
"\"last_failed_dev\":\"%s\",\"last_failed_errno\":\"%s\",\"powerd_status\":\"%s\"}\n",
|
||||
profile, bat_cap, bat_status, bat_uv, bat_ua, online_cpus, a72_online,
|
||||
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);
|
||||
spm_allow_md1, spm_sleep_im_wait, spm_last_wake_r12, gpu_rail_suspends,
|
||||
vgpu_state, vgpu_uv, suspend_ok, suspend_fail, dev_esc, errno_esc,
|
||||
pwr_esc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -221,10 +233,10 @@ int main(int argc, char **argv) {
|
||||
printf("CPUfreq Caps : policy0=%s kHz, policy4=%s kHz\n", max0, max4);
|
||||
printf("Bluetooth RFKill : %s\n", bt_state);
|
||||
printf("ZRAM Compression : %s\n", zram_algo);
|
||||
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("Suspend Modes : %s (pmic_modes=%s, allow_md1=%s, sleep_im_wait=%s, last_wake_r12=%s)\n",
|
||||
mem_sleep, spm_pmic_modes, spm_allow_md1, spm_sleep_im_wait, spm_last_wake_r12);
|
||||
printf("Suspend Stats : ok=%s, fail=%s (last_failed=%s, errno=%s)\n",
|
||||
suspend_ok, suspend_fail, last_failed_dev, last_failed_errno);
|
||||
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);
|
||||
|
||||
@@ -76,6 +76,8 @@ typedef struct {
|
||||
bool low_power_standby;
|
||||
uint32_t suspend_ok_count;
|
||||
uint32_t suspend_fail_count;
|
||||
int last_suspend_errno;
|
||||
uint64_t last_suspend_ms;
|
||||
uint64_t standby_retry_ms;
|
||||
bool airplane_mode;
|
||||
bool air_prev_wifi;
|
||||
@@ -95,12 +97,23 @@ static uint64_t monotonic_ms(void) {
|
||||
return (uint64_t)ts.tv_sec * 1000ULL + (uint64_t)(ts.tv_nsec / 1000000L);
|
||||
}
|
||||
|
||||
static uint64_t boottime_ms(void) {
|
||||
struct timespec ts;
|
||||
if (clock_gettime(CLOCK_BOOTTIME, &ts) != 0) return 0;
|
||||
return (uint64_t)ts.tv_sec * 1000ULL + (uint64_t)(ts.tv_nsec / 1000000L);
|
||||
}
|
||||
|
||||
static int write_sysfs_str(const char *path, const char *val) {
|
||||
int fd = open(path, O_WRONLY | O_CLOEXEC);
|
||||
if (fd < 0) return -1;
|
||||
ssize_t w = write(fd, val, strlen(val));
|
||||
int saved_errno = errno;
|
||||
close(fd);
|
||||
return (w >= 0) ? 0 : -1;
|
||||
if (w < 0) {
|
||||
errno = saved_errno;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int read_sysfs_line(const char *path, char *buf, size_t sz) {
|
||||
@@ -1139,11 +1152,13 @@ static bool wait_post_resume_lid_events(powerd_ctx_t *ctx, bool was_lid_closed,
|
||||
if (!ctx->policy.lid_closed && was_lid_closed) saw_wake_input = true;
|
||||
} else if ((iev.type == EV_KEY && iev.value != 0) ||
|
||||
iev.type == EV_REL || iev.type == EV_ABS) {
|
||||
if (!ctx->policy.lid_closed) {
|
||||
ctx->last_input_ms = monotonic_ms();
|
||||
saw_wake_input = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
refresh_lid_state(ctx);
|
||||
if (was_lid_closed && !ctx->policy.lid_closed) saw_wake_input = true;
|
||||
if (saw_wake_input) break;
|
||||
@@ -1247,14 +1262,22 @@ static void trigger_suspend(powerd_ctx_t *ctx) {
|
||||
prepare_cpus_for_suspend();
|
||||
bool can_deep = can_enter_deep_mem_sleep(ctx);
|
||||
bool suspended = false;
|
||||
uint64_t slept_ms = 0;
|
||||
if (can_deep) {
|
||||
write_sysfs_str("/sys/power/mem_sleep", "deep");
|
||||
uint64_t bt_before = boottime_ms();
|
||||
suspended = (write_sysfs_str("/sys/power/state", "mem") == 0);
|
||||
int susp_errno = errno;
|
||||
uint64_t bt_after = boottime_ms();
|
||||
slept_ms = (bt_after >= bt_before) ? (bt_after - bt_before) : 0;
|
||||
if (suspended) {
|
||||
ctx->suspend_ok_count++;
|
||||
ctx->standby_retry_ms = 0;
|
||||
ctx->last_suspend_errno = 0;
|
||||
ctx->last_suspend_ms = slept_ms;
|
||||
} else {
|
||||
ctx->suspend_fail_count++;
|
||||
ctx->last_suspend_errno = susp_errno;
|
||||
ctx->last_suspend_ms = 0;
|
||||
}
|
||||
}
|
||||
if (!suspended) {
|
||||
@@ -1287,7 +1310,7 @@ static void trigger_suspend(powerd_ctx_t *ctx) {
|
||||
bool want_resleep_open = !was_lid_closed && !ctx->policy.lid_closed && !saw_wake_input &&
|
||||
!ctx->policy.on_ac_power && !ctx->policy.hdmi_connected &&
|
||||
ctx->policy.inhibit_count == 0;
|
||||
bool want_resleep_closed = ctx->policy.lid_closed && !saw_wake_input &&
|
||||
bool want_resleep_closed = ctx->policy.lid_closed &&
|
||||
geminux_should_suspend_on_lid(&ctx->policy);
|
||||
bool quiet_timer_resleep = suspended && !ctx->suspend_ebusy_on_ac &&
|
||||
(want_resleep_closed || want_resleep_open);
|
||||
@@ -1297,7 +1320,6 @@ static void trigger_suspend(powerd_ctx_t *ctx) {
|
||||
restore_cpus_after_resume(ctx);
|
||||
} else {
|
||||
ctx->low_power_standby = true;
|
||||
ctx->standby_retry_ms = 0;
|
||||
}
|
||||
if (!quiet_timer_resleep &&
|
||||
(!ctx->policy.lid_closed || !geminux_should_suspend_on_lid(&ctx->policy) ||
|
||||
@@ -1313,7 +1335,14 @@ static void trigger_suspend(powerd_ctx_t *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);
|
||||
uint64_t delay_ms = modem_wake ? 3500 : 300;
|
||||
if (!modem_wake && slept_ms < 5000) {
|
||||
ctx->standby_retry_ms = next_standby_retry_ms(ctx->standby_retry_ms);
|
||||
delay_ms = ctx->standby_retry_ms;
|
||||
} else {
|
||||
ctx->standby_retry_ms = 0;
|
||||
}
|
||||
arm_timer_ms(ctx->tmr_fd, delay_ms);
|
||||
} else {
|
||||
toggle_backlight(ctx, false);
|
||||
ctx->idle_stage = IDLE_STAGE_LOCKED_BLANK;
|
||||
@@ -1424,7 +1453,8 @@ static void handle_client_cmd(powerd_ctx_t *ctx, int cfd) {
|
||||
} else if (strcmp(buf, "status") == 0) {
|
||||
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",
|
||||
"airplane=%d standby=%d suspend_ok=%u suspend_fail=%u "
|
||||
"last_errno=%d last_sleep_ms=%llu\n",
|
||||
geminux_policy_profile_name(ctx->policy.profile),
|
||||
ctx->policy.on_ac_power ? 1 : 0,
|
||||
ctx->policy.hdmi_connected ? 1 : 0,
|
||||
@@ -1434,7 +1464,9 @@ static void handle_client_cmd(powerd_ctx_t *ctx, int cfd) {
|
||||
ctx->airplane_mode ? 1 : 0,
|
||||
ctx->low_power_standby ? 1 : 0,
|
||||
ctx->suspend_ok_count,
|
||||
ctx->suspend_fail_count);
|
||||
ctx->suspend_fail_count,
|
||||
ctx->last_suspend_errno,
|
||||
(unsigned long long)ctx->last_suspend_ms);
|
||||
} else {
|
||||
dprintf(cfd, "ERR unknown command\n");
|
||||
}
|
||||
@@ -1475,6 +1507,7 @@ static int setup_uevent_socket(void) {
|
||||
}
|
||||
|
||||
static void handle_lid_closed(powerd_ctx_t *ctx) {
|
||||
refresh_ac_and_hdmi(ctx);
|
||||
lock_x11_session();
|
||||
evaluate_idle(ctx);
|
||||
if (geminux_should_suspend_on_lid(&ctx->policy)) {
|
||||
|
||||
Reference in new issue
Block a user