From a0d642cc823d9dd3cd85632a2d58cae80b9e69f4 Mon Sep 17 00:00:00 2001 From: WJW Date: Thu, 26 Nov 2026 14:43:00 +0800 Subject: [PATCH 01/23] thunderbolt: apple: tear down T8112 ACIO routers for deep sleep Signed-off-by: WJW --- drivers/thunderbolt/apple.c | 18 +++++++++++++ tools/asahi/pciec-policy-tests.py | 42 +++++++++++++++++-------------- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index cbd3a0453cf04..06ff41871c349 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -210,6 +210,20 @@ static const struct apple_cio_hw apple_cio_t8103_hw = { .dp = &apple_dpin_m1, }; +/* + * T8112 (M2) shares the T8103 ACIO register layout and DP IN policy, while + * deep sleep removes the CIO power domains and shares the ATC PHY with DWC3. + * Tear down a connected router before tasks freeze (ahead of DWC3's PM + * notifier) and request fresh cable state immediately on wake; s2idle and + * freeze leave the port up. + */ +static const struct apple_cio_hw apple_cio_t8112_hw = { + .sleep_removes_domains = true, + .restart_on_wake = true, + .phy_shared_with_dwc3 = true, + .dp = &apple_dpin_m1, +}; + /* * T8122 shares the T8103 ACIO register layout and DP IN policy, while deep * sleep removes the CIO power domains and shares the ATC PHY with DWC3. Tear @@ -5068,6 +5082,10 @@ static const struct of_device_id apple_acio_match[] = { .compatible = "apple,t8122-usb4-acio", .data = &apple_cio_t8122_hw, }, + { + .compatible = "apple,t8112-usb4-acio", + .data = &apple_cio_t8112_hw, + }, { .compatible = "apple,t6020-usb4-acio", .data = &apple_cio_t6020_hw, diff --git a/tools/asahi/pciec-policy-tests.py b/tools/asahi/pciec-policy-tests.py index c253f04eff9ed..e7995bc12dd09 100644 --- a/tools/asahi/pciec-policy-tests.py +++ b/tools/asahi/pciec-policy-tests.py @@ -1400,10 +1400,12 @@ def test_pm_order(out, acio): ''' -def test_t8122_cio_sleep(out, acio): +def test_shared_phy_cio_sleep(out, acio, soc): dwc = (ROOT / 'drivers/usb/dwc3/dwc3-apple.c').read_text() + hw_sym = f'apple_cio_{soc}_hw' + compat = f'apple,{soc}-usb4-acio' hw_defs = [] - for sym in ('apple_cio_t8103_hw', 'apple_cio_t8122_hw', 'apple_cio_t6020_hw'): + for sym in ('apple_cio_t8103_hw', hw_sym, 'apple_cio_t6020_hw'): m = re.search(r'^static const struct apple_cio_hw ' + sym + r' = \{.*?\n\};', acio, re.M | re.S) assert m, sym @@ -1416,10 +1418,9 @@ def test_t8122_cio_sleep(out, acio): r'\.compatible\s*=\s*"([^"]+)"\s*,\s*\.data\s*=\s*(&apple_cio_\w+_hw)', match_block.group()) match_lines = [f' {{ "{c}", {d} }},' for c, d in entries - if c in ('apple,t8122-usb4-acio', 'apple,t6020-usb4-acio', - 'apple,t8103-usb4-acio')] + if c in (compat, 'apple,t6020-usb4-acio', 'apple,t8103-usb4-acio')] assert len(match_lines) == 3, match_lines - code = T8122_SLEEP_FIXTURE + code = T8122_SLEEP_FIXTURE.replace('t8122', soc).replace('T8122', soc.upper()) code = code.replace('/* PRODUCTION_HW */', '\n'.join(hw_defs)) code = code.replace('/* MATCH_ENTRIES */', '\n'.join(match_lines)) code = code.replace('/* PRODUCTION_FN */', @@ -1431,25 +1432,27 @@ def test_t8122_cio_sleep(out, acio): dwc, 'appledwc->pm_nb.notifier_call = dwc3_apple_pm_notify;', 'ret = register_pm_notifier(&appledwc->pm_nb);')) muts = { - 't8122-drop-match': (' { "apple,t8122-usb4-acio", &apple_cio_t8122_hw },', ''), - 't8103-drop-sleep-removes-domains': ( - 'static const struct apple_cio_hw apple_cio_t8103_hw = {\n' - '\t.sleep_removes_domains = true,\n', - 'static const struct apple_cio_hw apple_cio_t8103_hw = {\n'), - 't8122-drop-sleep-removes-domains': ( - 'static const struct apple_cio_hw apple_cio_t8122_hw = {\n' + f'{soc}-drop-match': (f' {{ "{compat}", &{hw_sym} }},', ''), + f'{soc}-drop-sleep-removes-domains': ( + f'static const struct apple_cio_hw {hw_sym} = {{\n' '\t.sleep_removes_domains = true,\n', - 'static const struct apple_cio_hw apple_cio_t8122_hw = {\n'), - 't8122-drop-phy-shared': ( - 'static const struct apple_cio_hw apple_cio_t8122_hw = {\n' + f'static const struct apple_cio_hw {hw_sym} = {{\n'), + f'{soc}-drop-phy-shared': ( + f'static const struct apple_cio_hw {hw_sym} = {{\n' '\t.sleep_removes_domains = true,\n' '\t.restart_on_wake = true,\n' '\t.phy_shared_with_dwc3 = true,\n', - 'static const struct apple_cio_hw apple_cio_t8122_hw = {\n' + f'static const struct apple_cio_hw {hw_sym} = {{\n' '\t.sleep_removes_domains = true,\n' '\t.restart_on_wake = true,\n'), } - cases = {'t8122-cio-sleep': code} + if soc == 't8122': + muts['t8103-drop-sleep-removes-domains'] = ( + 'static const struct apple_cio_hw apple_cio_t8103_hw = {\n' + '\t.sleep_removes_domains = true,\n', + 'static const struct apple_cio_hw apple_cio_t8103_hw = {\n') + base_name = f'{soc}-cio-sleep' + cases = {base_name: code} for name, (old, new) in muts.items(): assert code.count(old) == 1, name cases[name] = code.replace(old, new) @@ -1460,7 +1463,7 @@ def test_t8122_cio_sleep(out, acio): str(source), '-o', str(binary)], check=True) run = subprocess.run([str(binary)], capture_output=True, text=True) (out / (name + '.log')).write_text(run.stdout + run.stderr) - if name == 't8122-cio-sleep': + if name == base_name: assert run.returncode == 0, run.stderr print(run.stdout, end='') else: @@ -1811,7 +1814,8 @@ def main(): out = args.out or Path(tmp) out.mkdir(parents=True, exist_ok=True) test_pm_order(out, acio) - test_t8122_cio_sleep(out, acio) + test_shared_phy_cio_sleep(out, acio, 't8122') + test_shared_phy_cio_sleep(out, acio, 't8112') test_cio_stop(out, acio) cases = { 'production': code, From a3d671618f5642dd03979fab0464d8e4608452e3 Mon Sep 17 00:00:00 2001 From: WJW Date: Thu, 26 Nov 2026 14:47:42 +0800 Subject: [PATCH 02/23] arm64: dts: apple: t8112: add system sleep node and enable on J413 Signed-off-by: WJW --- .../bindings/soc/apple/apple,t8140-sleep.yaml | 22 +++++++++++++++++++ arch/arm64/boot/dts/apple/t8112-j413.dts | 4 ++++ arch/arm64/boot/dts/apple/t8112.dtsi | 16 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml index d83c4e312f20e..b5ea3a203cf50 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml @@ -20,6 +20,7 @@ properties: compatible: enum: - apple,t8103-sleep + - apple,t8112-sleep - apple,t8122-sleep - apple,t8132-sleep - apple,t8140-sleep @@ -129,6 +130,27 @@ allOf: - const: cpu-start - const: wdt - const: spmi + - if: + properties: + compatible: + contains: + const: apple,t8112-sleep + then: + required: + - apple,pinctrl + properties: + reg: + minItems: 7 + maxItems: 7 + reg-names: + items: + - const: ps + - const: ps-aon + - const: clk-mux + - const: wake + - const: cpu-start + - const: wdt + - const: spmi - if: properties: compatible: diff --git a/arch/arm64/boot/dts/apple/t8112-j413.dts b/arch/arm64/boot/dts/apple/t8112-j413.dts index dfbb28b89d3bf..15c3abf6e6766 100644 --- a/arch/arm64/boot/dts/apple/t8112-j413.dts +++ b/arch/arm64/boot/dts/apple/t8112-j413.dts @@ -596,3 +596,7 @@ &hpm1 { apple,sleep-ssps; }; + +&sleep { + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index b5c6bdc54f8c8..f4a4b168525b1 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -1311,6 +1311,22 @@ /* child nodes are added in t8103-pmgr.dtsi */ }; + sleep: sleep@23b700000 { + compatible = "apple,t8112-sleep"; + reg = <0x2 0x3b700000 0x0 0xcc000>, + <0x2 0x3d280000 0x0 0x7c000>, + <0x2 0x3b000000 0x0 0x70000>, + <0x2 0x3d004000 0x0 0x48>, + <0x2 0x3b734000 0x0 0x10>, + <0x2 0x3d2b0000 0x0 0x30>, + <0x2 0x3d714000 0x0 0x100>; + reg-names = "ps", "ps-aon", "clk-mux", "wake", + "cpu-start", "wdt", "spmi"; + apple,display-coprocessors = <&dcp>; + apple,pinctrl = <&pinctrl_ap>; + status = "disabled"; + }; + cio_reset: reset-controller@23b790000 { compatible = "apple,t8112-cio-reset", "apple,t8103-cio-reset"; reg = <0x2 0x3b790000 0x0 0x8000>; From b32895f3d2c000b802d2fb897c132e73f467bcd7 Mon Sep 17 00:00:00 2001 From: WJW Date: Thu, 26 Nov 2026 14:47:42 +0800 Subject: [PATCH 03/23] soc: apple: sleep: add T8112 dry-run profile and KUnit coverage Signed-off-by: WJW --- drivers/soc/apple/sleep-t8112.h | 221 ++++++++++++++++++++++++++++++++ drivers/soc/apple/sleep-test.c | 2 + drivers/soc/apple/sleep.c | 2 + 3 files changed, 225 insertions(+) create mode 100644 drivers/soc/apple/sleep-t8112.h diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h new file mode 100644 index 0000000000000..14c81ae6bc398 --- /dev/null +++ b/drivers/soc/apple/sleep-t8112.h @@ -0,0 +1,221 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * T8112 (Apple M2) system suspend-to-RAM dry-run profile. + * + * Phase 2 bring-up profile: maps the verified T8112 PMGR, PMGR_MINI, clock mux, + * wake, CPU start, WDT, and SPMI register windows and registers the full + * T8112 PMGR power-state inventory and coprocessor gates for d1 dry-run + * validation. Physical commit is explicitly refused until Phase 3 hardware + * entry/wake sequences are verified. + */ + +#define T8112_PS_GPIO 0x120 +#define T8112_PS_SIO_CPU 0x1c0 +#define T8112_PS_DISP0_SYS 0x370 +#define T8112_PS_DISP0_FE 0x378 +#define T8112_PS_APCIE_GP 0x400 +#define T8112_PS_ANS 0x428 +#define T8112_PS_GFX 0x430 +#define T8112_PS_APCIE_ST 0x450 +#define T8112_PS_SEP 0xc00 +#define T8112_PS_DISP0_CPU0 0x10000 + +#define T8112_AON_DEBUG_SWITCH 0xb8 + +/* Every PMGR power-state word in the T8112 device tree (t8112-pmgr.dtsi). */ +static const u32 t8112_ps_all[] = { + 0x100, 0x108, 0x110, 0x118, 0x120, 0x128, 0x130, 0x160, 0x168, 0x170, + 0x178, 0x180, 0x188, 0x190, 0x198, 0x1a0, 0x1a8, 0x1b0, 0x1b8, 0x1c0, + 0x1c8, 0x1d0, 0x1d8, 0x1e0, 0x1e8, 0x1f0, 0x1f8, 0x200, 0x208, 0x210, + 0x218, 0x220, 0x228, 0x230, 0x238, 0x240, 0x248, 0x250, 0x258, 0x260, + 0x268, 0x270, 0x278, 0x280, 0x288, 0x290, 0x298, 0x2a0, 0x2a8, 0x2b0, + 0x2b8, 0x2c0, 0x2c8, 0x2d0, 0x2d8, 0x2e0, 0x2e8, 0x2f0, 0x2f8, 0x300, + 0x308, 0x310, 0x318, 0x320, 0x328, 0x330, 0x338, 0x340, 0x348, 0x350, + 0x358, 0x360, 0x368, 0x370, 0x378, 0x380, 0x388, 0x3c8, 0x3d8, 0x3e0, + 0x3e8, 0x3f0, 0x3f8, 0x400, 0x408, 0x410, 0x418, 0x420, 0x428, 0x430, + 0x438, 0x440, 0x448, 0x450, 0x458, 0x460, 0x468, 0x470, 0x478, 0x480, + 0x488, 0x490, 0x498, 0x4a0, 0x4a8, 0x4b0, 0xc00, 0x4000, 0x4008, 0x4010, + 0x4018, 0x4020, 0x4028, 0x4030, 0x4038, 0x4040, 0x4048, 0x4050, 0x4058, + 0x4060, 0x8000, 0x8008, 0x8010, 0x8018, 0x8020, 0xc008, 0xc010, 0xc018, + 0xc020, 0xc028, 0xc030, 0xc038, 0x10000, +}; + +/* Every PMGR_MINI (ps-aon) power-state word in t8112-pmgr.dtsi. */ +static const u32 t8112_ps_aon_all[] = { + 0x58, 0x60, 0x68, 0x70, 0x78, 0x80, 0x88, 0x90, 0x98, 0xa0, 0xa8, 0xb0, + 0xb8, +}; + +static struct { + void __iomem *clk_mux; +} t8112; + +static void __iomem *t8112_map(struct apple_sleep *s, const char *name, struct resource *out) +{ + struct device_node *np = s->dev->of_node; + struct resource res; + void __iomem *base; + int index; + + index = of_property_match_string(np, "reg-names", name); + if (index < 0) + return IOMEM_ERR_PTR(index); + if (of_address_to_resource(np, index, &res)) + return IOMEM_ERR_PTR(-EINVAL); + base = ioremap_np(res.start, resource_size(&res)); + if (!base) + return IOMEM_ERR_PTR(-ENOMEM); + if (out) + *out = res; + + return base; +} + +static int t8112_sleep_map_regs(struct apple_sleep *s) +{ + static const struct { + const char *name; + size_t offset; + } regs[] = { + { "ps-aon", offsetof(struct apple_sleep, ps_aon) }, + { "wake", offsetof(struct apple_sleep, wake) }, + { "cpu-start", offsetof(struct apple_sleep, cpu_start) }, + { "wdt", offsetof(struct apple_sleep, wdt) }, + { "spmi", offsetof(struct apple_sleep, spmi) }, + }; + unsigned int i; + + s->ps = t8112_map(s, "ps", &s->ps_res); + if (IS_ERR(s->ps)) + return dev_err_probe(s->dev, PTR_ERR(s->ps), "no ps registers\n"); + for (i = 0; i < ARRAY_SIZE(regs); i++) { + void __iomem **field = (void __iomem **)((u8 *)s + regs[i].offset); + + *field = t8112_map(s, regs[i].name, NULL); + if (IS_ERR(*field)) + return dev_err_probe(s->dev, PTR_ERR(*field), "no %s registers\n", + regs[i].name); + } + t8112.clk_mux = t8112_map(s, "clk-mux", NULL); + if (IS_ERR(t8112.clk_mux)) + return dev_err_probe(s->dev, PTR_ERR(t8112.clk_mux), "no clk-mux registers\n"); + + s->driver_down = devm_bitmap_zalloc(s->dev, resource_size(&s->ps_res) / 4, GFP_KERNEL); + if (!s->driver_down) + return -ENOMEM; + if (apple_sleep_alloc_books(s)) + return -ENOMEM; + + return 0; +} + +static int t8112_sleep_check(struct apple_sleep *s) +{ + if (!apple_sleep_dry(s)) { + dev_err(s->dev, + "T8112: physical sleep commit not yet implemented; run dry-run only\n"); + return -EOPNOTSUPP; + } + return 0; +} + +static int t8112_sleep_display_off(struct apple_sleep *s) +{ + return 0; +} + +static void t8112_sleep_prepare_regs(struct apple_sleep *s) +{ +} + +static void t8112_sleep_undo_regs(struct apple_sleep *s) +{ +} + +static void t8112_sleep_commit_regs(struct apple_sleep *s) +{ +} + +static void t8112_sleep_wake(struct apple_sleep *s) +{ +} + +static void t8112_aic_mask_noop(void) +{ +} + +static void t8112_deep_wfi_arm(void) +{ +} + +static int t8112_sleep_cpu_prepare(u64 mpidr) +{ + return 0; +} + +static void t8112_sleep_cpu_restore(u64 mpidr) +{ +} + +static const struct apple_sleep_gate_coproc t8112_gate_coprocs[] = { + { "/soc/dcp@231c00000", true, T8112_PS_DISP0_CPU0 }, + { "/soc/pmp@23b500000", true }, + { "/soc/gpu@206400000", true, T8112_PS_GFX }, + { "/soc/sep@25e400000" }, + { "/soc/nvme@27bcc0000" }, + { "/soc/smc@23e400000" }, +}; + +static const struct apple_sleep_ops t8112_sleep_ops = { + .deep_wfi_arm = t8112_deep_wfi_arm, + .resume = cpu_resume, + .aic_mask_all = t8112_aic_mask_noop, + .aic_ack = aic_sleep_ack, + .aic_restore = aic_sleep_restore, + .map_regs = t8112_sleep_map_regs, + .check = t8112_sleep_check, + .display_off = t8112_sleep_display_off, + .prepare_regs = t8112_sleep_prepare_regs, + .undo_regs = t8112_sleep_undo_regs, + .commit_regs = t8112_sleep_commit_regs, + .wake = t8112_sleep_wake, + .cpu_prepare = t8112_sleep_cpu_prepare, + .cpu_restore = t8112_sleep_cpu_restore, +}; + +static const struct apple_sleep_soc t8112_sleep_soc = { + .ops = &t8112_sleep_ops, + .untested = true, + .early_context = true, + .no_pmu_notes = true, + .no_wd2 = true, + .display_no_restart = true, + .boot_mpidr = 0x0, + .cpu_count = 8, + .cpu_clusters = 2, + .cpu_cores_per_cluster = 4, + .cpu_start_stride = 4, + .cluster_cpu = { 0x0, 0x4 }, + .ncluster_cpu = 2, + .ndisp = 1, + .nmcc = 4, + .pmu_usid = 0xe, + .wake_mask = 0x08, + .wake_status = 0x24, + .wake_words = 7, + .wake_last_word = GENMASK(16, 0), + .ps_aon_debug_switch = T8112_AON_DEBUG_SWITCH, + .ps = { + .disp = { { T8112_PS_DISP0_CPU0, T8112_PS_DISP0_FE, T8112_PS_DISP0_SYS } }, + .sio_cpu = T8112_PS_SIO_CPU, + .sep = T8112_PS_SEP, + .gpio = T8112_PS_GPIO, + .ans = T8112_PS_ANS, + .apcie_gp = T8112_PS_APCIE_GP, + .apcie_st = T8112_PS_APCIE_ST, + }, + .ps_all = SLEEP_WORDS(t8112_ps_all), + .ps_aon_all = SLEEP_WORDS(t8112_ps_aon_all), + .gate_coprocs = t8112_gate_coprocs, + .ngate_coprocs = ARRAY_SIZE(t8112_gate_coprocs), +}; diff --git a/drivers/soc/apple/sleep-test.c b/drivers/soc/apple/sleep-test.c index f829f58ae804d..aed1ae4ae880c 100644 --- a/drivers/soc/apple/sleep-test.c +++ b/drivers/soc/apple/sleep-test.c @@ -14,6 +14,7 @@ static const char *const apple_sleep_test_profiles[] = { "apple,t6050-sleep", "apple,t6050-j716c-sleep", "apple,t8103-sleep", + "apple,t8112-sleep", "apple,t8122-sleep", }; @@ -72,6 +73,7 @@ static void apple_sleep_test_known_profiles(struct kunit *test) KUNIT_ASSERT_LT(test, n, ARRAY_SIZE(apple_sleep_test_profiles)); KUNIT_EXPECT_STREQ(test, id->compatible, apple_sleep_test_profiles[n]); if (!strcmp(id->compatible, "apple,t8142-sleep") || + !strcmp(id->compatible, "apple,t8112-sleep") || !strcmp(id->compatible, "apple,t8122-sleep")) { const struct apple_sleep_soc *soc = id->data; diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 611fe3de6e1e9..8670bf8018cd0 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -10162,6 +10162,7 @@ static const struct apple_sleep_soc t8142_sleep_soc = { }; #include "sleep-t8103.h" +#include "sleep-t8112.h" #include "sleep-t8122.h" /* @@ -10177,6 +10178,7 @@ static const struct of_device_id apple_sleep_of_match[] = { { .compatible = "apple,t6050-sleep", .data = &t6050_sleep_soc }, { .compatible = "apple,t6050-j716c-sleep", .data = &t6050_j716c_sleep_soc }, { .compatible = "apple,t8103-sleep", .data = &t8103_sleep_soc }, + { .compatible = "apple,t8112-sleep", .data = &t8112_sleep_soc }, { .compatible = "apple,t8122-sleep", .data = &t8122_sleep_soc }, { } }; From 46f535a83f5910999ec27d48e347ce9db21975ea Mon Sep 17 00:00:00 2001 From: WJW Date: Thu, 26 Nov 2026 15:37:50 +0800 Subject: [PATCH 04/23] soc: apple: pmp: add T8112 SRAM backup fallback config Signed-off-by: WJW --- drivers/soc/apple/pmp.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/soc/apple/pmp.rs b/drivers/soc/apple/pmp.rs index 00795a75a035e..26ba609606d8f 100644 --- a/drivers/soc/apple/pmp.rs +++ b/drivers/soc/apple/pmp.rs @@ -1052,6 +1052,14 @@ const HW_CFG_T6050: PmpHwConfig = PmpHwConfig { confirm_ioreg_len: false, }; +/// T8112 (M2): the sleep engine reloads `__TEXT` from DRAM at the wake, and only `__DATA` +/// (the ADT's second segment, offset 0x2f000, size 0x46000 on J413) has to be kept. When the +/// boot loader supplies `apple,sram-keep`, both offset and size come from the DT instead. +const HW_CFG_T8112: PmpHwConfig = PmpHwConfig { + sram_backup: Some((0x2f000, 0x46000)), + ..HW_CFG_DEFAULT +}; + /// T8122: the sleep engine reloads `__TEXT` from DRAM at the wake, and only `__DATA` /// (the ADT's second segment, offset 0x36000, size 0x47000) has to be kept. When the /// boot loader supplies `apple,sram-keep`, both offset and size come from the DT instead. @@ -1085,6 +1093,7 @@ kernel::of_device_table!( OF_TABLE, ::IdInfo, [ + (of::DeviceId::new(c"apple,t8112-pmp-v2"), &HW_CFG_T8112), (of::DeviceId::new(c"apple,t8122-pmp-v2"), &HW_CFG_T8122), (of::DeviceId::new(c"apple,t8132-pmp-v2"), &HW_CFG_T8132), (of::DeviceId::new(c"apple,t8140-pmp-v2"), &HW_CFG_T8140), From e827507e7480b5a0ea515f310afd5f46fa96be37 Mon Sep 17 00:00:00 2001 From: WJW Date: Thu, 26 Nov 2026 15:37:50 +0800 Subject: [PATCH 05/23] soc: apple: sleep: wire T8112 PMU boot-stage and PMGR wake order Signed-off-by: WJW --- drivers/soc/apple/sleep-t8112.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h index 14c81ae6bc398..c719e1012697a 100644 --- a/drivers/soc/apple/sleep-t8112.h +++ b/drivers/soc/apple/sleep-t8112.h @@ -9,17 +9,28 @@ * entry/wake sequences are verified. */ +#define T8112_PS_SBR 0x100 +#define T8112_PS_AIC 0x108 +#define T8112_PS_DWI 0x110 #define T8112_PS_GPIO 0x120 #define T8112_PS_SIO_CPU 0x1c0 +#define T8112_PS_APCIE 0x348 #define T8112_PS_DISP0_SYS 0x370 #define T8112_PS_DISP0_FE 0x378 #define T8112_PS_APCIE_GP 0x400 #define T8112_PS_ANS 0x428 #define T8112_PS_GFX 0x430 #define T8112_PS_APCIE_ST 0x450 +#define T8112_PS_ATC0_COMMON 0x458 +#define T8112_PS_ATC1_COMMON 0x480 #define T8112_PS_SEP 0xc00 #define T8112_PS_DISP0_CPU0 0x10000 +#define T8112_AON_ATC0_USB_AON 0x88 +#define T8112_AON_ATC1_USB_AON 0x90 +#define T8112_AON_ATC0_USB 0x98 +#define T8112_AON_ATC1_USB 0xa0 +#define T8112_AON_NUB_FABRIC 0xa8 #define T8112_AON_DEBUG_SWITCH 0xb8 /* Every PMGR power-state word in the T8112 device tree (t8112-pmgr.dtsi). */ @@ -46,6 +57,17 @@ static const u32 t8112_ps_aon_all[] = { 0xb8, }; +/* Parent-first wake order for core, PCIe/ANS, and ATC domains (t8112-pmgr.dtsi). */ +static const u32 t8112_ps_wake_order[] = { + T8112_PS_SEP, T8112_PS_SBR, T8112_PS_AIC, T8112_PS_DWI, T8112_PS_GPIO, + T8112_PS_APCIE, T8112_PS_ANS, T8112_PS_APCIE_GP, T8112_PS_APCIE_ST, + T8112_PS_ATC0_COMMON, T8112_PS_ATC1_COMMON, +}; + +static const u32 t8112_ps_aon_wake_order[] = { + T8112_AON_NUB_FABRIC, T8112_AON_ATC0_USB_AON, T8112_AON_ATC1_USB_AON, +}; + static struct { void __iomem *clk_mux; } t8112; @@ -200,6 +222,10 @@ static const struct apple_sleep_soc t8112_sleep_soc = { .ndisp = 1, .nmcc = 4, .pmu_usid = 0xe, + /* Stowe PMU on nub-spmi0:0e (info-leg_scrpad = 0xf700, boot-stage = 0xf701). */ + .pmu_sleep_reg = 0xf701, + .pmu_sleep_val = 0x50, + .spmi_notify_sleep = 0x2000001, .wake_mask = 0x08, .wake_status = 0x24, .wake_words = 7, @@ -216,6 +242,8 @@ static const struct apple_sleep_soc t8112_sleep_soc = { }, .ps_all = SLEEP_WORDS(t8112_ps_all), .ps_aon_all = SLEEP_WORDS(t8112_ps_aon_all), + .ps_wake_order = SLEEP_WORDS(t8112_ps_wake_order), + .ps_aon_wake_order = SLEEP_WORDS(t8112_ps_aon_wake_order), .gate_coprocs = t8112_gate_coprocs, .ngate_coprocs = ARRAY_SIZE(t8112_gate_coprocs), }; From 31ee0d9bf5971364c2ced449a05f1ef7a081b873 Mon Sep 17 00:00:00 2001 From: WJW Date: Thu, 26 Nov 2026 15:41:05 +0800 Subject: [PATCH 06/23] soc: apple: sleep: add T8112 HID4/EHID4 cache clean and CYC_OVRD deep WFI Signed-off-by: WJW --- drivers/soc/apple/sleep-t8112.h | 122 ++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h index c719e1012697a..8aac6c5e07888 100644 --- a/drivers/soc/apple/sleep-t8112.h +++ b/drivers/soc/apple/sleep-t8112.h @@ -33,6 +33,16 @@ #define T8112_AON_NUB_FABRIC 0xa8 #define T8112_AON_DEBUG_SWITCH 0xb8 +#define T8112_SYS_HID4 sys_reg(3, 0, 15, 4, 0) +#define T8112_SYS_EHID4 sys_reg(3, 0, 15, 4, 1) +#define T8112_HID4_DISABLE_DC_MVA BIT_ULL(11) +#define T8112_HID4_DISABLE_DC_SW_L2 BIT_ULL(44) +#define T8112_HID4_DC_MASK (T8112_HID4_DISABLE_DC_MVA | T8112_HID4_DISABLE_DC_SW_L2) +#define T8112_MPIDR_P_CORE BIT_ULL(16) + +#define T8112_SYS_CYC_OVRD sys_reg(3, 5, 15, 5, 0) +#define T8112_CYC_WFI_MODE GENMASK_ULL(25, 24) + /* Every PMGR power-state word in the T8112 device tree (t8112-pmgr.dtsi). */ static const u32 t8112_ps_all[] = { 0x100, 0x108, 0x110, 0x118, 0x120, 0x128, 0x130, 0x160, 0x168, 0x170, @@ -166,8 +176,120 @@ static void t8112_aic_mask_noop(void) { } +static __always_inline bool t8112_is_pcore(void) +{ + return !!(read_sysreg(mpidr_el1) & T8112_MPIDR_P_CORE); +} + +static __always_inline u64 t8112_read_hid4(bool pcore) +{ + return pcore ? read_sysreg_s(T8112_SYS_HID4) + : read_sysreg_s(T8112_SYS_EHID4); +} + +static __always_inline void t8112_write_hid4(bool pcore, u64 val) +{ + if (pcore) + write_sysreg_s(val, T8112_SYS_HID4); + else + write_sysreg_s(val, T8112_SYS_EHID4); + isb(); +} + +/* + * Register-only dc csw across all implemented data/unified cache levels + * (L1 + L2 on T8112). Must run with HID4/EHID4 DISABLE_DC_SW_L2 cleared so + * set/way L2 maintenance instructions are not ignored as NOPs. + */ +static __always_inline void t8112_dcache_clean_all_levels(void) +{ + u64 r_clidr, r_ccidx, r_lvl, r_ctype, r_ccsidr, r_lshift; + u64 r_way, r_mset, r_wshift, r_set, r_tmp; + + asm volatile( + "dsb sy\n\t" + "mrs %[clidr], clidr_el1\n\t" + "mrs %[ccidx], id_aa64mmfr2_el1\n\t" + "ubfx %[ccidx], %[ccidx], #20, #4\n\t" + "mov %[lvl], #0\n\t" + "1:\n\t" + "cmp %[lvl], #7\n\t" + "b.hs 5f\n\t" + "add %[tmp], %[lvl], %[lvl], lsl #1\n\t" + "lsr %[ctype], %[clidr], %[tmp]\n\t" + "and %[ctype], %[ctype], #7\n\t" + "cbz %[ctype], 5f\n\t" + "cmp %[ctype], #2\n\t" + "b.lo 4f\n\t" + "cmp %[ctype], #4\n\t" + "b.hi 4f\n\t" + "lsl %[tmp], %[lvl], #1\n\t" + "msr csselr_el1, %[tmp]\n\t" + "isb\n\t" + "mrs %[ccsidr], ccsidr_el1\n\t" + "and %[lshift], %[ccsidr], #7\n\t" + "add %[lshift], %[lshift], #4\n\t" + "cbnz %[ccidx], 20f\n\t" + "ubfx %[way], %[ccsidr], #3, #10\n\t" + "ubfx %[mset], %[ccsidr], #13, #15\n\t" + "b 21f\n\t" + "20:\n\t" + "ubfx %[way], %[ccsidr], #3, #21\n\t" + "ubfx %[mset], %[ccsidr], #32, #24\n\t" + "21:\n\t" + "clz %w[wshift], %w[way]\n\t" + "2:\n\t" + "mov %[set], %[mset]\n\t" + "lsl %[ctype], %[way], %[wshift]\n\t" + "orr %[ctype], %[ctype], %[lvl], lsl #1\n\t" + "3:\n\t" + "lsl %[tmp], %[set], %[lshift]\n\t" + "orr %[tmp], %[ctype], %[tmp]\n\t" + "dc csw, %[tmp]\n\t" + "subs %[set], %[set], #1\n\t" + "b.ge 3b\n\t" + "subs %[way], %[way], #1\n\t" + "b.ge 2b\n\t" + "dsb sy\n\t" + "4:\n\t" + "add %[lvl], %[lvl], #1\n\t" + "b 1b\n\t" + "5:\n\t" + "msr csselr_el1, xzr\n\t" + "dsb sy\n\t" + "isb\n\t" + : [clidr] "=&r"(r_clidr), + [ccidx] "=&r"(r_ccidx), + [lvl] "=&r"(r_lvl), + [ctype] "=&r"(r_ctype), + [ccsidr] "=&r"(r_ccsidr), + [lshift] "=&r"(r_lshift), + [way] "=&r"(r_way), + [mset] "=&r"(r_mset), + [wshift] "=&r"(r_wshift), + [set] "=&r"(r_set), + [tmp] "=&r"(r_tmp) + : + : "cc", "memory"); +} + static void t8112_deep_wfi_arm(void) { + bool pcore = t8112_is_pcore(); + u64 hid4 = t8112_read_hid4(pcore); + + t8112_write_hid4(pcore, hid4 & ~T8112_HID4_DC_MASK); + t8112_dcache_clean_all_levels(); + t8112_write_hid4(pcore, hid4); + + sysreg_clear_set_s(T8112_SYS_CYC_OVRD, 0, T8112_CYC_WFI_MODE); + isb(); + sysreg_clear_set_s(SYS_APL_DEEP_SLEEP, 0, DEEP_SLEEP_ENABLE); + isb(); + if (is_kernel_in_hyp_mode()) { + dsb(sy); + t8142_el1_wfi(); + } } static int t8112_sleep_cpu_prepare(u64 mpidr) From b95dc26fbbb31e170541839f41fdf04e2d26d214 Mon Sep 17 00:00:00 2001 From: WJW Date: Thu, 26 Nov 2026 17:47:38 +0800 Subject: [PATCH 07/23] arm64: dts: apple: t8112: add power-domains to sep node for S2R Signed-off-by: WJW --- arch/arm64/boot/dts/apple/t8112.dtsi | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index f4a4b168525b1..74c4aa441d358 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -1886,6 +1886,7 @@ mboxes = <&sep_mbox>; mbox-names = "mbox"; iommus = <&sep_dart 0>; + power-domains = <&ps_sep>, <&ps_gpio>; status = "disabled"; }; From 163865dc633a0c69ebccb5bdfa37eeedf15a6ded Mon Sep 17 00:00:00 2001 From: WJW Date: Thu, 26 Nov 2026 17:58:48 +0800 Subject: [PATCH 08/23] soc: apple: sleep: wire verified T8112 pwrgate, cllt, cluster, and commit blocks Signed-off-by: WJW --- .../bindings/soc/apple/apple,t8140-sleep.yaml | 14 +++++++++----- arch/arm64/boot/dts/apple/t8112.dtsi | 19 ++++++++++++------- drivers/soc/apple/sleep-t8112.h | 17 ++++++++++++++--- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml index b5ea3a203cf50..ade869f781141 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml @@ -140,17 +140,21 @@ allOf: - apple,pinctrl properties: reg: - minItems: 7 - maxItems: 7 + minItems: 11 + maxItems: 11 reg-names: items: - const: ps - - const: ps-aon - - const: clk-mux - - const: wake + - const: pwrgate - const: cpu-start + - const: cllt + - const: cluster + - const: commit - const: wdt - const: spmi + - const: wake + - const: ps-aon + - const: clk-mux - if: properties: compatible: diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index 74c4aa441d358..248c6c46ef592 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -1313,15 +1313,20 @@ sleep: sleep@23b700000 { compatible = "apple,t8112-sleep"; - reg = <0x2 0x3b700000 0x0 0xcc000>, - <0x2 0x3d280000 0x0 0x7c000>, - <0x2 0x3b000000 0x0 0x70000>, - <0x2 0x3d004000 0x0 0x48>, + reg = <0x2 0x3b700000 0x0 0x14000>, + <0x2 0x3b724000 0x0 0x4000>, <0x2 0x3b734000 0x0 0x10>, + <0x2 0x3b760000 0x0 0x40>, + <0x2 0x3b780000 0x0 0x8>, + <0x2 0x3d2d4000 0x0 0x4>, <0x2 0x3d2b0000 0x0 0x30>, - <0x2 0x3d714000 0x0 0x100>; - reg-names = "ps", "ps-aon", "clk-mux", "wake", - "cpu-start", "wdt", "spmi"; + <0x2 0x3d714000 0x0 0x100>, + <0x2 0x3d004000 0x0 0x48>, + <0x2 0x3d280000 0x0 0x4000>, + <0x2 0x3b000000 0x0 0x70000>; + reg-names = "ps", "pwrgate", "cpu-start", "cllt", + "cluster", "commit", "wdt", "spmi", + "wake", "ps-aon", "clk-mux"; apple,display-coprocessors = <&dcp>; apple,pinctrl = <&pinctrl_ap>; status = "disabled"; diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h index 8aac6c5e07888..7010c1ae08b94 100644 --- a/drivers/soc/apple/sleep-t8112.h +++ b/drivers/soc/apple/sleep-t8112.h @@ -33,6 +33,11 @@ #define T8112_AON_NUB_FABRIC 0xa8 #define T8112_AON_DEBUG_SWITCH 0xb8 +#define T8112_PWRGATE_E 0x80 +#define T8112_PWRGATE_P 0x88 +#define T8112_CLUSTER_E 0x0 +#define T8112_CLUSTER_P 0x4 + #define T8112_SYS_HID4 sys_reg(3, 0, 15, 4, 0) #define T8112_SYS_EHID4 sys_reg(3, 0, 15, 4, 1) #define T8112_HID4_DISABLE_DC_MVA BIT_ULL(11) @@ -109,11 +114,15 @@ static int t8112_sleep_map_regs(struct apple_sleep *s) const char *name; size_t offset; } regs[] = { - { "ps-aon", offsetof(struct apple_sleep, ps_aon) }, - { "wake", offsetof(struct apple_sleep, wake) }, + { "pwrgate", offsetof(struct apple_sleep, pwrgate) }, { "cpu-start", offsetof(struct apple_sleep, cpu_start) }, + { "cllt", offsetof(struct apple_sleep, cllt) }, + { "cluster", offsetof(struct apple_sleep, cluster) }, + { "commit", offsetof(struct apple_sleep, commit) }, { "wdt", offsetof(struct apple_sleep, wdt) }, { "spmi", offsetof(struct apple_sleep, spmi) }, + { "wake", offsetof(struct apple_sleep, wake) }, + { "ps-aon", offsetof(struct apple_sleep, ps_aon) }, }; unsigned int i; @@ -339,8 +348,10 @@ static const struct apple_sleep_soc t8112_sleep_soc = { .cpu_clusters = 2, .cpu_cores_per_cluster = 4, .cpu_start_stride = 4, - .cluster_cpu = { 0x0, 0x4 }, + .cluster_cpu = { T8112_CLUSTER_E, T8112_CLUSTER_P }, .ncluster_cpu = 2, + .pwrgate_wake = { 0x000, 0x040 }, + .pwrgate_cpm = { T8112_PWRGATE_E, T8112_PWRGATE_P }, .ndisp = 1, .nmcc = 4, .pmu_usid = 0xe, From dee5df4088cfd6ac1c9e247d0e52b6006e7cb98e Mon Sep 17 00:00:00 2001 From: WJW Date: Thu, 26 Nov 2026 18:03:24 +0800 Subject: [PATCH 09/23] soc: apple: sleep: implement T8112 prepare, undo, ATC-off, commit, and wake ops Signed-off-by: WJW --- drivers/soc/apple/sleep-t8112.h | 178 ++++++++++++++++++++++++++++---- 1 file changed, 158 insertions(+), 20 deletions(-) diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h index 7010c1ae08b94..354b6ed0867b2 100644 --- a/drivers/soc/apple/sleep-t8112.h +++ b/drivers/soc/apple/sleep-t8112.h @@ -85,6 +85,8 @@ static const u32 t8112_ps_aon_wake_order[] = { static struct { void __iomem *clk_mux; + u32 notify_saved; + bool notify_staged; } t8112; static void __iomem *t8112_map(struct apple_sleep *s, const char *name, struct resource *out) @@ -165,26 +167,6 @@ static int t8112_sleep_display_off(struct apple_sleep *s) return 0; } -static void t8112_sleep_prepare_regs(struct apple_sleep *s) -{ -} - -static void t8112_sleep_undo_regs(struct apple_sleep *s) -{ -} - -static void t8112_sleep_commit_regs(struct apple_sleep *s) -{ -} - -static void t8112_sleep_wake(struct apple_sleep *s) -{ -} - -static void t8112_aic_mask_noop(void) -{ -} - static __always_inline bool t8112_is_pcore(void) { return !!(read_sysreg(mpidr_el1) & T8112_MPIDR_P_CORE); @@ -205,6 +187,25 @@ static __always_inline void t8112_write_hid4(bool pcore, u64 val) isb(); } +static __always_inline void t8112_clean_range_slc(unsigned long start, unsigned long end) +{ + unsigned long line = 4UL << ((read_sysreg(ctr_el0) >> 16) & 0xf); + unsigned int dpb = read_sysreg(id_aa64isar1_el1) & 0xf; + unsigned long addr = start & ~(line - 1); + + if (dpb >= 2) { + for (; addr < end; addr += line) + asm volatile("sys #3, c7, c13, #1, %0" : : "r"(addr) : "memory"); + } else if (dpb >= 1) { + for (; addr < end; addr += line) + asm volatile("sys #3, c7, c12, #1, %0" : : "r"(addr) : "memory"); + } else { + for (; addr < end; addr += line) + asm volatile("dc civac, %0" : : "r"(addr) : "memory"); + } + dsb(sy); +} + /* * Register-only dc csw across all implemented data/unified cache levels * (L1 + L2 on T8112). Must run with HID4/EHID4 DISABLE_DC_SW_L2 cleared so @@ -282,6 +283,138 @@ static __always_inline void t8112_dcache_clean_all_levels(void) : "cc", "memory"); } +static void t8112_sleep_prepare_regs(struct apple_sleep *s) +{ + apple_sleep_pmu_write(s->spmi, s->soc->pmu_usid, + s->soc->pmu_sleep_reg, s->soc->pmu_sleep_val); + t8112.notify_saved = readl(s->spmi + SPMI_NOTIFY_ENABLE); + t8112.notify_staged = true; + writel(s->soc->spmi_notify_sleep, s->spmi + SPMI_NOTIFY_ENABLE); +} + +static void t8112_sleep_undo_regs(struct apple_sleep *s) +{ + if (!t8112.notify_staged) + return; + writel(t8112.notify_saved, s->spmi + SPMI_NOTIFY_ENABLE); + t8112.notify_staged = false; +} + +static void t8112_aon_lower(struct apple_sleep *s, u32 off) +{ + u32 val = readl(s->ps_aon + off); + + if (val & PS_AUTO_ENABLE) { + val &= ~(PS_AUTO_ENABLE | PS_FLAGS); + writel(val, s->ps_aon + off); + } + writel((val & ~PS_TARGET) | PS_FLAGS, s->ps_aon + off); +} + +static void t8112_sleep_atc_off(struct apple_sleep *s) +{ + static const struct { + u32 usb, usb_aon, common; + } port[] = { + { T8112_AON_ATC0_USB, T8112_AON_ATC0_USB_AON, T8112_PS_ATC0_COMMON }, + { T8112_AON_ATC1_USB, T8112_AON_ATC1_USB_AON, T8112_PS_ATC1_COMMON }, + }; + unsigned int i; + + if (!s->ps_aon) + return; + for (i = 0; i < ARRAY_SIZE(port); i++) { + t8112_aon_lower(s, port[i].usb); + t8112_aon_lower(s, port[i].usb_aon); + sleep_ps_lower(s, port[i].common); + sleep_ps_wait_off(s, port[i].common); + } +} + +static void t8112_sleep_commit_regs(struct apple_sleep *s) +{ + bool pcore; + u64 hid4_orig; + + sleep_ps_save(s); + t8112_sleep_atc_off(s); + writel(0, s->wdt + WDT_WD0_CTL); + + aic_sleep_mask_all(); + + if (s->mbox) { + s->resumes_before = READ_ONCE(s->mbox->resumes); + WRITE_ONCE(s->mbox->resume_pa, __pa_symbol(s->soc->ops->resume)); + } + + pcore = t8112_is_pcore(); + hid4_orig = t8112_read_hid4(pcore); + t8112_write_hid4(pcore, hid4_orig & ~T8112_HID4_DC_MASK); + t8112_dcache_clean_all_levels(); + if (s->mbox) + t8112_clean_range_slc((unsigned long)s->mbox, + (unsigned long)(s->mbox + 1)); + t8112_clean_range_slc((unsigned long)s, (unsigned long)(s + 1)); + t8112_clean_range_slc((unsigned long)current, + (unsigned long)current + sizeof(*current)); + t8112_clean_range_slc((unsigned long)task_stack_page(current), + (unsigned long)task_stack_page(current) + THREAD_SIZE); + dsb(sy); + t8112_write_hid4(pcore, hid4_orig); + + writel(PWRGATE_ON, s->pwrgate + T8112_PWRGATE_E); + writel(PWRGATE_ON, s->pwrgate + T8112_PWRGATE_P); + writel(0, s->cluster + T8112_CLUSTER_E); + write_sysreg(ARCH_TIMER_CTRL_IT_MASK, cntp_ctl_el0); + write_sysreg(ARCH_TIMER_CTRL_IT_MASK, cntv_ctl_el0); + sysreg_clear_set_s(SYS_APL_DEEP_SLEEP, 0, DEEP_SLEEP_ENABLE); + writel(0, s->cluster + T8112_CLUSTER_P); +} + +static void t8112_sleep_pre_commit(struct apple_sleep *s) +{ + bool pcore = t8112_is_pcore(); + u64 hid4_orig = t8112_read_hid4(pcore); + + t8112_write_hid4(pcore, hid4_orig & ~T8112_HID4_DISABLE_DC_MVA); + if (s->mbox) + t8112_clean_range_slc((unsigned long)s->mbox, + (unsigned long)(s->mbox + 1)); + t8112_clean_range_slc((unsigned long)s, (unsigned long)(s + 1)); + dsb(sy); + t8112_write_hid4(pcore, hid4_orig); +} + +static void t8112_sleep_wake(struct apple_sleep *s) +{ + u32 val; + + writel(CLUSTER_ON, s->cluster + T8112_CLUSTER_E); + s->cluster_e_ret = readl_poll_timeout_atomic(s->cluster + T8112_CLUSTER_E, val, + val & CLUSTER_E_READY, 1, + CLUSTER_TIMEOUT_US); + writel(CLUSTER_ON, s->cluster + T8112_CLUSTER_P); + + writel(PWRGATE_ON, s->pwrgate + s->soc->pwrgate_wake[0]); + writel(PWRGATE_ON, s->pwrgate + s->soc->pwrgate_wake[1]); + + if (s->ps_aon) + sleep_ps_rewake(s); + sleep_ps_raise(s, T8112_PS_GPIO); + s->pins_lost = s->pins_saved_valid; + + val = readl(s->ps + T8112_PS_SEP); + if (val & PS_DEV_DISABLE) + writel(val & ~PS_DEV_DISABLE, s->ps + T8112_PS_SEP); + + writel(PWRGATE_ON, s->pwrgate + T8112_PWRGATE_E); + writel(PWRGATE_ON, s->pwrgate + T8112_PWRGATE_P); +} + +static void t8112_aic_mask_noop(void) +{ +} + static void t8112_deep_wfi_arm(void) { bool pcore = t8112_is_pcore(); @@ -331,6 +464,7 @@ static const struct apple_sleep_ops t8112_sleep_ops = { .prepare_regs = t8112_sleep_prepare_regs, .undo_regs = t8112_sleep_undo_regs, .commit_regs = t8112_sleep_commit_regs, + .pre_commit = t8112_sleep_pre_commit, .wake = t8112_sleep_wake, .cpu_prepare = t8112_sleep_cpu_prepare, .cpu_restore = t8112_sleep_cpu_restore, @@ -339,7 +473,11 @@ static const struct apple_sleep_ops t8112_sleep_ops = { static const struct apple_sleep_soc t8112_sleep_soc = { .ops = &t8112_sleep_ops, .untested = true, + .pen_deep = true, + .el1_wfi = true, .early_context = true, + .early_cpu_wfi = true, + .boot_wfi_delay_ms = 2, .no_pmu_notes = true, .no_wd2 = true, .display_no_restart = true, From 9f6478c8ea8cf628cbb3f6594fe0d870a357f57b Mon Sep 17 00:00:00 2001 From: WJW Date: Thu, 26 Nov 2026 21:23:15 +0800 Subject: [PATCH 10/23] soc: apple: sleep: wire T8112 display-off, MCC, clk-mux, TVM, and DCS sequences Implement the T8112 (Apple M2) hardware sleep-entry and wake register sequences in sleep-t8112.h and extend the apple,t8112-sleep DT binding and t8112.dtsi with the MCC channel-stop windows and full 0x4000 cllt window: - Display-off sequence (DISP0_CPU0, DISP0_FE, DISP0_SYS) with 100ms power-down poll. - MCC channel step-down across mcc-ctl and mcc-a..e before clock park. - SoC clock-mux park and restore on 0x40040/48/44/38/34. - Four TVM/CLLT units (0x400/800/c00/000) disable/poll and restore. - DCS perf state park (0x335 -> 0x553) and restore at clk-mux + 0x5c000. - Clear/restore PS_AUTO_ENABLE on SIO_BUSIF (0x1b0), IMX (0x1a8), and SIO (0x1b8) around commit, and flush saved state to DRAM in pre_commit. Keep .untested = true so physical commit requires apple_sleep.untested_commit=1 while d1 dry-run remains the default. Signed-off-by: WJW --- .../bindings/soc/apple/apple,t8140-sleep.yaml | 10 +- arch/arm64/boot/dts/apple/t8112.dtsi | 14 +- drivers/soc/apple/sleep-t8112.h | 189 +++++++++++++++++- 3 files changed, 203 insertions(+), 10 deletions(-) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml index ade869f781141..de3fb04a87331 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml @@ -140,8 +140,8 @@ allOf: - apple,pinctrl properties: reg: - minItems: 11 - maxItems: 11 + minItems: 17 + maxItems: 17 reg-names: items: - const: ps @@ -155,6 +155,12 @@ allOf: - const: wake - const: ps-aon - const: clk-mux + - const: mcc-ctl + - const: mcc-a + - const: mcc-b + - const: mcc-c + - const: mcc-d + - const: mcc-e - if: properties: compatible: diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index 248c6c46ef592..571493ac5874a 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -1316,17 +1316,25 @@ reg = <0x2 0x3b700000 0x0 0x14000>, <0x2 0x3b724000 0x0 0x4000>, <0x2 0x3b734000 0x0 0x10>, - <0x2 0x3b760000 0x0 0x40>, + <0x2 0x3b760000 0x0 0x4000>, <0x2 0x3b780000 0x0 0x8>, <0x2 0x3d2d4000 0x0 0x4>, <0x2 0x3d2b0000 0x0 0x30>, <0x2 0x3d714000 0x0 0x100>, <0x2 0x3d004000 0x0 0x48>, <0x2 0x3d280000 0x0 0x4000>, - <0x2 0x3b000000 0x0 0x70000>; + <0x2 0x3b000000 0x0 0x70000>, + <0x2 0x0001c000 0x0 0x4000>, + <0x2 0x00024000 0x0 0x1000>, + <0x2 0x00064000 0x0 0x1000>, + <0x2 0x000a4000 0x0 0x1000>, + <0x2 0x000e4000 0x0 0x1000>, + <0x2 0x01000000 0x0 0x1000>; reg-names = "ps", "pwrgate", "cpu-start", "cllt", "cluster", "commit", "wdt", "spmi", - "wake", "ps-aon", "clk-mux"; + "wake", "ps-aon", "clk-mux", + "mcc-ctl", "mcc-a", "mcc-b", "mcc-c", + "mcc-d", "mcc-e"; apple,display-coprocessors = <&dcp>; apple,pinctrl = <&pinctrl_ap>; status = "disabled"; diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h index 354b6ed0867b2..f013aed53fbd2 100644 --- a/drivers/soc/apple/sleep-t8112.h +++ b/drivers/soc/apple/sleep-t8112.h @@ -38,6 +38,18 @@ #define T8112_CLUSTER_E 0x0 #define T8112_CLUSTER_P 0x4 +#define T8112_MUX_PARK_VAL 0x80100000 +#define T8112_DCS_PERF_OFF 0x5c000 +#define T8112_DCS_BUSY BIT(31) +#define T8112_DCS_TIMEOUT_US 10000 +#define T8112_TVM_IDLE_OFF 0x3e0 +#define T8112_TVM_BUSY BIT(1) +#define T8112_TVM_TIMEOUT_US 10000 + +static const u32 t8112_mux_park[] = { 0x40040, 0x40048, 0x40044, 0x40038, 0x40034 }; +static const u32 t8112_tvm[] = { 0x400, 0x800, 0xc00, 0x000 }; +static const u32 t8112_auto_off[] = { 0x1b0, 0x1a8, 0x1b8 }; + #define T8112_SYS_HID4 sys_reg(3, 0, 15, 4, 0) #define T8112_SYS_EHID4 sys_reg(3, 0, 15, 4, 1) #define T8112_HID4_DISABLE_DC_MVA BIT_ULL(11) @@ -85,8 +97,15 @@ static const u32 t8112_ps_aon_wake_order[] = { static struct { void __iomem *clk_mux; + void __iomem *mcc_ctl; + void __iomem *mcc[5]; u32 notify_saved; bool notify_staged; + u32 mux_saved[ARRAY_SIZE(t8112_mux_park)]; + u32 tvm_saved[ARRAY_SIZE(t8112_tvm)]; + u32 auto_saved[ARRAY_SIZE(t8112_auto_off)]; + u32 dcs_saved; + bool commit_saved; } t8112; static void __iomem *t8112_map(struct apple_sleep *s, const char *name, struct resource *out) @@ -143,6 +162,26 @@ static int t8112_sleep_map_regs(struct apple_sleep *s) if (IS_ERR(t8112.clk_mux)) return dev_err_probe(s->dev, PTR_ERR(t8112.clk_mux), "no clk-mux registers\n"); + t8112.mcc_ctl = t8112_map(s, "mcc-ctl", NULL); + if (IS_ERR(t8112.mcc_ctl)) { + dev_warn(s->dev, "no mcc-ctl registers: MCC quiesce unavailable\n"); + t8112.mcc_ctl = NULL; + } + { + static const char *const mcc_names[5] = { + "mcc-a", "mcc-b", "mcc-c", "mcc-d", "mcc-e", + }; + + for (i = 0; i < ARRAY_SIZE(mcc_names); i++) { + t8112.mcc[i] = t8112_map(s, mcc_names[i], NULL); + if (IS_ERR(t8112.mcc[i])) { + dev_warn(s->dev, "no %s registers: MCC channel stop unavailable\n", + mcc_names[i]); + t8112.mcc[i] = NULL; + } + } + } + s->driver_down = devm_bitmap_zalloc(s->dev, resource_size(&s->ps_res) / 4, GFP_KERNEL); if (!s->driver_down) return -ENOMEM; @@ -154,16 +193,44 @@ static int t8112_sleep_map_regs(struct apple_sleep *s) static int t8112_sleep_check(struct apple_sleep *s) { - if (!apple_sleep_dry(s)) { - dev_err(s->dev, - "T8112: physical sleep commit not yet implemented; run dry-run only\n"); - return -EOPNOTSUPP; - } return 0; } +static void t8112_ps_lower_if_on(struct apple_sleep *s, u32 off, u32 first, u32 second) +{ + if (!FIELD_GET(PS_ACTUAL, readl(s->ps + off))) + return; + if (first) + writel(first, s->ps + off); + writel(second, s->ps + off); +} + static int t8112_sleep_display_off(struct apple_sleep *s) { + u64 start, hz = arch_timer_get_cntfrq(); + bool off = false; + + if (FIELD_GET(PS_ACTUAL, readl(s->ps + T8112_PS_DISP0_CPU0))) { + writel(0x0f0000ff, s->ps + T8112_PS_DISP0_CPU0); + writel(0x0f0003f0, s->ps + T8112_PS_DISP0_CPU0); + } + t8112_ps_lower_if_on(s, T8112_PS_DISP0_FE, 0, 0x23f0); + t8112_ps_lower_if_on(s, T8112_PS_DISP0_SYS, 0, 0x23f0); + + start = read_sysreg(cntvct_el0); + while (read_sysreg(cntvct_el0) - start < hz / 10) { + if (!FIELD_GET(PS_ACTUAL, readl(s->ps + T8112_PS_DISP0_CPU0))) { + off = true; + break; + } + cpu_relax(); + } + if (!off) { + dev_err(s->dev, "refused: DISP0_CPU0 stayed on: %#x\n", + readl(s->ps + T8112_PS_DISP0_CPU0)); + return -EBUSY; + } + return 0; } @@ -331,10 +398,76 @@ static void t8112_sleep_atc_off(struct apple_sleep *s) } } +static void t8112_mcc_clear_bits64(void __iomem *reg) +{ + u64 q = readq(reg); + + while (q) { + q &= q - 1; + writeq(q, reg); + } +} + +static void t8112_mcc_clear_bits32(void __iomem *reg) +{ + u32 l = readl(reg); + + while (l) { + l &= l - 1; + writel(l, reg); + } +} + +static void t8112_mcc_channel_stop(void) +{ + unsigned int i; + + if (!t8112.mcc[0] || !t8112.mcc[1] || !t8112.mcc[2] || !t8112.mcc[3] || !t8112.mcc[4]) + return; + + if (t8112.mcc_ctl) { + u64 q; + + writel(0x3e, t8112.mcc_ctl + 0x10); + writel(0, t8112.mcc_ctl + 0x0c); + writel(2, t8112.mcc_ctl + 0x2004); + q = readq(t8112.mcc[0]); + if (q) { + q &= q - 1; + writeq(q, t8112.mcc[0]); + } + if (q) { + q &= q - 1; + writeq(q, t8112.mcc[0]); + } + writel(0x3e, t8112.mcc_ctl + 0x10); + writel(0, t8112.mcc_ctl + 0x0c); + writel(0, t8112.mcc_ctl + 0x2004); + } + + for (i = 0; i < 3; i++) + t8112_mcc_clear_bits64(t8112.mcc[i]); + for (i = 0; i < 4; i++) + t8112_mcc_clear_bits64(t8112.mcc[i] + 0x800); + t8112_mcc_clear_bits32(t8112.mcc[4] + 0x584); + t8112_mcc_clear_bits32(t8112.mcc[4] + 0x588); +} + +static void t8112_dcs_write(u32 val) +{ + u32 cur; + + writel(val, t8112.clk_mux + T8112_DCS_PERF_OFF); + readl_poll_timeout_atomic(t8112.clk_mux + T8112_DCS_PERF_OFF, cur, + !(cur & T8112_DCS_BUSY), 1, T8112_DCS_TIMEOUT_US); +} + static void t8112_sleep_commit_regs(struct apple_sleep *s) { bool pcore; u64 hid4_orig; + unsigned int i; + u32 val; sleep_ps_save(s); t8112_sleep_atc_off(s); @@ -362,6 +495,25 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) dsb(sy); t8112_write_hid4(pcore, hid4_orig); + t8112_mcc_channel_stop(); + + for (i = 0; i < ARRAY_SIZE(t8112_mux_park); i++) { + t8112.mux_saved[i] = readl(t8112.clk_mux + t8112_mux_park[i]); + writel(T8112_MUX_PARK_VAL, t8112.clk_mux + t8112_mux_park[i]); + } + + for (i = 0; i < ARRAY_SIZE(t8112_tvm); i++) { + t8112.tvm_saved[i] = readl(s->cllt + t8112_tvm[i]); + writel(0, s->cllt + t8112_tvm[i]); + readl_poll_timeout_atomic(s->cllt + t8112_tvm[i] + T8112_TVM_IDLE_OFF, + val, !(val & T8112_TVM_BUSY), 1, + T8112_TVM_TIMEOUT_US); + } + + t8112.dcs_saved = readl(t8112.clk_mux + T8112_DCS_PERF_OFF); + t8112_dcs_write(0x335); + t8112_dcs_write(0x553); + writel(PWRGATE_ON, s->pwrgate + T8112_PWRGATE_E); writel(PWRGATE_ON, s->pwrgate + T8112_PWRGATE_P); writel(0, s->cluster + T8112_CLUSTER_E); @@ -369,6 +521,14 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) write_sysreg(ARCH_TIMER_CTRL_IT_MASK, cntv_ctl_el0); sysreg_clear_set_s(SYS_APL_DEEP_SLEEP, 0, DEEP_SLEEP_ENABLE); writel(0, s->cluster + T8112_CLUSTER_P); + + for (i = 0; i < ARRAY_SIZE(t8112_auto_off); i++) { + val = readl(s->ps + t8112_auto_off[i]); + t8112.auto_saved[i] = val; + if (val & PS_AUTO_ENABLE) + writel(val & ~PS_AUTO_ENABLE, s->ps + t8112_auto_off[i]); + } + t8112.commit_saved = true; } static void t8112_sleep_pre_commit(struct apple_sleep *s) @@ -381,6 +541,7 @@ static void t8112_sleep_pre_commit(struct apple_sleep *s) t8112_clean_range_slc((unsigned long)s->mbox, (unsigned long)(s->mbox + 1)); t8112_clean_range_slc((unsigned long)s, (unsigned long)(s + 1)); + t8112_clean_range_slc((unsigned long)&t8112, (unsigned long)(&t8112 + 1)); dsb(sy); t8112_write_hid4(pcore, hid4_orig); } @@ -388,6 +549,7 @@ static void t8112_sleep_pre_commit(struct apple_sleep *s) static void t8112_sleep_wake(struct apple_sleep *s) { u32 val; + int i; writel(CLUSTER_ON, s->cluster + T8112_CLUSTER_E); s->cluster_e_ret = readl_poll_timeout_atomic(s->cluster + T8112_CLUSTER_E, val, @@ -398,6 +560,23 @@ static void t8112_sleep_wake(struct apple_sleep *s) writel(PWRGATE_ON, s->pwrgate + s->soc->pwrgate_wake[0]); writel(PWRGATE_ON, s->pwrgate + s->soc->pwrgate_wake[1]); + if (t8112.commit_saved) { + for (i = ARRAY_SIZE(t8112_auto_off) - 1; i >= 0; i--) + if (t8112.auto_saved[i] & PS_AUTO_ENABLE) + writel(t8112.auto_saved[i], s->ps + t8112_auto_off[i]); + + if (t8112.dcs_saved) + t8112_dcs_write(t8112.dcs_saved & ~T8112_DCS_BUSY); + + for (i = ARRAY_SIZE(t8112_tvm) - 1; i >= 0; i--) + writel(t8112.tvm_saved[i], s->cllt + t8112_tvm[i]); + + for (i = ARRAY_SIZE(t8112_mux_park) - 1; i >= 0; i--) + writel(t8112.mux_saved[i], t8112.clk_mux + t8112_mux_park[i]); + + t8112.commit_saved = false; + } + if (s->ps_aon) sleep_ps_rewake(s); sleep_ps_raise(s, T8112_PS_GPIO); From 60ab4422e009f615023235fa8a5c466a424b9e8e Mon Sep 17 00:00:00 2001 From: WJW Date: Thu, 26 Nov 2026 22:07:42 +0800 Subject: [PATCH 11/23] soc: apple: sleep: wire T8112 wake sources and drop PCIe-ANS gate Read apple,wake-enable in t8112_sleep_map_regs(), configure the 5-word nub-ap wake block (wake_mask 0x08, wake_status 0x1c) with the T8112 wake source names and required NUB.SPMI0Sw3IRQ source, and enable apple,wake-enable on t8112-j413. Drop .ps.ans from t8112_sleep_soc since T8112 uses MMIO ANS2 (quiesced directly by nvme-apple) rather than PCIe-attached ANS. Signed-off-by: WJW --- arch/arm64/boot/dts/apple/t8112-j413.dts | 1 + drivers/soc/apple/sleep-t8112.h | 29 ++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8112-j413.dts b/arch/arm64/boot/dts/apple/t8112-j413.dts index 15c3abf6e6766..282fa6eb0d238 100644 --- a/arch/arm64/boot/dts/apple/t8112-j413.dts +++ b/arch/arm64/boot/dts/apple/t8112-j413.dts @@ -598,5 +598,6 @@ }; &sleep { + apple,wake-enable = <14 54 76 81 133 134>; status = "okay"; }; diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h index f013aed53fbd2..2e682cc281eda 100644 --- a/drivers/soc/apple/sleep-t8112.h +++ b/drivers/soc/apple/sleep-t8112.h @@ -182,6 +182,13 @@ static int t8112_sleep_map_regs(struct apple_sleep *s) } } + { + int ret = apple_sleep_read_wake_sources(s); + + if (ret) + return ret; + } + s->driver_down = devm_bitmap_zalloc(s->dev, resource_size(&s->ps_res) / 4, GFP_KERNEL); if (!s->driver_down) return -ENOMEM; @@ -631,6 +638,17 @@ static const struct apple_sleep_gate_coproc t8112_gate_coprocs[] = { { "/soc/smc@23e400000" }, }; +static const struct apple_sleep_wake_name t8112_wake_names[] = { + { 14, "AOP.GPIO.IRQ6" }, + { 54, "NUB.SPMI0Sw3IRQ" }, + { 76, "SMC.CPUWakeupAP" }, + { 81, "SMC.OutboxNotEmpty" }, + { 133, "ATC0.USBWakeup" }, + { 134, "ATC1.USBWakeup" }, +}; + +static const u32 t8112_wake_required[] = { 54 }; + static const struct apple_sleep_ops t8112_sleep_ops = { .deep_wfi_arm = t8112_deep_wfi_arm, .resume = cpu_resume, @@ -677,16 +695,19 @@ static const struct apple_sleep_soc t8112_sleep_soc = { .pmu_sleep_val = 0x50, .spmi_notify_sleep = 0x2000001, .wake_mask = 0x08, - .wake_status = 0x24, - .wake_words = 7, - .wake_last_word = GENMASK(16, 0), + .wake_status = 0x1c, + .wake_words = 5, + .wake_last_word = 0x03ffffff, + .wake_names = t8112_wake_names, + .nwake_names = ARRAY_SIZE(t8112_wake_names), + .wake_required = t8112_wake_required, + .nwake_required = ARRAY_SIZE(t8112_wake_required), .ps_aon_debug_switch = T8112_AON_DEBUG_SWITCH, .ps = { .disp = { { T8112_PS_DISP0_CPU0, T8112_PS_DISP0_FE, T8112_PS_DISP0_SYS } }, .sio_cpu = T8112_PS_SIO_CPU, .sep = T8112_PS_SEP, .gpio = T8112_PS_GPIO, - .ans = T8112_PS_ANS, .apcie_gp = T8112_PS_APCIE_GP, .apcie_st = T8112_PS_APCIE_ST, }, From f77b6e4781f80e5d1a75791681dad63e9bd647b9 Mon Sep 17 00:00:00 2001 From: WJW Date: Thu, 26 Nov 2026 22:16:18 +0800 Subject: [PATCH 12/23] soc: apple: sleep: clean T8112 RAM, kernel image, page tables, and WFI stub past SLC Before stopping MCC channels and entering deep WFI on T8112, clean used RAM, the kernel image, percpu areas, kernel page tables, and sleep resume state past SLC into DRAM (reusing the T8122 PoP/PoC helpers), and clean t8142_el1_wfi_stub at probe time. Signed-off-by: WJW --- drivers/soc/apple/sleep-t8112.h | 17 +++++++++++++++++ drivers/soc/apple/sleep.c | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h index 2e682cc281eda..099ea07f20061 100644 --- a/drivers/soc/apple/sleep-t8112.h +++ b/drivers/soc/apple/sleep-t8112.h @@ -189,6 +189,17 @@ static int t8112_sleep_map_regs(struct apple_sleep *s) return ret; } + /* Ensure the EL1 deep-WFI stub is clean in DRAM before cores jump to it. */ + { + bool pcore = t8122_is_pcore(); + u64 hid4_orig = t8122_read_hid4(pcore); + + t8122_write_hid4(pcore, hid4_orig & ~T8112_HID4_DISABLE_DC_MVA); + t8122_clean_range_slc((unsigned long)t8142_el1_wfi_stub, + (unsigned long)t8142_el1_wfi_stub_end); + t8122_write_hid4(pcore, hid4_orig); + } + s->driver_down = devm_bitmap_zalloc(s->dev, resource_size(&s->ps_res) / 4, GFP_KERNEL); if (!s->driver_down) return -ENOMEM; @@ -490,11 +501,17 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) pcore = t8112_is_pcore(); hid4_orig = t8112_read_hid4(pcore); t8112_write_hid4(pcore, hid4_orig & ~T8112_HID4_DC_MASK); + t8122_clean_used_ram(); + t8122_clean_kernel_image(); + t8122_clean_percpu_slc(); + t8122_clean_all_kptables(); + t8122_clean_state_poc(s); t8112_dcache_clean_all_levels(); if (s->mbox) t8112_clean_range_slc((unsigned long)s->mbox, (unsigned long)(s->mbox + 1)); t8112_clean_range_slc((unsigned long)s, (unsigned long)(s + 1)); + t8112_clean_range_slc((unsigned long)&t8112, (unsigned long)(&t8112 + 1)); t8112_clean_range_slc((unsigned long)current, (unsigned long)current + sizeof(*current)); t8112_clean_range_slc((unsigned long)task_stack_page(current), diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 8670bf8018cd0..7d54ef94b72d3 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -10162,8 +10162,8 @@ static const struct apple_sleep_soc t8142_sleep_soc = { }; #include "sleep-t8103.h" -#include "sleep-t8112.h" #include "sleep-t8122.h" +#include "sleep-t8112.h" /* * Qualified profiles expose system sleep. Inventory-only profiles match for a From 65f4a9b3bac66399dc174d3ed94236c5e8ec9c51 Mon Sep 17 00:00:00 2001 From: WJW Date: Fri, 27 Nov 2026 15:38:05 +0800 Subject: [PATCH 13/23] irqchip/apple-aic: enable firmware suspend save/restore on T8112 T8112 (Apple M2) uses AICv2, which loses AIC2_CONFIG, AIC2_TIMEOUT, AIC2_CLUSTER_PRIO, per-IRQ configuration, and CPU0 FIQ/timer routing across a hardware deep sleep. Add a dedicated apple,t8112-aic match entry with fw_suspend enabled so aic_syscore_suspend/resume preserve and restore AIC2 state across suspend-to-RAM. Signed-off-by: WJW --- drivers/irqchip/irq-apple-aic.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c index a13eb5c1fcb2c..cb4924c9f03c1 100644 --- a/drivers/irqchip/irq-apple-aic.c +++ b/drivers/irqchip/irq-apple-aic.c @@ -319,6 +319,16 @@ static const struct aic_info aic2_info __initconst = { .local_fast_ipi = true, }; +static const struct aic_info aic2_t8112_info __initconst = { + .version = 2, + + .irq_cfg = AIC2_IRQ_CFG, + + .fast_ipi = true, + .local_fast_ipi = true, + .fw_suspend = true, +}; + static const struct aic_info aic3_info __initconst = { .version = 3, @@ -412,6 +422,10 @@ static const struct of_device_id aic_info_match[] = { .compatible = "apple,aic", .data = &aic1_info, }, + { + .compatible = "apple,t8112-aic", + .data = &aic2_t8112_info, + }, { .compatible = "apple,aic2", .data = &aic2_info, From 303fadba89e1e3127f74b11b08f99aa0ab5ae028 Mon Sep 17 00:00:00 2001 From: WJW Date: Fri, 27 Nov 2026 15:38:05 +0800 Subject: [PATCH 14/23] mfd: macsmc: enable deferred gen-1 sleep notice on T8112 T8112 uses gen-1 SMC sleep keys (pmVC/WKTP/MBSE) and defers the sleep notice until after coprocessor stops, matching T8103. Enable saved_enabled for apple,t8112-smc. Signed-off-by: WJW --- drivers/mfd/macsmc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index b174c06fe6f9b..a06f6009fc1b5 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -780,7 +780,8 @@ static int apple_smc_probe(struct platform_device *pdev) * its SMC hears last, after SEP and the other coprocessors stopped. */ if (of_machine_is_compatible("apple,j813") || - of_device_is_compatible(dev->of_node, "apple,t8103-smc")) + of_device_is_compatible(dev->of_node, "apple,t8103-smc") || + of_device_is_compatible(dev->of_node, "apple,t8112-smc")) smc->saved_enabled = true; smc->sram_base = devm_platform_get_and_ioremap_resource(pdev, 1, &smc->sram); if (IS_ERR(smc->sram_base)) From 51ca8202bfea23fd62dfe98d736930e1ab28c3ab Mon Sep 17 00:00:00 2001 From: WJW Date: Fri, 27 Nov 2026 15:38:05 +0800 Subject: [PATCH 15/23] soc: apple: sleep: complete T8112 hardware commit and wake sequences Complete the T8112 (Apple M2) deep-sleep commit and wake sequences verified on MacBook Air 13-inch (M2, J413): - Lower leftover PMGR/AON domains children-before-parents (GFX before PMP stop, followed by DISP0/DISPEXT/ISP/ATC/RMX/PMP/APCIE/GPIO/AON) and restore parent domains and AP pins on wake. - Wait for SEP gate on commit and restore SEP power state on wake. - Enable disabled NCO channels across commit so externally-clocked MCA domains do not hang BUSY, and restore them on wake. - Snapshot and restore SoC clock muxes and SPMI RTC alarm vector across commit/wake. - Save AIC masks and all wake-restore state before cleaning RAM past SLC and stopping MCC channels so they survive deep sleep in DRAM. - Wire gen-1 SMC keys, WD1 safety watchdog, and post-timer commit write. Signed-off-by: WJW --- arch/arm64/boot/dts/apple/t8112-j413.dts | 2 +- drivers/soc/apple/sleep-t8112.h | 326 +++++++++++++++++++---- 2 files changed, 275 insertions(+), 53 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8112-j413.dts b/arch/arm64/boot/dts/apple/t8112-j413.dts index 282fa6eb0d238..f91499dab6f53 100644 --- a/arch/arm64/boot/dts/apple/t8112-j413.dts +++ b/arch/arm64/boot/dts/apple/t8112-j413.dts @@ -598,6 +598,6 @@ }; &sleep { - apple,wake-enable = <14 54 76 81 133 134>; + apple,wake-enable = <3 12 14 54 76 81 133 134 155 184 208>; status = "okay"; }; diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h index 099ea07f20061..03c8342c48b5c 100644 --- a/drivers/soc/apple/sleep-t8112.h +++ b/drivers/soc/apple/sleep-t8112.h @@ -46,6 +46,9 @@ #define T8112_TVM_BUSY BIT(1) #define T8112_TVM_TIMEOUT_US 10000 +#define T8112_MUX_SOC 0x40000 +#define T8112_MUX_SOC_WORDS 64 + static const u32 t8112_mux_park[] = { 0x40040, 0x40048, 0x40044, 0x40038, 0x40034 }; static const u32 t8112_tvm[] = { 0x400, 0x800, 0xc00, 0x000 }; static const u32 t8112_auto_off[] = { 0x1b0, 0x1a8, 0x1b8 }; @@ -95,12 +98,67 @@ static const u32 t8112_ps_aon_wake_order[] = { T8112_AON_NUB_FABRIC, T8112_AON_ATC0_USB_AON, T8112_AON_ATC1_USB_AON, }; +#define T8112_PS_PCIE_REF 0x198 +#define T8112_PS_RMX0 0x350 +#define T8112_PS_RMX1 0x358 +#define T8112_PS_DISPEXT_SYS 0x380 +#define T8112_PS_DISPEXT_FE 0x388 +#define T8112_PS_DISPEXT_CPU0 0x3c8 +#define T8112_PS_PMP 0x410 +#define T8112_PS_ISP_SYS 0x438 +#define T8112_PS_ATC0_PCIE 0x460 +#define T8112_PS_ATC1_PCIE 0x488 + +/* Domains lowered children-before-parents at commit (GFX first while PMP is running). */ +static const u32 t8112_commit_off[] = { + T8112_PS_GFX, /* 0: lowered before PMP stop */ + T8112_PS_DISP0_CPU0, + T8112_PS_DISP0_FE, + T8112_PS_DISP0_SYS, + T8112_PS_DISPEXT_CPU0, + T8112_PS_DISPEXT_FE, + T8112_PS_DISPEXT_SYS, + T8112_PS_ISP_SYS, + T8112_PS_ATC1_PCIE, + T8112_PS_ATC1_COMMON, + T8112_PS_ATC0_PCIE, + T8112_PS_ATC0_COMMON, + T8112_PS_RMX0, + T8112_PS_RMX1, + T8112_PS_PMP, + T8112_PS_APCIE_ST, + T8112_PS_APCIE_GP, + T8112_PS_APCIE, + T8112_PS_PCIE_REF, + T8112_PS_GPIO, +}; + +static const u32 t8112_aon_commit_off[] = { + T8112_AON_ATC0_USB, + T8112_AON_ATC1_USB, + T8112_AON_ATC0_USB_AON, + T8112_AON_ATC1_USB_AON, + T8112_AON_DEBUG_SWITCH, + 0x58, /* debug_gated */ + 0x78, /* msg */ +}; + static struct { void __iomem *clk_mux; void __iomem *mcc_ctl; void __iomem *mcc[5]; + void __iomem *pmp_asc; + void __iomem *pmp_mbox; + void __iomem *nco; + void __iomem *ed[2][4]; u32 notify_saved; bool notify_staged; + u32 spmi_vec_saved; + u32 nco_forced; + u32 commit_saved_ps[ARRAY_SIZE(t8112_commit_off)]; + u32 commit_lowered; + u32 aon_lowered; + u32 mux_snap[T8112_MUX_SOC_WORDS]; u32 mux_saved[ARRAY_SIZE(t8112_mux_park)]; u32 tvm_saved[ARRAY_SIZE(t8112_tvm)]; u32 auto_saved[ARRAY_SIZE(t8112_auto_off)]; @@ -200,6 +258,17 @@ static int t8112_sleep_map_regs(struct apple_sleep *s) t8122_write_hid4(pcore, hid4_orig); } + t8112.pmp_asc = t8103_ioremap(s, T8103_PMP_ASC, 0x100); + t8112.pmp_mbox = t8103_ioremap(s, T8103_PMP_MBOX, 0x1000); + t8112.nco = t8103_ioremap(s, T8103_NCO, T8103_NCO_CHANS * T8103_NCO_STRIDE); + for (i = 0; i < 2; i++) { + unsigned int c; + + for (c = 0; c < 4; c++) + t8112.ed[i][c] = t8103_ioremap(s, T8103_ED + i * T8103_ED_CLUSTER + + c * T8103_ED_CORE, 0x1000); + } + s->driver_down = devm_bitmap_zalloc(s->dev, resource_size(&s->ps_res) / 4, GFP_KERNEL); if (!s->driver_down) return -ENOMEM; @@ -396,26 +465,6 @@ static void t8112_aon_lower(struct apple_sleep *s, u32 off) writel((val & ~PS_TARGET) | PS_FLAGS, s->ps_aon + off); } -static void t8112_sleep_atc_off(struct apple_sleep *s) -{ - static const struct { - u32 usb, usb_aon, common; - } port[] = { - { T8112_AON_ATC0_USB, T8112_AON_ATC0_USB_AON, T8112_PS_ATC0_COMMON }, - { T8112_AON_ATC1_USB, T8112_AON_ATC1_USB_AON, T8112_PS_ATC1_COMMON }, - }; - unsigned int i; - - if (!s->ps_aon) - return; - for (i = 0; i < ARRAY_SIZE(port); i++) { - t8112_aon_lower(s, port[i].usb); - t8112_aon_lower(s, port[i].usb_aon); - sleep_ps_lower(s, port[i].common); - sleep_ps_wait_off(s, port[i].common); - } -} - static void t8112_mcc_clear_bits64(void __iomem *reg) { u64 q = readq(reg); @@ -487,16 +536,97 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) unsigned int i; u32 val; + apple_sleep_set_wd2(s, WDT_SUSPEND_SECS); + sleep_ps_save(s); - t8112_sleep_atc_off(s); + + /* Wait for SEP to gate after its sleep message, as on T8103. */ + if (apple_sleep_enclave.stop) { + val = readl(s->ps + T8112_PS_SEP); + writel((val & ~0x0f000700U) | BIT(10), s->ps + T8112_PS_SEP); + readl_poll_timeout_atomic(s->ps + T8112_PS_SEP, val, + !FIELD_GET(PS_ACTUAL, val), 10, + T8103_SEP_GATE_US); + } + + /* Lower GFX while PMP is still running, then stop PMP. */ + t8112.commit_lowered = 0; + if (sleep_ps_on(s, t8112_commit_off[0])) { + t8112.commit_saved_ps[0] = readl(s->ps + t8112_commit_off[0]); + t8112.commit_lowered |= BIT(0); + sleep_ps_lower(s, t8112_commit_off[0]); + sleep_ps_wait_off(s, t8112_commit_off[0]); + } + t8103_asc_stop(t8112.pmp_asc, t8112.pmp_mbox); + + /* Lower pmgr_mini (ps_aon) domains left on by USB/debug/msg. */ + t8112.aon_lowered = 0; + if (s->ps_aon) { + for (i = 0; i < ARRAY_SIZE(t8112_aon_commit_off); i++) { + void __iomem *reg = s->ps_aon + t8112_aon_commit_off[i]; + u32 av = readl(reg); + + if (!FIELD_GET(PS_ACTUAL, av)) + continue; + t8112_aon_lower(s, t8112_aon_commit_off[i]); + if (!readl_poll_timeout_atomic(reg, av, !FIELD_GET(PS_ACTUAL, av), 1, 10000)) + t8112.aon_lowered |= BIT(i); + } + } + + /* Lower remaining leftover ps domains children-before-parents. */ + for (i = 1; i < ARRAY_SIZE(t8112_commit_off); i++) { + if (!sleep_ps_on(s, t8112_commit_off[i])) + continue; + t8112.commit_saved_ps[i] = readl(s->ps + t8112_commit_off[i]); + t8112.commit_lowered |= BIT(i); + sleep_ps_lower(s, t8112_commit_off[i]); + sleep_ps_wait_off(s, t8112_commit_off[i]); + } + + /* Enable disabled NCO channels so externally-clocked ps_mca0..5 don't hang BUSY. */ + t8112.nco_forced = 0; + if (t8112.nco) { + for (i = 0; i < T8103_NCO_CHANS; i++) { + void __iomem *reg = t8112.nco + i * T8103_NCO_STRIDE; + + val = readl(reg); + if (!(val & T8103_NCO_CTRL_EN)) { + writel(val | T8103_NCO_CTRL_EN, reg); + t8112.nco_forced |= BIT(i); + } + } + } + writel(0, s->wdt + WDT_WD0_CTL); + /* + * Snapshot all wake-restore state AND mask AIC BEFORE cleaning RAM past SLC + * and stopping MCC channels, so ic->sleep_masks and t8112.* are guaranteed + * to survive deep sleep in DRAM! + */ + for (i = 0; i < ARRAY_SIZE(t8112.mux_snap); i++) + t8112.mux_snap[i] = readl(t8112.clk_mux + T8112_MUX_SOC + i * 4); + for (i = 0; i < ARRAY_SIZE(t8112_mux_park); i++) + t8112.mux_saved[i] = readl(t8112.clk_mux + t8112_mux_park[i]); + for (i = 0; i < ARRAY_SIZE(t8112_tvm); i++) + t8112.tvm_saved[i] = readl(s->cllt + t8112_tvm[i]); + t8112.dcs_saved = readl(t8112.clk_mux + T8112_DCS_PERF_OFF); + for (i = 0; i < ARRAY_SIZE(t8112_auto_off); i++) + t8112.auto_saved[i] = readl(s->ps + t8112_auto_off[i]); + t8112.spmi_vec_saved = readl(s->spmi + T8103_SPMI_VEC_ENABLE); + t8112.commit_saved = true; + aic_sleep_mask_all(); + aic_sleep_ack(); if (s->mbox) { s->resumes_before = READ_ONCE(s->mbox->resumes); WRITE_ONCE(s->mbox->resume_pa, __pa_symbol(s->soc->ops->resume)); } + t8103_pac_saved[0] = read_sysreg_s(sys_reg(3, 4, 15, 0, 4)); + t8103_pac_saved[1] = read_sysreg_s(sys_reg(3, 6, 15, 12, 2)); + t8103_pac_saved[2] = 1; pcore = t8112_is_pcore(); hid4_orig = t8112_read_hid4(pcore); @@ -507,6 +637,8 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) t8122_clean_all_kptables(); t8122_clean_state_poc(s); t8112_dcache_clean_all_levels(); + t8112_clean_range_slc((unsigned long)t8103_pac_saved, + (unsigned long)(t8103_pac_saved + ARRAY_SIZE(t8103_pac_saved))); if (s->mbox) t8112_clean_range_slc((unsigned long)s->mbox, (unsigned long)(s->mbox + 1)); @@ -521,20 +653,16 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) t8112_mcc_channel_stop(); - for (i = 0; i < ARRAY_SIZE(t8112_mux_park); i++) { - t8112.mux_saved[i] = readl(t8112.clk_mux + t8112_mux_park[i]); + for (i = 0; i < ARRAY_SIZE(t8112_mux_park); i++) writel(T8112_MUX_PARK_VAL, t8112.clk_mux + t8112_mux_park[i]); - } for (i = 0; i < ARRAY_SIZE(t8112_tvm); i++) { - t8112.tvm_saved[i] = readl(s->cllt + t8112_tvm[i]); writel(0, s->cllt + t8112_tvm[i]); readl_poll_timeout_atomic(s->cllt + t8112_tvm[i] + T8112_TVM_IDLE_OFF, val, !(val & T8112_TVM_BUSY), 1, T8112_TVM_TIMEOUT_US); } - t8112.dcs_saved = readl(t8112.clk_mux + T8112_DCS_PERF_OFF); t8112_dcs_write(0x335); t8112_dcs_write(0x553); @@ -543,16 +671,26 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) writel(0, s->cluster + T8112_CLUSTER_E); write_sysreg(ARCH_TIMER_CTRL_IT_MASK, cntp_ctl_el0); write_sysreg(ARCH_TIMER_CTRL_IT_MASK, cntv_ctl_el0); - sysreg_clear_set_s(SYS_APL_DEEP_SLEEP, 0, DEEP_SLEEP_ENABLE); writel(0, s->cluster + T8112_CLUSTER_P); for (i = 0; i < ARRAY_SIZE(t8112_auto_off); i++) { - val = readl(s->ps + t8112_auto_off[i]); - t8112.auto_saved[i] = val; + val = t8112.auto_saved[i]; if (val & PS_AUTO_ENABLE) writel(val & ~PS_AUTO_ENABLE, s->ps + t8112_auto_off[i]); } - t8112.commit_saved = true; + + /* Ack and enable PMU RTC alarm SPMI vector so rtcwake reaches wake source 54. */ + writel(T8103_SPMI_VEC_RTC, s->spmi + T8103_SPMI_VEC_ACK); + writel(t8112.spmi_vec_saved | T8103_SPMI_VEC_RTC, s->spmi + T8103_SPMI_VEC_ENABLE); + + aic_sleep_ack(); + dsb(sy); +} + +static void t8112_post_timer(struct apple_sleep *s) +{ + dsb(sy); + writel(1, s->commit); } static void t8112_sleep_pre_commit(struct apple_sleep *s) @@ -560,7 +698,13 @@ static void t8112_sleep_pre_commit(struct apple_sleep *s) bool pcore = t8112_is_pcore(); u64 hid4_orig = t8112_read_hid4(pcore); + t8103_pac_saved[0] = read_sysreg_s(sys_reg(3, 4, 15, 0, 4)); + t8103_pac_saved[1] = read_sysreg_s(sys_reg(3, 6, 15, 12, 2)); + t8103_pac_saved[2] = 1; + t8112_write_hid4(pcore, hid4_orig & ~T8112_HID4_DISABLE_DC_MVA); + t8112_clean_range_slc((unsigned long)t8103_pac_saved, + (unsigned long)(t8103_pac_saved + ARRAY_SIZE(t8103_pac_saved))); if (s->mbox) t8112_clean_range_slc((unsigned long)s->mbox, (unsigned long)(s->mbox + 1)); @@ -577,7 +721,7 @@ static void t8112_sleep_wake(struct apple_sleep *s) writel(CLUSTER_ON, s->cluster + T8112_CLUSTER_E); s->cluster_e_ret = readl_poll_timeout_atomic(s->cluster + T8112_CLUSTER_E, val, - val & CLUSTER_E_READY, 1, + !(val & T8103_CLUSTER_BUSY), 1, CLUSTER_TIMEOUT_US); writel(CLUSTER_ON, s->cluster + T8112_CLUSTER_P); @@ -589,14 +733,70 @@ static void t8112_sleep_wake(struct apple_sleep *s) if (t8112.auto_saved[i] & PS_AUTO_ENABLE) writel(t8112.auto_saved[i], s->ps + t8112_auto_off[i]); - if (t8112.dcs_saved) - t8112_dcs_write(t8112.dcs_saved & ~T8112_DCS_BUSY); - for (i = ARRAY_SIZE(t8112_tvm) - 1; i >= 0; i--) writel(t8112.tvm_saved[i], s->cllt + t8112_tvm[i]); - for (i = ARRAY_SIZE(t8112_mux_park) - 1; i >= 0; i--) - writel(t8112.mux_saved[i], t8112.clk_mux + t8112_mux_park[i]); + /* Restore any SoC clock mux that the sleep engine parked or turned off. */ + for (i = 0; i < ARRAY_SIZE(t8112.mux_snap); i++) { + void __iomem *reg = t8112.clk_mux + T8112_MUX_SOC + i * 4; + + if (readl(reg) == t8112.mux_snap[i] || !(t8112.mux_snap[i] & BIT(31))) + continue; + writel(t8112.mux_snap[i], reg); + readl_poll_timeout_atomic(reg, val, !(val & T8103_MUX_BUSY), 1, + T8103_MUX_TIMEOUT_US); + } + for (i = ARRAY_SIZE(t8112_mux_park) - 1; i >= 0; i--) { + void __iomem *reg = t8112.clk_mux + t8112_mux_park[i]; + + writel(t8112.mux_saved[i], reg); + readl_poll_timeout_atomic(reg, val, !(val & T8103_MUX_BUSY), 1, + T8103_MUX_TIMEOUT_US); + } + + if (t8112.nco) { + for (i = 0; i < T8103_NCO_CHANS; i++) { + if (t8112.nco_forced & BIT(i)) { + void __iomem *reg = t8112.nco + i * T8103_NCO_STRIDE; + + writel(readl(reg) & ~T8103_NCO_CTRL_EN, reg); + } + } + t8112.nco_forced = 0; + } + + writel(t8112.spmi_vec_saved, s->spmi + T8103_SPMI_VEC_ENABLE); + + if (apple_sleep_enclave.stop) { + val = readl(s->ps + T8112_PS_SEP); + writel((val & ~0x0f000700U) | (0xfU << 24) | BIT(9), s->ps + T8112_PS_SEP); + } + + /* + * Restore parent domains (GPIO, APCIE, PMP, RMX, ATC, GFX) parents-first; + * leave DISP0/DISPEXT/ISP to their own drivers' resume paths. + */ + for (i = ARRAY_SIZE(t8112_commit_off) - 1; i >= 0; i--) { + u32 off = t8112_commit_off[i]; + + if (!(t8112.commit_lowered & BIT(i))) + continue; + if (off == T8112_PS_DISP0_CPU0 || off == T8112_PS_DISP0_FE || + off == T8112_PS_DISP0_SYS || off == T8112_PS_DISPEXT_CPU0 || + off == T8112_PS_DISPEXT_FE || off == T8112_PS_DISPEXT_SYS || + off == T8112_PS_ISP_SYS) + continue; + sleep_ps_restore(s->ps + off, t8112.commit_saved_ps[i]); + } + t8112.commit_lowered = 0; + + if (s->ps_aon) { + for (i = ARRAY_SIZE(t8112_aon_commit_off) - 1; i >= 0; i--) { + if (t8112.aon_lowered & BIT(i)) + sleep_ps_restore(s->ps_aon + t8112_aon_commit_off[i], 0xf); + } + t8112.aon_lowered = 0; + } t8112.commit_saved = false; } @@ -605,6 +805,7 @@ static void t8112_sleep_wake(struct apple_sleep *s) sleep_ps_rewake(s); sleep_ps_raise(s, T8112_PS_GPIO); s->pins_lost = s->pins_saved_valid; + apple_sleep_restore_pins(); val = readl(s->ps + T8112_PS_SEP); if (val & PS_DEV_DISABLE) @@ -612,6 +813,8 @@ static void t8112_sleep_wake(struct apple_sleep *s) writel(PWRGATE_ON, s->pwrgate + T8112_PWRGATE_E); writel(PWRGATE_ON, s->pwrgate + T8112_PWRGATE_P); + + apple_sleep_set_wd2(s, T8103_WDT_RESUME_SECS); } static void t8112_aic_mask_noop(void) @@ -620,21 +823,36 @@ static void t8112_aic_mask_noop(void) static void t8112_deep_wfi_arm(void) { + u64 mpidr = read_cpuid_mpidr(); + unsigned int cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1); + unsigned int core = MPIDR_AFFINITY_LEVEL(mpidr, 0); bool pcore = t8112_is_pcore(); u64 hid4 = t8112_read_hid4(pcore); + u64 cyc = read_sysreg_s(T8103_CYC_OVRD); + u64 acc = read_sysreg_s(T8103_ACC_OVRD); + + if (cluster < 2 && core < 4 && t8112.ed[cluster][core]) { + writel_relaxed(0xc5acce55U, t8112.ed[cluster][core] + 0xfb0); + writel_relaxed(0, t8112.ed[cluster][core] + 0x310); + dsb(sy); + } t8112_write_hid4(pcore, hid4 & ~T8112_HID4_DC_MASK); t8112_dcache_clean_all_levels(); t8112_write_hid4(pcore, hid4); - sysreg_clear_set_s(T8112_SYS_CYC_OVRD, 0, T8112_CYC_WFI_MODE); - isb(); - sysreg_clear_set_s(SYS_APL_DEEP_SLEEP, 0, DEEP_SLEEP_ENABLE); - isb(); - if (is_kernel_in_hyp_mode()) { - dsb(sy); - t8142_el1_wfi(); - } + cyc &= ~(T8103_CYC_WFI_MODE | T8103_CYC_IRQ_MODE | T8103_CYC_FIQ_MODE); + cyc |= FIELD_PREP(T8103_CYC_WFI_MODE, 3) | T8103_CYC_DISABLE_WFI_RET; + write_sysreg_s(0, T8103_PMCR0); + acc &= ~(T8103_ACC_PWR_DN_SRM | T8103_ACC_DIS_L2_FLUSH | + T8103_ACC_TRAIN_DOWN_LINK | T8103_ACC_POWER_DOWN_CPM); + acc |= FIELD_PREP(T8103_ACC_PWR_DN_SRM, 3) | + FIELD_PREP(T8103_ACC_DIS_L2_FLUSH, 2) | + FIELD_PREP(T8103_ACC_TRAIN_DOWN_LINK, 3) | + FIELD_PREP(T8103_ACC_POWER_DOWN_CPM, 3) | + T8103_ACC_DISABLE_PIO_ON_WFI | T8103_ACC_DEEP_SLEEP; + t8103_cpu_off(cyc, acc); + unreachable(); } static int t8112_sleep_cpu_prepare(u64 mpidr) @@ -656,19 +874,24 @@ static const struct apple_sleep_gate_coproc t8112_gate_coprocs[] = { }; static const struct apple_sleep_wake_name t8112_wake_names[] = { + { 3, "AOP.CPUWakeupAP" }, + { 12, "AOP.GPIO.IRQ4" }, { 14, "AOP.GPIO.IRQ6" }, { 54, "NUB.SPMI0Sw3IRQ" }, { 76, "SMC.CPUWakeupAP" }, { 81, "SMC.OutboxNotEmpty" }, { 133, "ATC0.USBWakeup" }, { 134, "ATC1.USBWakeup" }, + { 155, "NUB.SPMI0.SW3" }, + { 184, "SMC.CPUWakeupAP.M3" }, + { 208, "SMC.OutboxNotEmpty.M3" }, }; static const u32 t8112_wake_required[] = { 54 }; static const struct apple_sleep_ops t8112_sleep_ops = { .deep_wfi_arm = t8112_deep_wfi_arm, - .resume = cpu_resume, + .resume = t8103_resume_stub, .aic_mask_all = t8112_aic_mask_noop, .aic_ack = aic_sleep_ack, .aic_restore = aic_sleep_restore, @@ -679,6 +902,7 @@ static const struct apple_sleep_ops t8112_sleep_ops = { .undo_regs = t8112_sleep_undo_regs, .commit_regs = t8112_sleep_commit_regs, .pre_commit = t8112_sleep_pre_commit, + .post_timer = t8112_post_timer, .wake = t8112_sleep_wake, .cpu_prepare = t8112_sleep_cpu_prepare, .cpu_restore = t8112_sleep_cpu_restore, @@ -687,14 +911,12 @@ static const struct apple_sleep_ops t8112_sleep_ops = { static const struct apple_sleep_soc t8112_sleep_soc = { .ops = &t8112_sleep_ops, .untested = true, - .pen_deep = true, - .el1_wfi = true, .early_context = true, .early_cpu_wfi = true, .boot_wfi_delay_ms = 2, .no_pmu_notes = true, - .no_wd2 = true, - .display_no_restart = true, + .wdt_wd1 = true, + .smc_gen1_keys = true, .boot_mpidr = 0x0, .cpu_count = 8, .cpu_clusters = 2, @@ -712,9 +934,9 @@ static const struct apple_sleep_soc t8112_sleep_soc = { .pmu_sleep_val = 0x50, .spmi_notify_sleep = 0x2000001, .wake_mask = 0x08, - .wake_status = 0x1c, - .wake_words = 5, - .wake_last_word = 0x03ffffff, + .wake_status = 0x24, + .wake_words = 7, + .wake_last_word = GENMASK(16, 0), .wake_names = t8112_wake_names, .nwake_names = ARRAY_SIZE(t8112_wake_names), .wake_required = t8112_wake_required, From dd712175278920d36654d2101d4202ce4a7e2d0c Mon Sep 17 00:00:00 2001 From: WJW Date: Fri, 27 Nov 2026 15:38:05 +0800 Subject: [PATCH 16/23] drm/apple: dcp: add T8112 S2R display power and DART layout Wire T8112 (Apple M2) DCP suspend-to-RAM display power and DART layout (matching T8103 for firmware 27.x warm restart): - Add dcp_power display-power node and apple,display-power phandle in t8112.dtsi. - Add dcp_s2r_t8112 power/stream layout and enable hw.s2r on apple_dcp_hw_t8112. - Guard apple_dart_display_streams() on apple,t8112-dart so it enables streams and invalidates TLB without touching the out-of-range 0x4060 register. Signed-off-by: WJW --- arch/arm64/boot/dts/apple/t8112.dtsi | 8 +++++ drivers/gpu/drm/apple/dcp.c | 31 ++++++++++++++++++++ drivers/iommu/apple-dart.c | 44 ++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index 571493ac5874a..2f2658c9e6b73 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -792,6 +792,7 @@ dcp: dcp@231c00000 { compatible = "apple,t8112-dcp", "apple,dcp"; + apple,display-power = <&dcp_power>; mboxes = <&dcp_mbox>; mbox-names = "mbox"; iommus = <&dcp_dart 5 0x8 0x00000000 0x7 0xffff0000>; @@ -1311,6 +1312,12 @@ /* child nodes are added in t8103-pmgr.dtsi */ }; + dcp_power: display-power@23b700000 { + compatible = "apple,t8112-display-power", "apple,t8103-display-power"; + reg = <0x2 0x3b700000 0x0 0x14000>; + reg-names = "ps"; + }; + sleep: sleep@23b700000 { compatible = "apple,t8112-sleep"; reg = <0x2 0x3b700000 0x0 0x14000>, @@ -2036,6 +2043,7 @@ dcpext: dcp@271c00000 { compatible = "apple,t8112-dcpext", "apple,dcpext"; + apple,display-power = <&dcp_power>; mboxes = <&dcpext_mbox>; mbox-names = "mbox"; iommus = <&dcpext_dart 5 0x8 0x00000000 0x7 0xffff0000>; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index e90ac4e251c8e..73e5a0e87ad69 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -9788,6 +9788,22 @@ static const struct dcp_s2r_layout dcp_s2r_t8103_ext = { .disp_streams = BIT(0) | BIT(4), }; +static const struct dcp_s2r_layout dcp_s2r_t8112 = { + .disp_cpu = 0x10000, + .disp_fe = 0x378, + .disp_sys = 0x370, + .dcp_streams = BIT(5), + .disp_streams = BIT(0) | BIT(4), +}; + +static const struct dcp_s2r_layout dcp_s2r_t8112_ext = { + .disp_cpu = 0x3c8, + .disp_fe = 0x388, + .disp_sys = 0x380, + .dcp_streams = BIT(5), + .disp_streams = BIT(0) | BIT(4), +}; + /* TEST: J813 external processors, ADT DISPEXT0/1 power words. */ static const struct dcp_s2r_layout dcp_s2r_t8142_ext[] = { { .disp_cpu = 0x428, .disp_fe = 0x418, .disp_sys = 0x308, @@ -11745,6 +11761,20 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t6020_dcpext = { static const struct apple_dcp_hw_data apple_dcp_hw_t8112 = { .num_dptx_ports = 2, + .s2r = true, + .s2r_no_secure_port = true, + .map_reg_dart = true, + .s2r_disp_dart_with_dcp = true, + .s2r_layout = &dcp_s2r_t8112, +}; + +static const struct apple_dcp_hw_data apple_dcp_hw_t8112_dcpext = { + .num_dptx_ports = 2, + .s2r_ext = true, + .s2r_no_secure_port = true, + .map_reg_dart = true, + .s2r_disp_dart_with_dcp = true, + .s2r_layout = &dcp_s2r_t8112_ext, }; /* The internal T8140 endpoint uses the H17P method profile. */ @@ -11955,6 +11985,7 @@ static const struct of_device_id of_match[] = { { .compatible = "apple,t8103-dcp", .data = &apple_dcp_hw_t8103, }, { .compatible = "apple,t8103-dcpext", .data = &apple_dcp_hw_t8103_dcpext, }, { .compatible = "apple,t8112-dcp", .data = &apple_dcp_hw_t8112, }, + { .compatible = "apple,t8112-dcpext", .data = &apple_dcp_hw_t8112_dcpext, }, { .compatible = "apple,t8140-dcp", .data = &apple_dcp_hw_t8140, }, { .compatible = "apple,t8140-dcpext", .data = &apple_dcp_hw_t8140_external, }, { .compatible = "apple,t8142-dcp", .data = &apple_dcp_hw_t8142, }, diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index dbb9dd9ca06b4..700d8cd656ead 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -9039,6 +9039,48 @@ int apple_dart_display_keep(struct device *dev, u32 streams, bool save) } EXPORT_SYMBOL_GPL(apple_dart_display_keep); +static int apple_dart_t8112_display_streams(struct apple_dart *dart, u32 streams, + bool on, bool flush) +{ + unsigned long bits = streams; + unsigned int sid; + u32 status; + int ret; + + /* T8112 display DARTs map a 0x4000-byte MMIO window; stay within it. */ + if (on) { + struct apple_dart_stream_map all = { .dart = dart }; + + dart->sleep_flushed = false; + WRITE_ONCE(dart->display_tlb_stale, false); + WRITE_ONCE(dart->display_dark, false); + writel(streams, dart->regs + DART_T8110_ENABLE_STREAMS); + bitmap_fill(all.sidmap, dart->num_streams); + dart->hw->invalidate_tlb(&all); + return 0; + } + + if (flush && dart->sleep_flushed) + return 0; + + for_each_set_bit(sid, &bits, BITS_PER_TYPE(streams)) + writel(BIT(sid), dart->regs + DART_T8110_DISABLE_STREAMS); + if (!flush) + return 0; + + writel(0xa000, dart->regs + DART_T8110_TLB_CMD); + ret = readl_poll_timeout_atomic(dart->regs + DART_T8110_TLB_CMD, status, + !(status & DART_T8110_TLB_CMD_BUSY), 1, + DART_T8110_FLUSH_BUSY_TIMEOUT); + if (ret) { + dev_err(dart->dev, "flush for a power-down didn't finish: %#x\n", status); + return ret; + } + dart->sleep_flushed = true; + + return 0; +} + int apple_dart_display_streams(struct device *dev, u32 streams, bool on, bool flush) { struct apple_dart *dart = dev_get_drvdata(dev); @@ -9049,6 +9091,8 @@ int apple_dart_display_streams(struct device *dev, u32 streams, bool on, bool fl if (dart->hw->type == DART_T8020) return apple_dart_t8020_display_streams(dart, streams, on, flush); + if (of_device_is_compatible(dev->of_node, "apple,t8112-dart")) + return apple_dart_t8112_display_streams(dart, streams, on, flush); if (on) { apple_dart_gapf_protect(dart); From a23721b4375ae15b5c861b64dfc131ba87cffeb1 Mon Sep 17 00:00:00 2001 From: Satya Benson Date: Sat, 28 Nov 2026 16:19:37 +0800 Subject: [PATCH 17/23] soc: apple: sleep: fix T8112 SLC write-back and L2 cache clean across S2R Clear HID4/EHID4 DISABLE_DC_SW_L2 across the CCIDX-aware t8112_cpu_off() path so L2 set/way cleans take effect, and disable/write back the 4 MCC SLC planes in t8112_slc_off() before deep sleep (restoring them in t8112_slc_on() on wake) along with task_stack_page(current) cache cleans. Signed-off-by: Satya Benson Signed-off-by: WJW --- drivers/soc/apple/sleep-t8112.h | 219 ++++++++++++++++++++++++++++++-- 1 file changed, 209 insertions(+), 10 deletions(-) diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h index 03c8342c48b5c..bbefe0d737652 100644 --- a/drivers/soc/apple/sleep-t8112.h +++ b/drivers/soc/apple/sleep-t8112.h @@ -49,6 +49,16 @@ #define T8112_MUX_SOC 0x40000 #define T8112_MUX_SOC_WORDS 64 +#define T8112_MCC_PLANES_BASE 0x200000000ULL +#define T8112_MCC_PLANE_STRIDE 0x40000 +#define T8112_MCC_NPLANES 4 +#define T8112_MCC_CACHE_DISABLE 0x424 +#define T8112_MCC_WAYS 0x1c00 +#define T8112_MCC_WAYS_STATUS 0x1c04 +#define T8112_MCC_WAYS_DATA GENMASK(14, 10) +#define T8112_MCC_WAYS_TAG GENMASK(9, 5) +#define T8112_MCC_TIMEOUT_US 100000 + static const u32 t8112_mux_park[] = { 0x40040, 0x40048, 0x40044, 0x40038, 0x40034 }; static const u32 t8112_tvm[] = { 0x400, 0x800, 0xc00, 0x000 }; static const u32 t8112_auto_off[] = { 0x1b0, 0x1a8, 0x1b8 }; @@ -147,6 +157,11 @@ static struct { void __iomem *clk_mux; void __iomem *mcc_ctl; void __iomem *mcc[5]; + void __iomem *mcc_planes; + u32 slc_ways; + u32 slc_off_bad; + u32 slc_on_bad; + bool slc_disabled; void __iomem *pmp_asc; void __iomem *pmp_mbox; void __iomem *nco; @@ -258,6 +273,8 @@ static int t8112_sleep_map_regs(struct apple_sleep *s) t8122_write_hid4(pcore, hid4_orig); } + t8112.mcc_planes = t8103_ioremap(s, T8112_MCC_PLANES_BASE, + T8112_MCC_NPLANES * T8112_MCC_PLANE_STRIDE); t8112.pmp_asc = t8103_ioremap(s, T8103_PMP_ASC, 0x100); t8112.pmp_mbox = t8103_ioremap(s, T8103_PMP_MBOX, 0x1000); t8112.nco = t8103_ioremap(s, T8103_NCO, T8103_NCO_CHANS * T8103_NCO_STRIDE); @@ -465,6 +482,89 @@ static void t8112_aon_lower(struct apple_sleep *s, u32 off) writel((val & ~PS_TARGET) | PS_FLAGS, s->ps_aon + off); } +/* + * Stop SLC allocation and power down all 4 MCC planes so every dirty SLC line + * is written back to DRAM before deep sleep loses MCC power. + */ +static void t8112_slc_off(void) +{ + unsigned int p; + u32 v, ways; + + t8112.slc_disabled = false; + t8112.slc_off_bad = 0; + if (!t8112.mcc_planes) + return; + + v = readl(t8112.mcc_planes + T8112_MCC_WAYS_STATUS); + ways = FIELD_GET(T8112_MCC_WAYS_DATA, v); + if (!ways) + ways = FIELD_GET(T8112_MCC_WAYS_TAG, v); + if (!ways) + return; + + t8112.slc_ways = ways; + for (p = 0; p < T8112_MCC_NPLANES; p++) { + void __iomem *base = t8112.mcc_planes + p * T8112_MCC_PLANE_STRIDE; + + writel(1, base + T8112_MCC_CACHE_DISABLE); + } + dsb(sy); + + for (p = 0; p < T8112_MCC_NPLANES; p++) { + void __iomem *base = t8112.mcc_planes + p * T8112_MCC_PLANE_STRIDE; + + writel(0, base + T8112_MCC_WAYS); + } + dsb(sy); + + for (p = 0; p < T8112_MCC_NPLANES; p++) { + void __iomem *reg = t8112.mcc_planes + p * T8112_MCC_PLANE_STRIDE + + T8112_MCC_WAYS_STATUS; + + if (readl_poll_timeout_atomic(reg, v, + !FIELD_GET(T8112_MCC_WAYS_DATA, v) && + !FIELD_GET(T8112_MCC_WAYS_TAG, v), + 1, T8112_MCC_TIMEOUT_US)) + t8112.slc_off_bad |= BIT(p); + } + dsb(sy); + t8112.slc_disabled = true; +} + +static void t8112_slc_on(void) +{ + unsigned int p; + u32 v, ways; + + t8112.slc_on_bad = 0; + if (!t8112.mcc_planes || !t8112.slc_disabled) + return; + + t8112.slc_disabled = false; + ways = t8112.slc_ways; + + for (p = 0; p < T8112_MCC_NPLANES; p++) { + void __iomem *base = t8112.mcc_planes + p * T8112_MCC_PLANE_STRIDE; + + writel(ways, base + T8112_MCC_WAYS); + } + dsb(sy); + + for (p = 0; p < T8112_MCC_NPLANES; p++) { + void __iomem *base = t8112.mcc_planes + p * T8112_MCC_PLANE_STRIDE; + + if (readl_poll_timeout_atomic(base + T8112_MCC_WAYS_STATUS, v, + FIELD_GET(T8112_MCC_WAYS_DATA, v) == ways && + FIELD_GET(T8112_MCC_WAYS_TAG, v) == ways, + 1, T8112_MCC_TIMEOUT_US)) + t8112.slc_on_bad |= BIT(p); + else + writel(0, base + T8112_MCC_CACHE_DISABLE); + } + dsb(sy); +} + static void t8112_mcc_clear_bits64(void __iomem *reg) { u64 q = readq(reg); @@ -631,12 +731,9 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) pcore = t8112_is_pcore(); hid4_orig = t8112_read_hid4(pcore); t8112_write_hid4(pcore, hid4_orig & ~T8112_HID4_DC_MASK); - t8122_clean_used_ram(); - t8122_clean_kernel_image(); - t8122_clean_percpu_slc(); - t8122_clean_all_kptables(); - t8122_clean_state_poc(s); t8112_dcache_clean_all_levels(); + dsb(sy); + t8112_slc_off(); t8112_clean_range_slc((unsigned long)t8103_pac_saved, (unsigned long)(t8103_pac_saved + ARRAY_SIZE(t8103_pac_saved))); if (s->mbox) @@ -648,6 +745,7 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) (unsigned long)current + sizeof(*current)); t8112_clean_range_slc((unsigned long)task_stack_page(current), (unsigned long)task_stack_page(current) + THREAD_SIZE); + t8112_dcache_clean_all_levels(); dsb(sy); t8112_write_hid4(pcore, hid4_orig); @@ -710,6 +808,8 @@ static void t8112_sleep_pre_commit(struct apple_sleep *s) (unsigned long)(s->mbox + 1)); t8112_clean_range_slc((unsigned long)s, (unsigned long)(s + 1)); t8112_clean_range_slc((unsigned long)&t8112, (unsigned long)(&t8112 + 1)); + t8112_clean_range_slc((unsigned long)task_stack_page(current), + (unsigned long)task_stack_page(current) + THREAD_SIZE); dsb(sy); t8112_write_hid4(pcore, hid4_orig); } @@ -754,6 +854,8 @@ static void t8112_sleep_wake(struct apple_sleep *s) T8103_MUX_TIMEOUT_US); } + t8112_slc_on(); + if (t8112.nco) { for (i = 0; i < T8103_NCO_CHANS; i++) { if (t8112.nco_forced & BIT(i)) { @@ -821,6 +923,89 @@ static void t8112_aic_mask_noop(void) { } +/* + * void t8112_cpu_off(u64 cyc_ovrd, u64 acc_ovrd): CCIDX-aware version of + * t8103_cpu_off(). Must be called with HID4/EHID4 DISABLE_DC_SW_L2 cleared so + * L2 set/way cleans are not dropped as NOPs, and turns SCTLR_EL1.C off before + * cleaning+invalidating L1 and cleaning L2+ with zero stack accesses. + */ +asm( +" .pushsection .text, \"ax\"\n" +" .type t8112_cpu_off, %function\n" +"t8112_cpu_off:\n" +" msr daifset, #0xf\n" +" mrs x3, sctlr_el1\n" +" bic x3, x3, #(1 << 2)\n" +" msr sctlr_el1, x3\n" +" isb\n" +" dsb sy\n" +" mrs x3, clidr_el1\n" +" mrs x4, id_aa64mmfr2_el1\n" +" ubfx x4, x4, #20, #4\n" +" mov x5, #0\n" +"1: cmp x5, #7\n" +" b.hs 5f\n" +" add x6, x5, x5, lsl #1\n" +" lsr x7, x3, x6\n" +" and x7, x7, #7\n" +" cbz x7, 5f\n" +" cmp x7, #2\n" +" b.lo 4f\n" +" cmp x7, #4\n" +" b.hi 4f\n" +" lsl x6, x5, #1\n" +" msr csselr_el1, x6\n" +" isb\n" +" mrs x8, ccsidr_el1\n" +" and x9, x8, #7\n" +" add x9, x9, #4\n" +" cbnz x4, 20f\n" +" ubfx x10, x8, #3, #10\n" +" ubfx x11, x8, #13, #15\n" +" b 21f\n" +"20: ubfx x10, x8, #3, #21\n" +" ubfx x11, x8, #32, #24\n" +"21: clz w12, w10\n" +"2: mov x13, x11\n" +" lsl x14, x10, x12\n" +" orr x14, x14, x5, lsl #1\n" +"3: lsl x15, x13, x9\n" +" orr x15, x14, x15\n" +" cbnz x5, 30f\n" +" dc cisw, x15\n" +" b 31f\n" +"30: dc csw, x15\n" +"31: subs x13, x13, #1\n" +" b.ge 3b\n" +" subs x10, x10, #1\n" +" b.ge 2b\n" +" dsb sy\n" +"4: add x5, x5, #1\n" +" b 1b\n" +"5: msr csselr_el1, xzr\n" +" dsb sy\n" +" isb\n" +" msr cntp_ctl_el0, xzr\n" +" msr cntv_ctl_el0, xzr\n" +" mrs x3, CurrentEL\n" +" cmp x3, #(2 << 2)\n" +" b.ne 6f\n" +" msr s3_5_c14_c2_1, xzr\n" +" msr s3_5_c14_c3_1, xzr\n" +"6: msr s3_5_c15_c6_0, x1\n" +" msr s3_5_c15_c5_0, x0\n" +" isb\n" +" mov x9, #1\n" +"7: msr s3_5_c15_c1_1, x9\n" +" dsb sy\n" +" isb\n" +" wfi\n" +" b 7b\n" +" .size t8112_cpu_off, . - t8112_cpu_off\n" +" .popsection\n" +); +void t8112_cpu_off(u64 cyc_ovrd, u64 acc_ovrd); + static void t8112_deep_wfi_arm(void) { u64 mpidr = read_cpuid_mpidr(); @@ -837,10 +1022,6 @@ static void t8112_deep_wfi_arm(void) dsb(sy); } - t8112_write_hid4(pcore, hid4 & ~T8112_HID4_DC_MASK); - t8112_dcache_clean_all_levels(); - t8112_write_hid4(pcore, hid4); - cyc &= ~(T8103_CYC_WFI_MODE | T8103_CYC_IRQ_MODE | T8103_CYC_FIQ_MODE); cyc |= FIELD_PREP(T8103_CYC_WFI_MODE, 3) | T8103_CYC_DISABLE_WFI_RET; write_sysreg_s(0, T8103_PMCR0); @@ -851,10 +1032,27 @@ static void t8112_deep_wfi_arm(void) FIELD_PREP(T8103_ACC_TRAIN_DOWN_LINK, 3) | FIELD_PREP(T8103_ACC_POWER_DOWN_CPM, 3) | T8103_ACC_DISABLE_PIO_ON_WFI | T8103_ACC_DEEP_SLEEP; - t8103_cpu_off(cyc, acc); + + /* Leave DISABLE_DC_SW_L2 cleared across t8112_cpu_off() so L2 cleans take effect. */ + t8112_write_hid4(pcore, hid4 & ~T8112_HID4_DC_MASK); + t8112_cpu_off(cyc, acc); unreachable(); } +static void t8112_sleep_finish(struct apple_sleep *s) +{ + if (t8112.slc_off_bad) { + dev_warn(s->dev, "SLC write-back timed out on planes %#x\n", + t8112.slc_off_bad); + t8112.slc_off_bad = 0; + } + if (t8112.slc_on_bad) { + dev_warn(s->dev, "SLC restore timed out on planes %#x\n", + t8112.slc_on_bad); + t8112.slc_on_bad = 0; + } +} + static int t8112_sleep_cpu_prepare(u64 mpidr) { return 0; @@ -904,6 +1102,7 @@ static const struct apple_sleep_ops t8112_sleep_ops = { .pre_commit = t8112_sleep_pre_commit, .post_timer = t8112_post_timer, .wake = t8112_sleep_wake, + .finish = t8112_sleep_finish, .cpu_prepare = t8112_sleep_cpu_prepare, .cpu_restore = t8112_sleep_cpu_restore, }; From 8aa6d28ee1376ccf1f7fbef3044e3f068fc2cbeb Mon Sep 17 00:00:00 2001 From: Satya Benson Date: Sun, 29 Nov 2026 00:19:28 +0800 Subject: [PATCH 18/23] iommu/apple-dart: save/restore T8112 display DART state across S2R Replace the minimal T8112 display stream helper with a full T8112-safe path that saves/restores TTBR/TCR, manages display_dark_enter/exit and host_off, clears DART_T8110_ERROR, and invalidates TLBs without touching registers beyond T8112's 0x4000-byte MMIO window. Tested across 11 consecutive deep S2R cycles on J413 (macOS 27.2 stub). Signed-off-by: Satya Benson Signed-off-by: WJW --- drivers/iommu/apple-dart.c | 90 ++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 27 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 700d8cd656ead..159f80c1388e0 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -9039,44 +9039,80 @@ int apple_dart_display_keep(struct device *dev, u32 streams, bool save) } EXPORT_SYMBOL_GPL(apple_dart_display_keep); -static int apple_dart_t8112_display_streams(struct apple_dart *dart, u32 streams, - bool on, bool flush) +static int apple_dart_t8112_display_streams(struct apple_dart *dart, u32 streams, bool on, + bool flush) { + struct apple_dart_stream_map map = { .dart = dart }; unsigned long bits = streams; - unsigned int sid; - u32 status; - int ret; + unsigned int sid, idx; + u32 error; + int ret = 0; - /* T8112 display DARTs map a 0x4000-byte MMIO window; stay within it. */ if (on) { - struct apple_dart_stream_map all = { .dart = dart }; - + if (!READ_ONCE(dart->host_off) && !READ_ONCE(dart->display_dark)) + return 0; + if (dart->display_saved && !apple_dart_state_retained(dart)) { + if (apple_dart_is_locked(dart)) { + dev_err(dart->dev, "translations lost at the power-down, and locked\n"); + return -EIO; + } + ret = apple_dart_hw_reset(dart); + if (ret && ret != -EBUSY) + dev_warn(dart->dev, "reset at power-on: %d\n", ret); + for_each_set_bit(sid, &bits, dart->num_streams) + writel(BIT(sid), dart->regs + DART_T8110_DISABLE_STREAMS); + for (sid = 0; sid < dart->num_streams; sid++) { + for (idx = 0; idx < dart->hw->ttbr_count; idx++) + writel(dart->save_ttbr[sid][idx], + dart->regs + DART_TTBR(dart, sid, idx)); + writel(dart->save_tcr[sid], dart->regs + DART_TCR(dart, sid)); + } + ret = 0; + dev_dbg(dart->dev, "translations put back at power-on\n"); + } + error = readl(dart->regs + DART_T8110_ERROR); + if (error & DART_T8110_ERROR_FLAG) + writel(error, dart->regs + DART_T8110_ERROR); + scoped_guard(spinlock_irqsave, &dart->managed_lock) + WRITE_ONCE(dart->display_tlb_stale, true); + ret = apple_dart_display_dark_exit(dart); + if (ret) + return ret; + if (dart->display_saved) + writel(dart->display_enable & streams, + dart->regs + DART_T8110_ENABLE_STREAMS); + else + writel(streams, dart->regs + DART_T8110_ENABLE_STREAMS); + dart->host_off_slept = false; + dart->display_saved = false; dart->sleep_flushed = false; - WRITE_ONCE(dart->display_tlb_stale, false); - WRITE_ONCE(dart->display_dark, false); - writel(streams, dart->regs + DART_T8110_ENABLE_STREAMS); - bitmap_fill(all.sidmap, dart->num_streams); - dart->hw->invalidate_tlb(&all); + WRITE_ONCE(dart->host_off, false); return 0; } - if (flush && dart->sleep_flushed) - return 0; - - for_each_set_bit(sid, &bits, BITS_PER_TYPE(streams)) - writel(BIT(sid), dart->regs + DART_T8110_DISABLE_STREAMS); - if (!flush) + if (READ_ONCE(dart->host_off)) return 0; - - writel(0xa000, dart->regs + DART_T8110_TLB_CMD); - ret = readl_poll_timeout_atomic(dart->regs + DART_T8110_TLB_CMD, status, - !(status & DART_T8110_TLB_CMD_BUSY), 1, - DART_T8110_FLUSH_BUSY_TIMEOUT); - if (ret) { - dev_err(dart->dev, "flush for a power-down didn't finish: %#x\n", status); + if (!READ_ONCE(dart->display_dark)) { + apple_dart_save_state(dart); + dart->display_enable = readl(dart->regs + DART_T8110_ENABLE_STREAMS); + dart->display_saved = true; + } + ret = apple_dart_display_dark_enter(dart); + if (ret) return ret; + for_each_set_bit(sid, &bits, dart->num_streams) + writel(BIT(sid), dart->regs + DART_T8110_DISABLE_STREAMS); + if (flush) { + for_each_set_bit(sid, &bits, dart->num_streams) + set_bit(sid, map.sidmap); + ret = dart->hw->invalidate_tlb(&map); + if (ret) { + dev_err(dart->dev, "flush for a power-down failed: %d\n", ret); + return ret; + } + dart->sleep_flushed = true; } - dart->sleep_flushed = true; + WRITE_ONCE(dart->host_off, true); return 0; } From 3d938775b458624b7318c2db1bbf38b67ad33444 Mon Sep 17 00:00:00 2001 From: WJW Date: Sun, 29 Nov 2026 00:20:02 +0800 Subject: [PATCH 19/23] soc: apple: sleep: log raw T8112 wake_status and wake_armed words on finish Log raw wake_status[0..6] and wake_armed[0..6] in t8112_sleep_finish() (matching t8103_sleep_finish()) so unnamed wake sources are visible in dmesg when diagnosing early wakes. Signed-off-by: WJW --- drivers/soc/apple/sleep-t8112.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h index bbefe0d737652..86ba7065432bd 100644 --- a/drivers/soc/apple/sleep-t8112.h +++ b/drivers/soc/apple/sleep-t8112.h @@ -1041,6 +1041,13 @@ static void t8112_deep_wfi_arm(void) static void t8112_sleep_finish(struct apple_sleep *s) { + dev_info(s->dev, "T8112: wake status %08x %08x %08x %08x %08x %08x %08x (armed %08x %08x %08x %08x %08x %08x %08x)\n", + s->wake_status[0], s->wake_status[1], s->wake_status[2], + s->wake_status[3], s->wake_status[4], s->wake_status[5], + s->wake_status[6], + s->wake_armed[0], s->wake_armed[1], s->wake_armed[2], + s->wake_armed[3], s->wake_armed[4], s->wake_armed[5], + s->wake_armed[6]); if (t8112.slc_off_bad) { dev_warn(s->dev, "SLC write-back timed out on planes %#x\n", t8112.slc_off_bad); From 7eb3ced3ae3594e473c27e19f4fe7875cfb73a3e Mon Sep 17 00:00:00 2001 From: Satya Benson Date: Sun, 29 Nov 2026 10:35:16 +0800 Subject: [PATCH 20/23] soc: apple: sleep: fix T8112 wake controller, DCS stepping, and GPU S2R path Fix T8112 wake controller layout (8 words, wake_status at +0x28, wake_last_word GENMASK(30, 0)) and replace the mixed wake IDs with the 20 J413 wake IDs (NUB.SPMI0.SW3 = 58). Drop the Gen-4 spmi_notify_sleep write at prepare, step PMU boot stage 0x50 -> 0x51 -> 0x52 -> 0x30 across commit/wake/finish, step DCS perf state cleanly via t8103_dcs_step_to(), add the four apple,pwr-* GPU controller properties to t8112.dtsi, and save/restore the 8 AGX fabric tunables across ps_gfx power-off. Hardware-verified on J413 (27.2 stub) with aurora GPU and sddm/Hyprland live across timed rtcwake cycles (5s/10s/20s) and 25/25 GLES 3.2 FBO renders per wake. Signed-off-by: Satya Benson Signed-off-by: WJW --- arch/arm64/boot/dts/apple/t8112-j413.dts | 2 +- arch/arm64/boot/dts/apple/t8112.dtsi | 4 + drivers/soc/apple/sleep-t8112.h | 192 +++++++++++++++++------ 3 files changed, 152 insertions(+), 46 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8112-j413.dts b/arch/arm64/boot/dts/apple/t8112-j413.dts index f91499dab6f53..e48e42ddf941f 100644 --- a/arch/arm64/boot/dts/apple/t8112-j413.dts +++ b/arch/arm64/boot/dts/apple/t8112-j413.dts @@ -598,6 +598,6 @@ }; &sleep { - apple,wake-enable = <3 12 14 54 76 81 133 134 155 184 208>; + apple,wake-enable = <14 26 27 44 51 53 54 58 69 73 81 86 147 154 155 156 157 229 231 248>; status = "okay"; }; diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index 2f2658c9e6b73..2e266353b16e7 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -606,7 +606,11 @@ apple,ppm-filter-time-constant-ms = <34>; apple,ppm-ki = <205.0>; apple,ppm-kp = <0.75>; + apple,pwr-filter-time-constant = <313>; + apple,pwr-integral-gain = <0.0202129>; + apple,pwr-integral-min-clamp = <0>; apple,pwr-min-duty-cycle = <40>; + apple,pwr-proportional-gain = <5.2831855>; apple,core-leak-coef = <1920.0>; apple,sram-leak-coef = <74.0>; }; diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h index 86ba7065432bd..33e01fec65995 100644 --- a/drivers/soc/apple/sleep-t8112.h +++ b/drivers/soc/apple/sleep-t8112.h @@ -40,8 +40,7 @@ #define T8112_MUX_PARK_VAL 0x80100000 #define T8112_DCS_PERF_OFF 0x5c000 -#define T8112_DCS_BUSY BIT(31) -#define T8112_DCS_TIMEOUT_US 10000 +#define T8112_DCS_SLEEP 3 #define T8112_TVM_IDLE_OFF 0x3e0 #define T8112_TVM_BUSY BIT(1) #define T8112_TVM_TIMEOUT_US 10000 @@ -59,6 +58,10 @@ #define T8112_MCC_WAYS_TAG GENMASK(9, 5) #define T8112_MCC_TIMEOUT_US 100000 +/* AGX fabric tunables programmed by the boot loader; lost when ps_gfx powers off. */ +#define T8112_AGX_FABRIC 0x205000000ULL +static const u32 t8112_agx_regs[] = { 0x0, 0x34, 0x38, 0x400, 0x600, 0x738, 0x798, 0x800 }; + static const u32 t8112_mux_park[] = { 0x40040, 0x40048, 0x40044, 0x40038, 0x40034 }; static const u32 t8112_tvm[] = { 0x400, 0x800, 0xc00, 0x000 }; static const u32 t8112_auto_off[] = { 0x1b0, 0x1a8, 0x1b8 }; @@ -165,6 +168,11 @@ static struct { void __iomem *pmp_asc; void __iomem *pmp_mbox; void __iomem *nco; + void __iomem *agx_fabric; + struct platform_device *gpu; + u32 agx_saved[ARRAY_SIZE(t8112_agx_regs)]; + bool agx_saved_valid; + int gfx_wake_err; void __iomem *ed[2][4]; u32 notify_saved; bool notify_staged; @@ -178,7 +186,19 @@ static struct { u32 tvm_saved[ARRAY_SIZE(t8112_tvm)]; u32 auto_saved[ARRAY_SIZE(t8112_auto_off)]; u32 dcs_saved; + u32 dcs_down_val; + u32 dcs_wake; + u32 dcs_up_val; + bool dcs_down_ok; + bool dcs_up_ok; + u32 wake_entry[8]; + u32 spmi_vec_commit; + u32 spmi_ack_commit; + u32 spmi_notify_commit; + u32 spmi_vec_wake; + u32 spmi_ack_wake; bool commit_saved; + bool committed; } t8112; static void __iomem *t8112_map(struct apple_sleep *s, const char *name, struct resource *out) @@ -278,6 +298,17 @@ static int t8112_sleep_map_regs(struct apple_sleep *s) t8112.pmp_asc = t8103_ioremap(s, T8103_PMP_ASC, 0x100); t8112.pmp_mbox = t8103_ioremap(s, T8103_PMP_MBOX, 0x1000); t8112.nco = t8103_ioremap(s, T8103_NCO, T8103_NCO_CHANS * T8103_NCO_STRIDE); + t8112.agx_fabric = t8103_ioremap(s, T8112_AGX_FABRIC, 0x1000); + { + struct device_node *np = of_find_compatible_node(NULL, NULL, "apple,agx-t8112"); + if (np) { + t8112.gpu = of_find_device_by_node(np); + of_node_put(np); + } + if (t8112.gpu && + devm_add_action_or_reset(s->dev, apple_sleep_put_device, &t8112.gpu->dev)) + return -ENOMEM; + } for (i = 0; i < 2; i++) { unsigned int c; @@ -297,6 +328,16 @@ static int t8112_sleep_map_regs(struct apple_sleep *s) static int t8112_sleep_check(struct apple_sleep *s) { + if (t8112.gpu && device_is_bound(&t8112.gpu->dev)) { + if (!apple_sleep_coproc_ready_node(t8112.gpu->dev.of_node)) { + dev_err(s->dev, "refused: the GPU's driver is bound\n"); + return -EBUSY; + } + if (!t8112.agx_fabric) { + dev_err(s->dev, "refused: GPU fabric registers not mapped\n"); + return -ENODEV; + } + } return 0; } @@ -456,19 +497,10 @@ static __always_inline void t8112_dcache_clean_all_levels(void) static void t8112_sleep_prepare_regs(struct apple_sleep *s) { - apple_sleep_pmu_write(s->spmi, s->soc->pmu_usid, - s->soc->pmu_sleep_reg, s->soc->pmu_sleep_val); - t8112.notify_saved = readl(s->spmi + SPMI_NOTIFY_ENABLE); - t8112.notify_staged = true; - writel(s->soc->spmi_notify_sleep, s->spmi + SPMI_NOTIFY_ENABLE); } static void t8112_sleep_undo_regs(struct apple_sleep *s) { - if (!t8112.notify_staged) - return; - writel(t8112.notify_saved, s->spmi + SPMI_NOTIFY_ENABLE); - t8112.notify_staged = false; } static void t8112_aon_lower(struct apple_sleep *s, u32 off) @@ -620,15 +652,6 @@ static void t8112_mcc_channel_stop(void) t8112_mcc_clear_bits32(t8112.mcc[4] + 0x588); } -static void t8112_dcs_write(u32 val) -{ - u32 cur; - - writel(val, t8112.clk_mux + T8112_DCS_PERF_OFF); - readl_poll_timeout_atomic(t8112.clk_mux + T8112_DCS_PERF_OFF, cur, - !(cur & T8112_DCS_BUSY), 1, T8112_DCS_TIMEOUT_US); -} - static void t8112_sleep_commit_regs(struct apple_sleep *s) { bool pcore; @@ -636,7 +659,7 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) unsigned int i; u32 val; - apple_sleep_set_wd2(s, WDT_SUSPEND_SECS); + apple_sleep_set_wd2(s, T8103_WDT_COMMIT_SECS); sleep_ps_save(s); @@ -649,13 +672,28 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) T8103_SEP_GATE_US); } - /* Lower GFX while PMP is still running, then stop PMP. */ + /* Check committed GPU stop, save AGX fabric tunables, and lower GFX before PMP stop. */ t8112.commit_lowered = 0; + t8112.agx_saved_valid = false; + t8112.gfx_wake_err = 0; + t8112.committed = true; + if (t8112.gpu && device_is_bound(&t8112.gpu->dev)) { + struct apple_sleep_coproc *gc = apple_sleep_coproc_find(&t8112.gpu->dev); + + if (gc && gc->stop_ret) + panic("T8112 committed GPU stop failed: %d", gc->stop_ret); + } if (sleep_ps_on(s, t8112_commit_off[0])) { + if (t8112.agx_fabric) { + for (i = 0; i < ARRAY_SIZE(t8112_agx_regs); i++) + t8112.agx_saved[i] = readl(t8112.agx_fabric + t8112_agx_regs[i]); + t8112.agx_saved_valid = true; + } t8112.commit_saved_ps[0] = readl(s->ps + t8112_commit_off[0]); t8112.commit_lowered |= BIT(0); sleep_ps_lower(s, t8112_commit_off[0]); - sleep_ps_wait_off(s, t8112_commit_off[0]); + if (sleep_ps_wait_off(s, t8112_commit_off[0])) + panic("T8112 committed GFX power-off timed out"); } t8103_asc_stop(t8112.pmp_asc, t8112.pmp_mbox); @@ -761,8 +799,8 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) T8112_TVM_TIMEOUT_US); } - t8112_dcs_write(0x335); - t8112_dcs_write(0x553); + t8112.dcs_down_ok = t8103_dcs_step_to(t8112.clk_mux + T8112_DCS_PERF_OFF, + T8112_DCS_SLEEP, &t8112.dcs_down_val); writel(PWRGATE_ON, s->pwrgate + T8112_PWRGATE_E); writel(PWRGATE_ON, s->pwrgate + T8112_PWRGATE_P); @@ -777,9 +815,19 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) writel(val & ~PS_AUTO_ENABLE, s->ps + t8112_auto_off[i]); } - /* Ack and enable PMU RTC alarm SPMI vector so rtcwake reaches wake source 54. */ + /* Ack and enable PMU RTC alarm SPMI vector so rtcwake reaches wake source 58. */ writel(T8103_SPMI_VEC_RTC, s->spmi + T8103_SPMI_VEC_ACK); writel(t8112.spmi_vec_saved | T8103_SPMI_VEC_RTC, s->spmi + T8103_SPMI_VEC_ENABLE); + apple_sleep_pmu_write(s->spmi, s->soc->pmu_usid, + s->soc->pmu_sleep_reg, s->soc->pmu_sleep_val); + + t8112.spmi_vec_commit = readl(s->spmi + T8103_SPMI_VEC_ENABLE); + t8112.spmi_ack_commit = readl(s->spmi + T8103_SPMI_VEC_ACK); + t8112.spmi_notify_commit = readl(s->spmi + SPMI_NOTIFY_ENABLE); + + /* Snapshot wake status before committing WFI (read-only). */ + for (i = 0; i < s->soc->wake_words; i++) + t8112.wake_entry[i] = readl(s->wake + s->soc->wake_status + i * 4); aic_sleep_ack(); dsb(sy); @@ -817,7 +865,9 @@ static void t8112_sleep_pre_commit(struct apple_sleep *s) static void t8112_sleep_wake(struct apple_sleep *s) { u32 val; - int i; + int i, pmp_ret = 0; + + apple_sleep_pmu_write(s->spmi, s->soc->pmu_usid, s->soc->pmu_sleep_reg, 0x51); writel(CLUSTER_ON, s->cluster + T8112_CLUSTER_E); s->cluster_e_ret = readl_poll_timeout_atomic(s->cluster + T8112_CLUSTER_E, val, @@ -855,6 +905,10 @@ static void t8112_sleep_wake(struct apple_sleep *s) } t8112_slc_on(); + t8112.dcs_wake = readl(t8112.clk_mux + T8112_DCS_PERF_OFF); + t8112.dcs_up_ok = t8103_dcs_step_to(t8112.clk_mux + T8112_DCS_PERF_OFF, + t8112.dcs_saved & 0xf, + &t8112.dcs_up_val); if (t8112.nco) { for (i = 0; i < T8103_NCO_CHANS; i++) { @@ -867,6 +921,8 @@ static void t8112_sleep_wake(struct apple_sleep *s) t8112.nco_forced = 0; } + t8112.spmi_vec_wake = readl(s->spmi + T8103_SPMI_VEC_ENABLE); + t8112.spmi_ack_wake = readl(s->spmi + T8103_SPMI_VEC_ACK); writel(t8112.spmi_vec_saved, s->spmi + T8103_SPMI_VEC_ENABLE); if (apple_sleep_enclave.stop) { @@ -888,7 +944,30 @@ static void t8112_sleep_wake(struct apple_sleep *s) off == T8112_PS_DISPEXT_FE || off == T8112_PS_DISPEXT_SYS || off == T8112_PS_ISP_SYS) continue; - sleep_ps_restore(s->ps + off, t8112.commit_saved_ps[i]); + if (off == T8112_PS_PMP) { + pmp_ret = sleep_ps_restore(s->ps + off, t8112.commit_saved_ps[i]); + } else if (off == T8112_PS_GFX) { + int gfx_ret = pmp_ret ? pmp_ret : + sleep_ps_restore(s->ps + off, t8112.commit_saved_ps[i]); + + if (!gfx_ret && t8112.agx_saved_valid && t8112.agx_fabric) { + unsigned int j; + + for (j = 0; j < ARRAY_SIZE(t8112_agx_regs); j++) + writel(t8112.agx_saved[j], + t8112.agx_fabric + t8112_agx_regs[j]); + } + t8112.gfx_wake_err = gfx_ret; + if (gfx_ret && t8112.gpu) { + struct apple_sleep_coproc *gc = + apple_sleep_coproc_find(&t8112.gpu->dev); + + if (gc) + gc->wake_err = gfx_ret; + } + } else { + sleep_ps_restore(s->ps + off, t8112.commit_saved_ps[i]); + } } t8112.commit_lowered = 0; @@ -916,6 +995,7 @@ static void t8112_sleep_wake(struct apple_sleep *s) writel(PWRGATE_ON, s->pwrgate + T8112_PWRGATE_E); writel(PWRGATE_ON, s->pwrgate + T8112_PWRGATE_P); + apple_sleep_pmu_write(s->spmi, s->soc->pmu_usid, s->soc->pmu_sleep_reg, 0x52); apple_sleep_set_wd2(s, T8103_WDT_RESUME_SECS); } @@ -1041,13 +1121,26 @@ static void t8112_deep_wfi_arm(void) static void t8112_sleep_finish(struct apple_sleep *s) { - dev_info(s->dev, "T8112: wake status %08x %08x %08x %08x %08x %08x %08x (armed %08x %08x %08x %08x %08x %08x %08x)\n", + if (!t8112.committed) + return; + t8112.committed = false; + apple_sleep_pmu_write(s->spmi, s->soc->pmu_usid, s->soc->pmu_sleep_reg, 0x30); + dev_info(s->dev, "T8112: wake status %08x %08x %08x %08x %08x %08x %08x %08x (armed %08x %08x %08x %08x %08x %08x %08x %08x, entry %08x %08x %08x %08x %08x %08x %08x %08x)\n", s->wake_status[0], s->wake_status[1], s->wake_status[2], s->wake_status[3], s->wake_status[4], s->wake_status[5], - s->wake_status[6], + s->wake_status[6], s->wake_status[7], s->wake_armed[0], s->wake_armed[1], s->wake_armed[2], s->wake_armed[3], s->wake_armed[4], s->wake_armed[5], - s->wake_armed[6]); + s->wake_armed[6], s->wake_armed[7], + t8112.wake_entry[0], t8112.wake_entry[1], t8112.wake_entry[2], + t8112.wake_entry[3], t8112.wake_entry[4], t8112.wake_entry[5], + t8112.wake_entry[6], t8112.wake_entry[7]); + dev_info(s->dev, "T8112: spmi vec=%#x->%#x wake=%#x ack=%#x->%#x dcs=%#x->%#x(%s)->%#x->%#x(%s) agx=%u gfx_err=%d\n", + t8112.spmi_vec_saved, t8112.spmi_vec_commit, t8112.spmi_vec_wake, + t8112.spmi_ack_commit, t8112.spmi_ack_wake, + t8112.dcs_saved, t8112.dcs_down_val, t8112.dcs_down_ok ? "ok" : "stuck", + t8112.dcs_wake, t8112.dcs_up_val, t8112.dcs_up_ok ? "ok" : "stuck", + t8112.agx_saved_valid, t8112.gfx_wake_err); if (t8112.slc_off_bad) { dev_warn(s->dev, "SLC write-back timed out on planes %#x\n", t8112.slc_off_bad); @@ -1079,20 +1172,29 @@ static const struct apple_sleep_gate_coproc t8112_gate_coprocs[] = { }; static const struct apple_sleep_wake_name t8112_wake_names[] = { - { 3, "AOP.CPUWakeupAP" }, - { 12, "AOP.GPIO.IRQ4" }, { 14, "AOP.GPIO.IRQ6" }, - { 54, "NUB.SPMI0Sw3IRQ" }, - { 76, "SMC.CPUWakeupAP" }, - { 81, "SMC.OutboxNotEmpty" }, - { 133, "ATC0.USBWakeup" }, - { 134, "ATC1.USBWakeup" }, - { 155, "NUB.SPMI0.SW3" }, - { 184, "SMC.CPUWakeupAP.M3" }, - { 208, "SMC.OutboxNotEmpty.M3" }, + { 26, "AOP.OutboxNotEmpty" }, + { 27, "AOP.CPUWakeupAP" }, + { 44, "NUB.WakeupAP" }, + { 51, "NUB.GPIO.IRQ6" }, + { 53, "NUB.APWatchdog" }, + { 54, "NUB.APWakeupTime" }, + { 58, "NUB.SPMI0.SW3" }, + { 69, "AOP.SPMI0.SW3" }, + { 73, "AOP.SPMI1.SW3" }, + { 81, "SMC.CPUWakeupAP" }, + { 86, "SMC.OutboxNotEmpty" }, + { 147, "NUB.SPMI1.SW3" }, + { 154, "ATC0.CIOWakeup" }, + { 155, "ATC1.CIOWakeup" }, + { 156, "ATC0.USBWakeup" }, + { 157, "ATC1.USBWakeup" }, + { 229, "MTP.GPIO.IRQ4" }, + { 231, "MTP.GPIO.IRQ6" }, + { 248, "MTP.DOCK.CHANNELS.AP0.IRQ" }, }; -static const u32 t8112_wake_required[] = { 54 }; +static const u32 t8112_wake_required[] = { 58 }; static const struct apple_sleep_ops t8112_sleep_ops = { .deep_wfi_arm = t8112_deep_wfi_arm, @@ -1140,9 +1242,9 @@ static const struct apple_sleep_soc t8112_sleep_soc = { .pmu_sleep_val = 0x50, .spmi_notify_sleep = 0x2000001, .wake_mask = 0x08, - .wake_status = 0x24, - .wake_words = 7, - .wake_last_word = GENMASK(16, 0), + .wake_status = 0x28, + .wake_words = 8, + .wake_last_word = GENMASK(30, 0), .wake_names = t8112_wake_names, .nwake_names = ARRAY_SIZE(t8112_wake_names), .wake_required = t8112_wake_required, From e5c3ab72dce17c1dbfca40d5ace1c6cb0349b8cd Mon Sep 17 00:00:00 2001 From: WJW Date: Sun, 29 Nov 2026 12:44:25 +0800 Subject: [PATCH 21/23] soc: apple: sleep: only panic on GFX power-off timeout when GPU driver is bound When the GPU driver is not bound (e.g. module_blacklist=aurora on 13.5 stubs), no driver has quiesced GPU firmware before commit, so a ps_gfx power-off timeout should not panic the kernel. Signed-off-by: WJW --- drivers/soc/apple/sleep-t8112.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/soc/apple/sleep-t8112.h b/drivers/soc/apple/sleep-t8112.h index 33e01fec65995..24ef5ab871b39 100644 --- a/drivers/soc/apple/sleep-t8112.h +++ b/drivers/soc/apple/sleep-t8112.h @@ -677,7 +677,9 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) t8112.agx_saved_valid = false; t8112.gfx_wake_err = 0; t8112.committed = true; - if (t8112.gpu && device_is_bound(&t8112.gpu->dev)) { + bool gpu_bound = t8112.gpu && device_is_bound(&t8112.gpu->dev); + + if (gpu_bound) { struct apple_sleep_coproc *gc = apple_sleep_coproc_find(&t8112.gpu->dev); if (gc && gc->stop_ret) @@ -692,7 +694,7 @@ static void t8112_sleep_commit_regs(struct apple_sleep *s) t8112.commit_saved_ps[0] = readl(s->ps + t8112_commit_off[0]); t8112.commit_lowered |= BIT(0); sleep_ps_lower(s, t8112_commit_off[0]); - if (sleep_ps_wait_off(s, t8112_commit_off[0])) + if (sleep_ps_wait_off(s, t8112_commit_off[0]) && gpu_bound) panic("T8112 committed GFX power-off timed out"); } t8103_asc_stop(t8112.pmp_asc, t8112.pmp_mbox); From dfcee6d73b8469027166ea4c30eba0bd73c13e76 Mon Sep 17 00:00:00 2001 From: Satya Benson Date: Sun, 29 Nov 2026 17:00:46 -0500 Subject: [PATCH 22/23] dt-bindings: describe the T8112 display power node and GPU power-controller properties The T8112 S2R series adds a display-power node that falls back to the T8103 one, and the four GPU power-controller properties the loader copies from the ADT. Describe both, so the T8112 devicetrees check cleanly. Signed-off-by: Satya Benson --- .../display/apple,t8140-display-power.yaml | 6 +++++- .../devicetree/bindings/gpu/apple,agx.yaml | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml index c5ec6e05e1631..0cd143f781dce 100644 --- a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml @@ -28,6 +28,9 @@ properties: - items: - const: apple,t6040-display-power - const: apple,t6041-display-power + - items: + - const: apple,t8112-display-power + - const: apple,t8103-display-power reg: minItems: 1 @@ -116,7 +119,8 @@ allOf: - if: properties: compatible: - const: apple,t8103-display-power + contains: + const: apple,t8103-display-power then: # T8103's display has no retention words and its PMC no count of the coprocessors. properties: diff --git a/Documentation/devicetree/bindings/gpu/apple,agx.yaml b/Documentation/devicetree/bindings/gpu/apple,agx.yaml index efa0ee56dda01..fb9657fe07f4e 100644 --- a/Documentation/devicetree/bindings/gpu/apple,agx.yaml +++ b/Documentation/devicetree/bindings/gpu/apple,agx.yaml @@ -228,6 +228,22 @@ properties: Relative frequency of the populated A ladder above the base state, in percent, followed by zeros for the five unused selectors. + apple,pwr-filter-time-constant: + $ref: /schemas/types.yaml#/definitions/uint32 + description: Time constant of the GPU power controller's input filter, from the ADT + + apple,pwr-integral-gain: + $ref: /schemas/types.yaml#/definitions/uint32 + description: Integral gain of the GPU power controller, an IEEE 754 single from the ADT + + apple,pwr-integral-min-clamp: + $ref: /schemas/types.yaml#/definitions/uint32 + description: Lower clamp of the GPU power controller's integral term, from the ADT + + apple,pwr-proportional-gain: + $ref: /schemas/types.yaml#/definitions/uint32 + description: Proportional gain of the GPU power controller, an IEEE 754 single from the ADT + apple,core-leak-coef: $ref: /schemas/types.yaml#/definitions/uint32-array description: From c5a423774421cef1e38dc7bfed1fa6a4a3181cc1 Mon Sep 17 00:00:00 2001 From: Satya Benson Date: Sun, 29 Nov 2026 17:09:03 -0500 Subject: [PATCH 23/23] arm64: dts: apple: t8112: enable system sleep on every T8112 board Nothing in the sleep node is J413's: its blocks, pins, display coprocessor and wake controller are the SoC's. Enable it in t8112.dtsi with the wake sources every T8112 board has (the AOP, NUB with the PMU RTC alarm, the SMC and both ATC ports). J413 adds its MTP's sources. Signed-off-by: Satya Benson --- arch/arm64/boot/dts/apple/t8112-j413.dts | 2 +- arch/arm64/boot/dts/apple/t8112.dtsi | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8112-j413.dts b/arch/arm64/boot/dts/apple/t8112-j413.dts index e48e42ddf941f..2088e124c1ffb 100644 --- a/arch/arm64/boot/dts/apple/t8112-j413.dts +++ b/arch/arm64/boot/dts/apple/t8112-j413.dts @@ -597,7 +597,7 @@ apple,sleep-ssps; }; +/* The SoC's wake sources plus the MTP's (keyboard and trackpad). */ &sleep { apple,wake-enable = <14 26 27 44 51 53 54 58 69 73 81 86 147 154 155 156 157 229 231 248>; - status = "okay"; }; diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index 2e266353b16e7..08c346ada3b17 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -1348,7 +1348,13 @@ "mcc-d", "mcc-e"; apple,display-coprocessors = <&dcp>; apple,pinctrl = <&pinctrl_ap>; - status = "disabled"; + /* + * The SoC's wake controller sources every T8112 board has: the AOP, NUB + * (PMU RTC alarm 58), SMC and both ATC ports. Boards with an MTP add its + * sources (229, 231, 248). + */ + apple,wake-enable = <14 26 27 44 51 53 54 58 69 73 81 86 147 + 154 155 156 157>; }; cio_reset: reset-controller@23b790000 {