Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions drivers/soc/apple/clpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,11 @@ static unsigned int apple_clpc_step_khz(struct cpufreq_policy *policy,
return best;
}

/* The SMC of the apple,smc phandle, once its driver is bound; NULL before. */
/*
* The SMC of the apple,smc phandle, once its driver is bound; NULL before.
* Callers test IS_ENABLED(CONFIG_MFD_MACSMC) first, so a kernel without the
* SMC driver links without the apple_smc_*() calls.
*/
static struct apple_smc *apple_clpc_smc(struct apple_clpc *clpc)
{
struct platform_device *pdev;
Expand All @@ -819,7 +823,7 @@ static int apple_clpc_read_power(struct apple_clpc *clpc)
u64 mw;
u32 f;

if (!apple_clpc_smc(clpc))
if (!IS_ENABLED(CONFIG_MFD_MACSMC) || !apple_clpc_smc(clpc))
return -ENODEV;
ret = apple_smc_read_u32(clpc->smc, SMC_KEY(PHPC), &f);
if (ret)
Expand Down Expand Up @@ -1304,7 +1308,7 @@ static int apple_clpc_send_high_power(struct apple_clpc *clpc, bool on)
u8 rec[APPLE_CLPC_ZETM_SIZE] = { APPLE_CLPC_ZETM_TYPE, APPLE_CLPC_ZETM_VERSION };
int ret;

if (!apple_clpc_smc(clpc))
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);
Expand Down Expand Up @@ -1533,8 +1537,13 @@ static int apple_clpc_probe(struct platform_device *pdev)
if (!high_power && clpc->hw->high_power_machine)
high_power = of_machine_is_compatible(clpc->hw->high_power_machine);
if ((clpc->low_power_khz || high_power) && IS_REACHABLE(CONFIG_ACPI_PLATFORM_PROFILE)) {
/* The SMC is optional: without it the low-power profile has only its ceiling. */
clpc->smc_np = of_parse_phandle(dev->of_node, "apple,smc", 0);
/*
* The SMC is optional: without it (no apple,smc phandle, or a
* kernel without the SMC driver) the low-power profile has only
* its ceiling and there is no High Power mode.
*/
if (IS_ENABLED(CONFIG_MFD_MACSMC))
clpc->smc_np = of_parse_phandle(dev->of_node, "apple,smc", 0);
clpc->high_power = clpc->smc_np && high_power;
}
/* High Power mode alone needs the SMC; without it there is no profile. */
Expand Down
3 changes: 3 additions & 0 deletions tools/asahi/clpc-high-power-cleanup-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def function(source, name):
#define READ_ONCE(x) (x)
#define WRITE_ONCE(x, v) ((x) = (v))
#define SMC_KEY(x) 0x7a45544d
/* Model a kernel built with the SMC driver, so the SMC path runs. */
#define CONFIG_MFD_MACSMC 1
#define IS_ENABLED(option) (option)
#define dev_warn(...) (warnings++)
enum platform_profile_option { PLATFORM_PROFILE_BALANCED, PLATFORM_PROFILE_LOW_POWER,
PLATFORM_PROFILE_PERFORMANCE };
Expand Down
Loading