[RFC PATCH 1/6] cpufreq/amd-pstate: Extract platform profile to EPP conversion into a helper
From: K Prateek Nayak
Date: Tue Jun 30 2026 - 15:01:43 EST
Avoid duplication by extracting the switch case that derives EPP based
on platform profile into the amd_pstate_get_epp_from_platform_profile()
helper.
No functional changes intended.
Signed-off-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
---
drivers/cpufreq/amd-pstate.c | 67 +++++++++++++++++-------------------
1 file changed, 32 insertions(+), 35 deletions(-)
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 20c30d14100f..1893b0054a6a 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1179,6 +1179,24 @@ static int amd_pstate_power_supply_notifier(struct notifier_block *nb,
return NOTIFY_OK;
}
+static int amd_pstate_get_epp_from_platform_profile(struct cpufreq_policy *policy,
+ enum platform_profile_option profile)
+{
+ switch (profile) {
+ case PLATFORM_PROFILE_PERFORMANCE:
+ return AMD_CPPC_EPP_PERFORMANCE;
+ case PLATFORM_PROFILE_BALANCED:
+ return amd_pstate_get_balanced_epp(policy);
+ case PLATFORM_PROFILE_LOW_POWER:
+ return AMD_CPPC_EPP_POWERSAVE;
+ default:
+ break;
+ }
+
+ pr_err("Unknown Platform Profile %d\n", profile);
+ return -EOPNOTSUPP;
+}
+
static int amd_pstate_profile_probe(void *drvdata, unsigned long *choices)
{
set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
@@ -1204,28 +1222,16 @@ static int amd_pstate_profile_set(struct device *dev,
struct amd_cpudata *cpudata = dev_get_drvdata(dev);
struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpudata->cpu);
int ret;
+ u8 epp;
- switch (profile) {
- case PLATFORM_PROFILE_LOW_POWER:
- ret = amd_pstate_set_epp(policy, AMD_CPPC_EPP_POWERSAVE);
- if (ret)
- return ret;
- break;
- case PLATFORM_PROFILE_BALANCED:
- ret = amd_pstate_set_epp(policy,
- amd_pstate_get_balanced_epp(policy));
- if (ret)
- return ret;
- break;
- case PLATFORM_PROFILE_PERFORMANCE:
- ret = amd_pstate_set_epp(policy, AMD_CPPC_EPP_PERFORMANCE);
- if (ret)
- return ret;
- break;
- default:
- pr_err("Unknown Platform Profile %d\n", profile);
- return -EOPNOTSUPP;
- }
+ ret = amd_pstate_get_epp_from_platform_profile(policy, profile);
+ if (ret < 0)
+ return ret;
+
+ epp = (u8)ret;
+ ret = amd_pstate_set_epp(policy, epp);
+ if (ret)
+ return ret;
cpudata->current_profile = profile;
@@ -1259,20 +1265,11 @@ static int amd_pstate_set_dynamic_epp(struct cpufreq_policy *policy)
int ret;
u8 epp;
- switch (cpudata->current_profile) {
- case PLATFORM_PROFILE_PERFORMANCE:
- epp = AMD_CPPC_EPP_PERFORMANCE;
- break;
- case PLATFORM_PROFILE_LOW_POWER:
- epp = AMD_CPPC_EPP_POWERSAVE;
- break;
- case PLATFORM_PROFILE_BALANCED:
- epp = amd_pstate_get_balanced_epp(policy);
- break;
- default:
- pr_err("Unknown Platform Profile %d\n", cpudata->current_profile);
- return -EOPNOTSUPP;
- }
+ ret = amd_pstate_get_epp_from_platform_profile(policy, cpudata->current_profile);
+ if (ret < 0)
+ return ret;
+
+ epp = (u8)ret;
ret = amd_pstate_set_epp(policy, epp);
if (ret)
return ret;
--
2.34.1