From 2d3208136992c37f77223f41519cc89c57287e9b Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 1 Dec 2026 22:29:30 +0700 Subject: [PATCH 1/3] dt-bindings: apple: clpc: name the SMC's Low Power Mode notice apple,low-power-smc-notice: the low-power platform profile tells the SMC (apple,smc) that Low Power Mode is on, in the record that already carries High Power mode. In both bindings that carry a CLPC node. Signed-off-by: Nick --- Documentation/devicetree/bindings/power/apple,pmc.yaml | 6 ++++++ Documentation/devicetree/bindings/soc/apple/apple,clpc.yaml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/Documentation/devicetree/bindings/power/apple,pmc.yaml b/Documentation/devicetree/bindings/power/apple,pmc.yaml index 2dda852386bbb..3ab27517a53a0 100644 --- a/Documentation/devicetree/bindings/power/apple,pmc.yaml +++ b/Documentation/devicetree/bindings/power/apple,pmc.yaml @@ -294,6 +294,12 @@ patternProperties: platform profile holds the CPU clusters to it, up to the next frequency of their tables. + apple,low-power-smc-notice: + type: boolean + description: + The low-power platform profile tells the SMC (apple,smc) that Low + Power Mode is on, in the record that carries High Power mode. + apple,gpu-busy-memory-states: $ref: /schemas/types.yaml#/definitions/uint32-matrix description: diff --git a/Documentation/devicetree/bindings/soc/apple/apple,clpc.yaml b/Documentation/devicetree/bindings/soc/apple/apple,clpc.yaml index daa58ff8ca0c6..0ca2296a32d5b 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,clpc.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,clpc.yaml @@ -55,6 +55,12 @@ properties: Optional package power target in milliwatts (measured from SMC PHPC) for the low-power platform profile. + apple,low-power-smc-notice: + type: boolean + description: + The low-power platform profile tells the SMC (apple,smc) that Low Power + Mode is on, in the record that carries High Power mode. + required: - compatible From cf8263616ce18f2b374805eaad4a85733d6659e3 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 1 Dec 2026 22:29:34 +0700 Subject: [PATCH 2/3] soc: apple: clpc: tell the SMC when the low-power profile is on macOS writes the SMC's 120-byte zETM record at every power mode change. Besides the High Power float at byte 112, which the performance profile already sends, the record has a Low Power Mode float at byte 76: 1.0 while Low Power Mode is on, 0.0 otherwise. Traced on J815 (macOS 27.2.1) across four toggles and across deep sleep + wake: byte 76 is written on each mode toggle while every other slot stays 0, and the SMC retains the record across suspend without a rewrite on wake. Build one record from the profile with both floats and a single counter, so each write states the whole mode, and send it where the DT asks for the notice (apple,low-power-smc-notice). The notice is advisory: if the write fails, the low-power ceilings still apply and nothing is left to withdraw. High Power mode keeps failing the profile change without its write. Removal sends an all-off record when either flag was taken. The host test covers the combined record, a direct low-power to performance switch, the failed notice, and the missing opt-in; it still runs the pre-fix source as its negative control. Signed-off-by: Nick --- drivers/soc/apple/clpc.c | 68 +++++++++++++------- tools/asahi/clpc-high-power-cleanup-tests.py | 53 +++++++++++++-- 2 files changed, 90 insertions(+), 31 deletions(-) diff --git a/drivers/soc/apple/clpc.c b/drivers/soc/apple/clpc.c index fa47907b8123d..1f8556bba1d65 100644 --- a/drivers/soc/apple/clpc.c +++ b/drivers/soc/apple/clpc.c @@ -299,8 +299,12 @@ struct apple_clpc { struct apple_smc *smc; /* The performance profile is sent to the SMC as High Power mode */ bool high_power; - u8 high_power_seq; + /* apple,low-power-smc-notice: the low-power profile is sent to the SMC too */ + bool low_power_notice; + /* zETM records written, and what the last one that the SMC took said */ + u8 zetm_seq; bool high_power_sent; + bool low_power_sent; unsigned long power_next; unsigned long power_reads, power_updates; int power_mw; @@ -1535,9 +1539,10 @@ static int apple_clpc_status_show(struct seq_file *s, void *unused) clpc->clusters[i].max_khz); seq_puts(s, "\n"); } - if (clpc->high_power) - seq_printf(s, "smc high power: %s (%u records sent)\n", - clpc->high_power_sent ? "on" : "off", clpc->high_power_seq); + if (clpc->high_power || clpc->low_power_notice) + seq_printf(s, "smc power mode: high power %s, low power %s (%u records sent)\n", + clpc->high_power_sent ? "on" : "off", + clpc->low_power_sent ? "on" : "off", clpc->zetm_seq); if (clpc->gpu_pmgr) { seq_printf(s, "gpu: powered %u for %u ms, pmp limited ", clpc->gpu_on, clpc->gpu_on ? jiffies_to_msecs(jiffies - clpc->gpu_on_since) : 0); @@ -1670,7 +1675,7 @@ static void apple_clpc_halt(struct apple_clpc *clpc) clpc->ane_until = jiffies; } -static int apple_clpc_send_high_power(struct apple_clpc *clpc, bool on); +static int apple_clpc_send_mode(struct apple_clpc *clpc, bool low, bool high); static void apple_clpc_stop(void *data) { @@ -1699,8 +1704,9 @@ static void apple_clpc_stop(void *data) apple_clpc_halt(clpc); /* The SMC keeps this mode after the driver's profile state is gone. */ mutex_lock(&clpc->sample_lock); - if (clpc->high_power && clpc->high_power_sent) - apple_clpc_send_high_power(clpc, false); + if ((clpc->high_power && clpc->high_power_sent) || + (clpc->low_power_notice && clpc->low_power_sent)) + apple_clpc_send_mode(clpc, false, false); mutex_unlock(&clpc->sample_lock); if (clpc->policy_nb_added) cpufreq_unregister_notifier(&clpc->policy_nb, CPUFREQ_POLICY_NOTIFIER); @@ -1777,32 +1783,38 @@ static int apple_clpc_cluster_cpu(unsigned int index) /* * macOS tells the SMC its power mode through thermalmonitord's 120-byte zETM * record, written at every mode change: a record type (0x1d), a version (1), a - * count of the writes, zeros, and at byte 112 a float that is 1.0 while High - * Power mode is on and 0.0 otherwise. With it on, the SMC lets the fans run up - * to their maximum under a sustained load; in Automatic they level off well - * below it, whatever the temperature. No other SMC key changes with the mode. + * count of the writes, zeros, and two floats that are 1.0 while their mode is + * on and 0.0 otherwise: at byte 76 Low Power Mode, at byte 112 High Power + * mode. With High Power on, the SMC lets the fans run up to their maximum + * under a sustained load; in Automatic they level off well below it, whatever + * the temperature. Each record states the whole mode, so one write carries + * both. No other SMC key changes with the mode. */ #define APPLE_CLPC_ZETM_SIZE 120 #define APPLE_CLPC_ZETM_TYPE 0x1d #define APPLE_CLPC_ZETM_VERSION 1 +#define APPLE_CLPC_ZETM_LOW_POWER 76 #define APPLE_CLPC_ZETM_HIGH_POWER 112 #define APPLE_CLPC_FLOAT_ONE 0x3f800000 -static int apple_clpc_send_high_power(struct apple_clpc *clpc, bool on) +static int apple_clpc_send_mode(struct apple_clpc *clpc, bool low, bool high) { u8 rec[APPLE_CLPC_ZETM_SIZE] = { APPLE_CLPC_ZETM_TYPE, APPLE_CLPC_ZETM_VERSION }; int ret; if (!IS_ENABLED(CONFIG_MFD_MACSMC) || !apple_clpc_smc(clpc)) return -ENODEV; - rec[2] = ++clpc->high_power_seq; - put_unaligned_le32(on ? APPLE_CLPC_FLOAT_ONE : 0, rec + APPLE_CLPC_ZETM_HIGH_POWER); + rec[2] = ++clpc->zetm_seq; + put_unaligned_le32(low ? APPLE_CLPC_FLOAT_ONE : 0, rec + APPLE_CLPC_ZETM_LOW_POWER); + put_unaligned_le32(high ? APPLE_CLPC_FLOAT_ONE : 0, rec + APPLE_CLPC_ZETM_HIGH_POWER); ret = apple_smc_write(clpc->smc, SMC_KEY(zETM), rec, sizeof(rec)); - if (ret < 0) - dev_warn(clpc->dev, "High Power mode %s not sent to the SMC: %d\n", - on ? "on" : "off", ret); - else - clpc->high_power_sent = on; + if (ret < 0) { + dev_warn(clpc->dev, "power mode (low power %s, High Power %s) not sent to the SMC: %d\n", + low ? "on" : "off", high ? "on" : "off", ret); + } else { + clpc->low_power_sent = low; + clpc->high_power_sent = high; + } return ret < 0 ? ret : 0; } @@ -1825,15 +1837,21 @@ static int apple_clpc_profile_get(struct device *dev, enum platform_profile_opti static int apple_clpc_profile_set(struct device *dev, enum platform_profile_option profile) { struct apple_clpc *clpc = dev_get_drvdata(dev); - bool high_power = profile == PLATFORM_PROFILE_PERFORMANCE; + bool high = clpc->high_power && profile == PLATFORM_PROFILE_PERFORMANCE; + bool low = clpc->low_power_notice && profile == PLATFORM_PROFILE_LOW_POWER; bool need_work; mutex_lock(&clpc->sample_lock); - /* Performance is macOS's High Power mode; the other two are its Automatic. */ - if (clpc->high_power && high_power != clpc->high_power_sent) { - int ret = apple_clpc_send_high_power(clpc, high_power); + /* + * Performance is macOS's High Power mode, low-power its Low Power Mode, + * balanced its Automatic. High Power mode is the SMC's alone, so without + * the write the profile change fails; the Low Power notice is advisory, + * and the profile's ceilings and limit apply without it. + */ + if (high != clpc->high_power_sent || low != clpc->low_power_sent) { + int ret = apple_clpc_send_mode(clpc, low, high); - if (ret) { + if (ret && high != clpc->high_power_sent) { mutex_unlock(&clpc->sample_lock); return ret; } @@ -2047,6 +2065,8 @@ static int apple_clpc_probe(struct platform_device *pdev) } } clpc->high_power = clpc->smc_np && high_power; + clpc->low_power_notice = clpc->smc_np && clpc->low_power_khz && + of_property_read_bool(dev->of_node, "apple,low-power-smc-notice"); } /* High Power mode alone needs the SMC; without it there is no profile. */ has_profile = (clpc->low_power_khz || clpc->high_power) && diff --git a/tools/asahi/clpc-high-power-cleanup-tests.py b/tools/asahi/clpc-high-power-cleanup-tests.py index 841289d9845e5..20a3261764952 100755 --- a/tools/asahi/clpc-high-power-cleanup-tests.py +++ b/tools/asahi/clpc-high-power-cleanup-tests.py @@ -79,7 +79,9 @@ def function(source, name): struct hlist_node cpuhp_node; atomic_t idle_armed; bool has_pmc, stopped, high_power, high_power_sent, policy_nb_added, low_power, cpuhp_added; - u8 high_power_seq; + bool low_power_notice, low_power_sent; + /* the record counter: high_power_seq before the Low Power notice, zetm_seq after */ + u8 high_power_seq, zetm_seq; enum platform_profile_option profile; unsigned long power_next, ane_until; unsigned low_power_khz, low_power_mw, ane_qos_khz, nr_clusters, agent, mask, saved_floor; @@ -184,13 +186,15 @@ def function(source, name): detached = debug_removed = floor_restored = notifier_removed = node_put = freed = cleanup = false; smc_result = 0; memset(last_record, 0xff, sizeof(last_record)); } -static void record(bool on, unsigned seq) { +static void record2(bool low, bool on, unsigned seq) { for (unsigned i = 0; i < sizeof(last_record); i++) { unsigned expected = i == 0 ? 0x1d : i == 1 ? 1 : i == 2 ? seq : - on && i == 114 ? 0x80 : on && i == 115 ? 0x3f : 0; + on && i == 114 ? 0x80 : on && i == 115 ? 0x3f : + low && i == 78 ? 0x80 : low && i == 79 ? 0x3f : 0; assert(last_record[i] == expected); } } +static void record(bool on, unsigned seq) { record2(false, on, seq); } static void stop(void) { cleanup = true; apple_clpc_stop(&c); assert(freed && notifier_removed && qos_removed == 3); @@ -231,10 +235,37 @@ def function(source, name): smc_result = -EIO; stop(); assert(smc_writes == 2 && c.high_power_sent && warnings == 1); record(false, 2); reset(); c.high_power_sent = true; c.smc = NULL; - stop(); assert(!smc_writes && c.high_power_sent && !c.high_power_seq); + stop(); assert(!smc_writes && c.high_power_sent && !c.SEQ); /* The record sequence is an eight-bit counter, including during cleanup. */ - reset(); c.high_power_sent = true; c.high_power_seq = 255; + reset(); c.high_power_sent = true; c.SEQ = 255; stop(); record(false, 0); assert(!c.high_power_sent); +#ifdef LOW_POWER_NOTICE + /* The Low Power notice: byte 76 in the same record, advisory, and cleared on removal. */ + reset(); c.low_power_notice = true; c.low_power_khz = 2220000; + assert(!apple_clpc_profile_set(&dev, PLATFORM_PROFILE_LOW_POWER)); + assert(c.low_power_sent && !c.high_power_sent && c.low_power); record2(true, false, 1); + /* Low power straight to performance: one record, low off and High Power on. */ + assert(!apple_clpc_profile_set(&dev, PLATFORM_PROFILE_PERFORMANCE)); + assert(!c.low_power_sent && c.high_power_sent && smc_writes == 2); record2(false, true, 2); + assert(!apple_clpc_profile_set(&dev, PLATFORM_PROFILE_LOW_POWER)); record2(true, false, 3); + stop(); assert(smc_writes == 4 && !c.low_power_sent); record(false, 4); + /* A failed notice still applies the profile and leaves nothing to withdraw. */ + reset(); c.low_power_notice = true; c.low_power_khz = 2220000; smc_result = -EIO; + assert(!apple_clpc_profile_set(&dev, PLATFORM_PROFILE_LOW_POWER)); + assert(c.low_power && c.profile == PLATFORM_PROFILE_LOW_POWER && !c.low_power_sent); + assert(warnings == 1 && queued == 1); + stop(); assert(smc_writes == 1); + /* A failed off-notice still leaves low power; the SMC keeps the flag, so removal withdraws it. */ + reset(); c.low_power_notice = true; c.low_power_khz = 2220000; + assert(!apple_clpc_profile_set(&dev, PLATFORM_PROFILE_LOW_POWER)); smc_result = -EIO; + assert(!apple_clpc_profile_set(&dev, PLATFORM_PROFILE_BALANCED)); + assert(!c.low_power && c.profile == PLATFORM_PROFILE_BALANCED && c.low_power_sent && warnings == 1); + smc_result = 0; stop(); assert(smc_writes == 3 && !c.low_power_sent); record(false, 3); + /* Without the DT opt-in, the low-power profile writes nothing. */ + reset(); assert(!apple_clpc_profile_set(&dev, PLATFORM_PROFILE_LOW_POWER)); + assert(!smc_writes && c.low_power); + stop(); assert(!smc_writes); +#endif puts("CLPC High Power: profile state, cleanup ordering, zETM off and SMC failures passed"); return 0; } @@ -253,8 +284,16 @@ def main(): assert source.index('devm_add_action_or_reset(dev, apple_clpc_stop, clpc)') < source.index( 'devm_platform_profile_register(dev,') defines = '\n'.join(re.findall(r'^#define APPLE_CLPC_(?:ZETM_\w+|FLOAT_ONE)\s+[^\n]+', source, re.M)) - body = '\n\n'.join(function(source, n) for n in ( - 'apple_clpc_send_high_power', 'apple_clpc_profile_set', 'apple_clpc_halt', 'apple_clpc_stop')) + # Older sources have one High Power writer; newer ones one writer for the whole mode. + notice = 'static int apple_clpc_send_mode(' in source + if notice: + defines += '\n#define LOW_POWER_NOTICE 1\n#define SEQ zetm_seq' + else: + defines += '\n#define SEQ high_power_seq' + names = [ + 'apple_clpc_send_mode' if notice else 'apple_clpc_send_high_power', + 'apple_clpc_profile_set', 'apple_clpc_halt', 'apple_clpc_stop'] + body = '\n\n'.join(function(source, n) for n in names) with tempfile.TemporaryDirectory(prefix='clpc-high-power-') as tmp: out = args.out or Path(tmp) out.mkdir(parents=True, exist_ok=True) From 90300394b3d35c5ffebcc5bbf4fdc88a1b56ca1b Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 2 Dec 2026 11:00:55 +0700 Subject: [PATCH 3/3] arm64: dts: apple: t8142-j813-j815: send the SMC the Low Power Mode notice Give the M5 MacBook Air CLPC node the SMC phandle and opt into the zETM Low Power Mode notice, matching macOS on J815. Signed-off-by: Nick --- arch/arm64/boot/dts/apple/t8142-j813-j815.dtsi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8142-j813-j815.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-j815.dtsi index 251b00b004b86..9de8025160495 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813-j815.dtsi +++ b/arch/arm64/boot/dts/apple/t8142-j813-j815.dtsi @@ -243,6 +243,9 @@ clpc: performance-controller@1 { compatible = "apple,t8142-clpc"; reg = <1>; + /* Tell the SMC when the low-power platform profile is on. */ + apple,smc = <&smc>; + apple,low-power-smc-notice; /* * T8142 GPU busy-share memory-state ladder (shared by * J813/J815 M5 MacBook Air): DCS 1, 2, 5, 7 and fabric