- kernel: add 0013-gemini-pmic-wake-and-spm-safety.patch to arm MT6397/MT6351 wake IRQs in late suspend and enable PCM WDT, IM wait, and CNTP backstop on s.sleep - geminux-powerd: distinguish real input/lid-open wakes from spurious open-lid wakes and re-suspend cleanly on battery timer wakes - DE/WM: backport systray (32-bit ARGB, XEmbed race fix, lockscreen stacking), NETWM/EWMH/ICCCM and Wine/DXVK focus fixes, bar drawing fixes, and live Xresources reload across dwm, drw, st, libgemui, geminux-apply-theme, and geminux-session - themes: backport Anodized.xth, geminux-xth.h, and interactive geminux-themes editor/importer (--install), rebuild prebuilt binaries/kernel modules, and update verification scripts
310 lines
9.0 KiB
Diff
310 lines
9.0 KiB
Diff
--- a/include/linux/mfd/mt6397/core.h
|
|
+++ b/include/linux/mfd/mt6397/core.h
|
|
@@ -8,7 +8,6 @@
|
|
#define __MFD_MT6397_CORE_H__
|
|
|
|
#include <linux/mutex.h>
|
|
-#include <linux/notifier.h>
|
|
|
|
enum chip_id {
|
|
MT6323_CHIP_ID = 0x23,
|
|
@@ -63,7 +62,6 @@
|
|
struct mt6397_chip {
|
|
struct device *dev;
|
|
struct regmap *regmap;
|
|
- struct notifier_block pm_nb;
|
|
int irq;
|
|
struct irq_domain *irq_domain;
|
|
struct mutex irqlock;
|
|
@@ -79,5 +77,7 @@
|
|
|
|
int mt6358_irq_init(struct mt6397_chip *chip);
|
|
int mt6397_irq_init(struct mt6397_chip *chip);
|
|
+int mt6397_irq_suspend(struct mt6397_chip *chip);
|
|
+int mt6397_irq_resume(struct mt6397_chip *chip);
|
|
|
|
#endif /* __MFD_MT6397_CORE_H__ */
|
|
--- a/drivers/mfd/mt6397-irq.c
|
|
+++ b/drivers/mfd/mt6397-irq.c
|
|
@@ -8,7 +8,6 @@
|
|
#include <linux/module.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/regmap.h>
|
|
-#include <linux/suspend.h>
|
|
#include <linux/mfd/mt6323/core.h>
|
|
#include <linux/mfd/mt6323/registers.h>
|
|
#include <linux/mfd/mt6328/core.h>
|
|
@@ -131,34 +130,42 @@
|
|
.map = mt6397_irq_domain_map,
|
|
};
|
|
|
|
-static int mt6397_irq_pm_notifier(struct notifier_block *notifier,
|
|
- unsigned long pm_event, void *unused)
|
|
+int mt6397_irq_suspend(struct mt6397_chip *chip)
|
|
{
|
|
- struct mt6397_chip *chip =
|
|
- container_of(notifier, struct mt6397_chip, pm_nb);
|
|
unsigned int i;
|
|
|
|
- switch (pm_event) {
|
|
- case PM_SUSPEND_PREPARE:
|
|
- for (i = 0; i < chip->num_irq_regs; i++)
|
|
- regmap_write(chip->regmap, chip->int_con[i],
|
|
- chip->wake_mask[i]);
|
|
- enable_irq_wake(chip->irq);
|
|
- break;
|
|
+ if (!chip || !chip->num_irq_regs)
|
|
+ return 0;
|
|
|
|
- case PM_POST_SUSPEND:
|
|
- for (i = 0; i < chip->num_irq_regs; i++)
|
|
- regmap_write(chip->regmap, chip->int_con[i],
|
|
- chip->irq_masks_cur[i]);
|
|
- disable_irq_wake(chip->irq);
|
|
- break;
|
|
+ /* Apply wake_mask in suspend_late after all child .suspend() hooks arm IRQs */
|
|
+ mutex_lock(&chip->irqlock);
|
|
+ for (i = 0; i < chip->num_irq_regs; i++)
|
|
+ regmap_write(chip->regmap, chip->int_con[i],
|
|
+ chip->wake_mask[i]);
|
|
+ mutex_unlock(&chip->irqlock);
|
|
+ enable_irq_wake(chip->irq);
|
|
|
|
- default:
|
|
- break;
|
|
- }
|
|
+ return 0;
|
|
+}
|
|
+EXPORT_SYMBOL_GPL(mt6397_irq_suspend);
|
|
|
|
- return NOTIFY_DONE;
|
|
+int mt6397_irq_resume(struct mt6397_chip *chip)
|
|
+{
|
|
+ unsigned int i;
|
|
+
|
|
+ if (!chip || !chip->num_irq_regs)
|
|
+ return 0;
|
|
+
|
|
+ disable_irq_wake(chip->irq);
|
|
+ mutex_lock(&chip->irqlock);
|
|
+ for (i = 0; i < chip->num_irq_regs; i++)
|
|
+ regmap_write(chip->regmap, chip->int_con[i],
|
|
+ chip->irq_masks_cur[i]);
|
|
+ mutex_unlock(&chip->irqlock);
|
|
+
|
|
+ return 0;
|
|
}
|
|
+EXPORT_SYMBOL_GPL(mt6397_irq_resume);
|
|
|
|
int mt6397_irq_init(struct mt6397_chip *chip)
|
|
{
|
|
@@ -220,7 +227,6 @@
|
|
for (i = 0; i < chip->num_irq_regs; i++)
|
|
regmap_write(chip->regmap, chip->int_con[i], 0x0);
|
|
|
|
- chip->pm_nb.notifier_call = mt6397_irq_pm_notifier;
|
|
chip->irq_domain = irq_domain_create_linear(dev_fwnode(chip->dev),
|
|
chip->num_irq_regs * 16,
|
|
&mt6397_irq_domain_ops, chip);
|
|
@@ -239,6 +245,5 @@
|
|
return ret;
|
|
}
|
|
|
|
- register_pm_notifier(&chip->pm_nb);
|
|
return 0;
|
|
}
|
|
--- a/drivers/mfd/mt6397-core.c
|
|
+++ b/drivers/mfd/mt6397-core.c
|
|
@@ -10,6 +10,7 @@
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/platform_device.h>
|
|
+#include <linux/pm.h>
|
|
#include <linux/regmap.h>
|
|
#include <linux/mfd/core.h>
|
|
#include <linux/mfd/mt6323/core.h>
|
|
@@ -512,11 +513,30 @@
|
|
};
|
|
MODULE_DEVICE_TABLE(platform, mt6397_id);
|
|
|
|
+static int mt6397_suspend_late(struct device *dev)
|
|
+{
|
|
+ struct mt6397_chip *chip = dev_get_drvdata(dev);
|
|
+
|
|
+ return mt6397_irq_suspend(chip);
|
|
+}
|
|
+
|
|
+static int mt6397_resume_early(struct device *dev)
|
|
+{
|
|
+ struct mt6397_chip *chip = dev_get_drvdata(dev);
|
|
+
|
|
+ return mt6397_irq_resume(chip);
|
|
+}
|
|
+
|
|
+static const struct dev_pm_ops mt6397_pm_ops = {
|
|
+ LATE_SYSTEM_SLEEP_PM_OPS(mt6397_suspend_late, mt6397_resume_early)
|
|
+};
|
|
+
|
|
static struct platform_driver mt6397_driver = {
|
|
.probe = mt6397_probe,
|
|
.driver = {
|
|
.name = "mt6397",
|
|
.of_match_table = mt6397_of_match,
|
|
+ .pm = pm_sleep_ptr(&mt6397_pm_ops),
|
|
},
|
|
.id_table = mt6397_id,
|
|
};
|
|
--- a/drivers/soc/mediatek/mt6797-spm-sleep.c
|
|
+++ b/drivers/soc/mediatek/mt6797-spm-sleep.c
|
|
@@ -161,6 +161,7 @@
|
|
#define PCM_FSM_IM_STATE(v) (((v) >> 7) & 7)
|
|
/* How long the IM fetch may take before the PCM kick (D5q) */
|
|
#define SODI_IM_WAIT_US 200
|
|
+#define SLEEP_IM_WAIT_US 1000
|
|
#define PCM_RF_SYNC_R0 BIT(16)
|
|
#define PCM_RF_SYNC_R7 BIT(23)
|
|
#define PCM_PWRIO_R0_R7 0x81
|
|
@@ -179,8 +180,8 @@
|
|
#define S1_FLAGS 0x000902b1
|
|
#define FLAG_EN_SEGMENT2 BIT(18)
|
|
|
|
-/* Wake sources: PCM timer and EINT */
|
|
-#define S1_WAKE_SRC (BIT(0) | BIT(6))
|
|
+/* Wake sources: PCM timer, EINT, and PCM watchdog safety wake */
|
|
+#define S1_WAKE_SRC (BIT(0) | BIT(6) | WAKE_PCM_WDT)
|
|
|
|
/*
|
|
* The vendor's MT6797 SODI wake sources (WAKE_SRC_FOR_SODI, D4): PCM timer,
|
|
@@ -410,6 +411,8 @@
|
|
bool im_reuse; /* IM slave mode when the program is resident (D5q) */
|
|
bool r7_vendor; /* r7 starts from SPM_R7_VENDOR (D5r) */
|
|
bool vec_clear; /* PCM_EVENT_VECTOR_EN 0 before the kick (D5r) */
|
|
+ u32 im_wait_us; /* wait budget for IM fetch settle */
|
|
+ u32 backstop_ms; /* CPU0 physical timer backstop margin */
|
|
bool ready;
|
|
};
|
|
|
|
@@ -1027,7 +1030,8 @@
|
|
v = PCM_TIMER_EN;
|
|
if (sc->pcm_wdt) {
|
|
wdt_val = spm_rd(PCM_WDT_VAL);
|
|
- spm_wr(PCM_WDT_VAL, sc->ticks + SODI_PCM_WDT_MARGIN);
|
|
+ spm_wr(PCM_WDT_VAL,
|
|
+ min_t(u64, (u64)sc->ticks + SODI_PCM_WDT_MARGIN, U32_MAX));
|
|
v |= PCM_WDT_BITS;
|
|
}
|
|
spm_wr(PCM_CON1, spm_rd(PCM_CON1) | SPM_KEY | v);
|
|
@@ -1053,26 +1057,31 @@
|
|
spm_wr(SPM_CLK_CON, spm_rd(SPM_CLK_CON) | SPM_LOCK_INFRA_DCM);
|
|
|
|
/* D5q: has the IM fetch settled? Refuse the period if not */
|
|
- for (i = 0; ; i++) {
|
|
- s.wake.im_fsm1 = spm_rd(PCM_FSM_STA);
|
|
- if (!sc->im_wait || i >= SODI_IM_WAIT_US ||
|
|
- PCM_FSM_IM_STATE(s.wake.im_fsm1) ==
|
|
- PCM_FSM_IM_STATE(PCM_FSM_STA_DEF))
|
|
- break;
|
|
- udelay(1);
|
|
- }
|
|
- s.wake.im_us = i;
|
|
- if (sc->im_wait && i >= SODI_IM_WAIT_US) {
|
|
- s.wake.im_stuck = true;
|
|
- spm_restore();
|
|
- if (sc->pcm_wdt) {
|
|
- spm_wr(PCM_CON1, SPM_KEY | (spm_rd(PCM_CON1) & ~PCM_WDT_BITS) | con1);
|
|
- spm_wr(PCM_WDT_VAL, wdt_val);
|
|
+ {
|
|
+ u32 im_lim = sc->im_wait_us ? sc->im_wait_us : SODI_IM_WAIT_US;
|
|
+
|
|
+ for (i = 0; ; i++) {
|
|
+ s.wake.im_fsm1 = spm_rd(PCM_FSM_STA);
|
|
+ if (!sc->im_wait || i >= im_lim ||
|
|
+ PCM_FSM_IM_STATE(s.wake.im_fsm1) ==
|
|
+ PCM_FSM_IM_STATE(PCM_FSM_STA_DEF))
|
|
+ break;
|
|
+ udelay(1);
|
|
+ }
|
|
+ s.wake.im_us = i;
|
|
+ if (sc->im_wait && i >= im_lim) {
|
|
+ s.wake.im_stuck = true;
|
|
+ spm_restore();
|
|
+ if (sc->pcm_wdt) {
|
|
+ spm_wr(PCM_CON1,
|
|
+ SPM_KEY | (spm_rd(PCM_CON1) & ~PCM_WDT_BITS) | con1);
|
|
+ spm_wr(PCM_WDT_VAL, wdt_val);
|
|
+ }
|
|
+ writel(axi[0], s.mcucfg + MP0_AXI_CONFIG);
|
|
+ writel(axi[1], s.mcucfg + MP1_AXI_CONFIG);
|
|
+ writel(axi[2], s.mcucfg + MP2_AXI_CONFIG);
|
|
+ return -ETIMEDOUT;
|
|
}
|
|
- writel(axi[0], s.mcucfg + MP0_AXI_CONFIG);
|
|
- writel(axi[1], s.mcucfg + MP1_AXI_CONFIG);
|
|
- writel(axi[2], s.mcucfg + MP2_AXI_CONFIG);
|
|
- return -ETIMEDOUT;
|
|
}
|
|
|
|
if (sc->vec_clear)
|
|
@@ -1111,17 +1120,18 @@
|
|
s.gicd + GICD_ISENABLER + 4 * (SPM_GIC_INTID / 32));
|
|
|
|
/*
|
|
- * SODI: CPU0's physical timer is a backstop, 100 ms after the PCM timer
|
|
- * should end the period, so a program that never returns leaves CPU0
|
|
- * able to record its state instead of waiting for ever (D5i). Its PPI
|
|
- * stays enabled through the GIC mask.
|
|
+ * CPU0's physical timer is a backstop after when the PCM timer should
|
|
+ * end the period (100 ms for SODI, 5 s for mem suspend), so a program
|
|
+ * that never returns leaves CPU0 able to record its state instead of
|
|
+ * waiting for ever (D5i). Its PPI stays enabled through the GIC mask.
|
|
*/
|
|
- if (sc->cirq) {
|
|
+ if (sc->backstop_ms) {
|
|
cntp_cval = read_sysreg(cntp_cval_el0);
|
|
cntp_ctl = read_sysreg(cntp_ctl_el0);
|
|
write_sysreg(__arch_counter_get_cntpct() +
|
|
mul_u64_u64_div_u64(sc->ticks, arch_timer_get_cntfrq(), 32768) +
|
|
- arch_timer_get_cntfrq() / 10, cntp_cval_el0);
|
|
+ mul_u64_u64_div_u64(sc->backstop_ms, arch_timer_get_cntfrq(), MSEC_PER_SEC),
|
|
+ cntp_cval_el0);
|
|
write_sysreg(ARCH_TIMER_CTRL_ENABLE, cntp_ctl_el0);
|
|
isb();
|
|
}
|
|
@@ -1139,14 +1149,14 @@
|
|
s.im_resident = sc->im_ptr;
|
|
break;
|
|
}
|
|
- if (sc->cirq && (read_sysreg(cntp_ctl_el0) & ARCH_TIMER_CTRL_IT_STAT)) {
|
|
+ if (sc->backstop_ms && (read_sysreg(cntp_ctl_el0) & ARCH_TIMER_CTRL_IT_STAT)) {
|
|
s.wake.backstop = true;
|
|
break;
|
|
}
|
|
}
|
|
if (sc->idle)
|
|
ct_cpuidle_exit();
|
|
- if (sc->cirq) {
|
|
+ if (sc->backstop_ms) {
|
|
write_sysreg(cntp_ctl, cntp_ctl_el0);
|
|
write_sysreg(cntp_cval, cntp_cval_el0);
|
|
isb();
|
|
@@ -2093,6 +2103,10 @@
|
|
s.sleep.flags = s.flags;
|
|
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_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);
|
|
if (ret)
|
|
goto err;
|
|
@@ -2102,6 +2116,8 @@
|
|
s.sodi.src2_mask = 0x08ff009f;
|
|
s.sodi.wfi_count = 8;
|
|
s.sodi.cirq = true;
|
|
+ s.sodi.im_wait_us = SODI_IM_WAIT_US;
|
|
+ s.sodi.backstop_ms = 100;
|
|
s.cirq = ioremap(CIRQ_PHYS, 0x400);
|
|
s.afe = ioremap(AFE_PHYS, 0x1000);
|
|
np = of_find_compatible_node(NULL, NULL, "mediatek,mt6797-audio");
|