Apple A7-A11, T2 SoC cpufreq support
v2 cover Apple A7-A11, T2 SoC cpufreq support
This series add driver support for cpufreq Apple A7-A11, T2 SoCs. Device Tree nodes will be included in another series.
Changes since v1:
- transition_latency is in ns, APPLE_DVFS_TRANSITION_TIMEOUT in us. Multiply APPLE_DVFS_TRANSITION_TIMEOUT by 1000 before setting it as transition_latency.
v1: https://lore.kernel.org/asahi/[email protected]/T
Nick Chan
---
Hector Martin (1):
cpufreq: apple-soc: Drop setting the PS2 field on M2+
Nick Chan (6):
dt-bindings: cpufreq: apple,cluster-cpufreq: Add A7-A11, T2
compatibles
cpufreq: apple-soc: Allow per-SoC configuration of APPLE_DVFS_CMD_PS1
cpufreq: apple-soc: Use 32-bit read for status register
cpufreq: apple-soc: Increase cluster switch timeout to 400us
cpufreq: apple-soc: Set fallback transition latency to
APPLE_DVFS_TRANSITION_TIMEOUT
cpufreq: apple-soc: Add Apple A7-A8X SoC cpufreq support
.../cpufreq/apple,cluster-cpufreq.yaml | 10 +++- drivers/cpufreq/apple-soc-cpufreq.c | 56 +++++++++++++++---- 2 files changed, 54 insertions(+), 12 deletions(-)
base-commit: fac04efc5c793dccbd07e2d59af9f90b7fc0dca4
Signature · 1 line
2.47.1
PATCH v2 1/7 dt-bindings: cpufreq: apple,cluster-cpufreq: Add A7-A11, T2 compatibles
Add compatibles for Apple A7-A11, T2 SoCs.
Apple A7, A8, A8X gets the per-SoC compatible and the A7 "apple,s5l8960x-cluster-cpufreq" compatible.
Apple A9, A9X, A10, A10X, T2, A11 gets the per-SoC compatible, M1 "apple,t8103-cluster-cpufreq" compatible, then the "apple,cluster-cpufreq" fallback compatible.
--- .../bindings/cpufreq/apple,cluster-cpufreq.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/cpufreq/apple,cluster-cpufreq.yaml +9 -1
@@ -24,9 +24,17 @@ properties: - apple,t8112-cluster-cpufreq - const: apple,cluster-cpufreq - items: - - const: apple,t6000-cluster-cpufreq + - enum: + - apple,s8000-cluster-cpufreq + - apple,t8010-cluster-cpufreq + - apple,t8015-cluster-cpufreq + - apple,t6000-cluster-cpufreq - const: apple,t8103-cluster-cpufreq - const: apple,cluster-cpufreq + - items: + - const: apple,t7000-cluster-cpufreq + - const: apple,s5l8960x-cluster-cpufreq + - const: apple,s5l8960x-cluster-cpufreq reg: maxItems: 1
Signature · 1 line
2.47.1
Re: [PATCH v2 1/7] dt-bindings: cpufreq: apple,cluster-cpufreq: Add A7-A11, T2 compatibles
Quoted 10 lines · Nick Chan
Add compatibles for Apple A7-A11, T2 SoCs.
Apple A7, A8, A8X gets the per-SoC compatible and the A7 "apple,s5l8960x-cluster-cpufreq" compatible.
Apple A9, A9X, A10, A10X, T2, A11 gets the per-SoC compatible, M1 "apple,t8103-cluster-cpufreq" compatible, then the "apple,cluster-cpufreq" fallback compatible.
Signed-off-by Nick Chan <[email protected]>
Best regards,
Krzysztof
PATCH v2 2/7 cpufreq: apple-soc: Drop setting the PS2 field on M2+
In reply to Nick ChanFrom: Hector Martin <[email protected]>
Newer device do not use this. It is not known what this field does, but change the behavior to be same as macOS to be safe.
--- drivers/cpufreq/apple-soc-cpufreq.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/cpufreq/apple-soc-cpufreq.c +10 -3
@@ -25,7 +25,7 @@#define APPLE_DVFS_CMD 0x20#define APPLE_DVFS_CMD_BUSY BIT(31)#define APPLE_DVFS_CMD_SET BIT(25) -#define APPLE_DVFS_CMD_PS2 GENMASK(16, 12) +#define APPLE_DVFS_CMD_PS2 GENMASK(15, 12)#define APPLE_DVFS_CMD_PS1 GENMASK(4, 0)/* Same timebase as CPU counter (24MHz) */
@@ -55,6 +55,7 @@#define APPLE_DVFS_TRANSITION_TIMEOUT 100struct apple_soc_cpufreq_info { +bool has_ps2;u64 max_pstate;u64 cur_pstate_mask;u64 cur_pstate_shift;
@@ -69,18 +70,21 @@ struct apple_cpu_priv {static struct cpufreq_driver apple_soc_cpufreq_driver;static const struct apple_soc_cpufreq_info soc_t8103_info = { + .has_ps2 = true, .max_pstate =15 , .cur_pstate_mask =APPLE_DVFS_STATUS_CUR_PS_T8103 , .cur_pstate_shift =APPLE_DVFS_STATUS_CUR_PS_SHIFT_T8103 , };static const struct apple_soc_cpufreq_info soc_t8112_info = { + .has_ps2 = false, .max_pstate =31 , .cur_pstate_mask =APPLE_DVFS_STATUS_CUR_PS_T8112 , .cur_pstate_shift =APPLE_DVFS_STATUS_CUR_PS_SHIFT_T8112 , };static const struct apple_soc_cpufreq_info soc_default_info = { + .has_ps2 = false, .max_pstate =15 , .cur_pstate_mask =0 ,/* fallback */ };
@@ -148,9 +152,12 @@ static int apple_soc_cpufreq_set_target(struct cpufreq_policy *policy,return -EIO ; } - reg &= ~(APPLE_DVFS_CMD_PS1 |APPLE_DVFS_CMD_PS2 ); + reg &= ~APPLE_DVFS_CMD_PS1 ; reg |=FIELD_PREP (APPLE_DVFS_CMD_PS1 , pstate); - reg |=FIELD_PREP (APPLE_DVFS_CMD_PS2 , pstate); +if (priv->info->has_ps2) { + reg &= ~APPLE_DVFS_CMD_PS2 ; + reg |=FIELD_PREP (APPLE_DVFS_CMD_PS2 , pstate); + } reg |=APPLE_DVFS_CMD_SET ;writeq_relaxed (reg, priv->reg_base +APPLE_DVFS_CMD );
Signature · 1 line
2.47.1
PATCH v2 3/7 cpufreq: apple-soc: Allow per-SoC configuration of APPLE_DVFS_CMD_PS1
In reply to Nick ChanSupport for SoC that has a different APPLE_DVFS_CMD_PS1 will be added soon, so modify the driver first to allow it to be configured per-SoC.
--- drivers/cpufreq/apple-soc-cpufreq.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/cpufreq/apple-soc-cpufreq.c +11 -2
@@ -27,6 +27,7 @@#define APPLE_DVFS_CMD_SET BIT(25)#define APPLE_DVFS_CMD_PS2 GENMASK(15, 12)#define APPLE_DVFS_CMD_PS1 GENMASK(4, 0) +#define APPLE_DVFS_CMD_PS1_SHIFT 0/* Same timebase as CPU counter (24MHz) */ #define APPLE_DVFS_LAST_CHG_TIME 0x38
@@ -59,6 +60,8 @@ struct apple_soc_cpufreq_info {u64 max_pstate;u64 cur_pstate_mask;u64 cur_pstate_shift; +u64 ps1_mask; +u64 ps1_shift; };struct apple_cpu_priv {
@@ -74,6 +77,8 @@ static const struct apple_soc_cpufreq_info soc_t8103_info = { .max_pstate = 15, .cur_pstate_mask = APPLE_DVFS_STATUS_CUR_PS_T8103, .cur_pstate_shift = APPLE_DVFS_STATUS_CUR_PS_SHIFT_T8103, + .ps1_mask = APPLE_DVFS_CMD_PS1, + .ps1_shift = APPLE_DVFS_CMD_PS1_SHIFT, };static const struct apple_soc_cpufreq_info soc_t8112_info = {
@@ -81,12 +86,16 @@ static const struct apple_soc_cpufreq_info soc_t8112_info = { .max_pstate = 31, .cur_pstate_mask = APPLE_DVFS_STATUS_CUR_PS_T8112, .cur_pstate_shift = APPLE_DVFS_STATUS_CUR_PS_SHIFT_T8112, + .ps1_mask = APPLE_DVFS_CMD_PS1, + .ps1_shift = APPLE_DVFS_CMD_PS1_SHIFT, };static const struct apple_soc_cpufreq_info soc_default_info = { .has_ps2 = false, .max_pstate =15 , .cur_pstate_mask =0 ,/* fallback */ + .ps1_mask =APPLE_DVFS_CMD_PS1 , + .ps1_shift =APPLE_DVFS_CMD_PS1_SHIFT , };static const struct of_device_id apple_soc_cpufreq_of_match[]__maybe_unused = {
@@ -152,8 +161,8 @@ static int apple_soc_cpufreq_set_target(struct cpufreq_policy *policy,return -EIO ; } - reg &= ~APPLE_DVFS_CMD_PS1 ; - reg |=FIELD_PREP (APPLE_DVFS_CMD_PS1 , pstate); + reg &= ~priv->info->ps1_mask; + reg |= pstate << priv->info->ps1_shift;if (priv->info->has_ps2) { reg &= ~APPLE_DVFS_CMD_PS2 ; reg |=FIELD_PREP (APPLE_DVFS_CMD_PS2 , pstate);
Signature · 1 line
2.47.1
PATCH v2 4/7 cpufreq: apple-soc: Use 32-bit read for status register
In reply to Nick ChanApple A7-A9(X) SoCs requires 32-bit reads on the status register. Newer SoCs accepts 32-bit reads on the status register as well.
--- drivers/cpufreq/apple-soc-cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/apple-soc-cpufreq.c +1 -1
@@ -122,7 +122,7 @@ static unsigned int apple_soc_cpufreq_get_rate(unsigned int cpu)unsigned int pstate;if (priv->info->cur_pstate_mask) { -u64 reg =readq_relaxed (priv->reg_base +APPLE_DVFS_STATUS ); +u32 reg =readl_relaxed (priv->reg_base +APPLE_DVFS_STATUS ); pstate = (reg & priv->info->cur_pstate_mask) >> priv->info->cur_pstate_shift; }else {
Signature · 1 line
2.47.1
PATCH v2 5/7 cpufreq: apple-soc: Increase cluster switch timeout to 400us
In reply to Nick ChanApple A11 SoC takes a long time to switch. Maximum switch time observed is 345us, so increase the cluster switch timeout to 400us to be safe.
--- drivers/cpufreq/apple-soc-cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/apple-soc-cpufreq.c +1 -1
@@ -53,7 +53,7 @@#define APPLE_DVFS_PLL_FACTOR_MULT GENMASK(31, 16)#define APPLE_DVFS_PLL_FACTOR_DIV GENMASK(15, 0) -#define APPLE_DVFS_TRANSITION_TIMEOUT 100 +#define APPLE_DVFS_TRANSITION_TIMEOUT 400struct apple_soc_cpufreq_info {bool has_ps2;
Signature · 1 line
2.47.1
PATCH v2 6/7 cpufreq: apple-soc: Set fallback transition latency to APPLE_DVFS_TRANSITION_TIMEOUT
In reply to Nick ChanThe driver already assumes transitions will not take longer than APPLE_DVFS_TRANSITION_TIMEOUT in apple_soc_cpufreq_set_target(), so it makes little sense to set CPUFREQ_ETERNAL as the transition latency when the transistion latency is not given by the opp-table.
--- drivers/cpufreq/apple-soc-cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/apple-soc-cpufreq.c +1 -1
@@ -291,7 +291,7 @@ static int apple_soc_cpufreq_init(struct cpufreq_policy *policy) transition_latency =dev_pm_opp_get_max_transition_latency (cpu_dev);if (!transition_latency) - transition_latency =CPUFREQ_ETERNAL ; + transition_latency =APPLE_DVFS_TRANSITION_TIMEOUT *1000 ; policy->cpuinfo.transition_latency = transition_latency; policy->dvfs_possible_from_any_cpu = true;
Signature · 1 line
2.47.1
Re: [PATCH v2 6/7] cpufreq: apple-soc: Set fallback transition latency to APPLE_DVFS_TRANSITION_TIMEOUT
Quoted 6 lines · Nick Chan
The driver already assumes transitions will not take longer than
APPLE_DVFS_TRANSITION_TIMEOUTinapple_soc_cpufreq_set_target(), so it makes little sense to setCPUFREQ_ETERNALas the transition latency when the transistion latency is not given by the opp-table.Signed-off-by Nick Chan <[email protected]>
Quoted 17 lines
--- drivers/cpufreq/apple-soc-cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cpufreq/apple-soc-cpufreq.c +1
-1@@ -291,7 +291,7 @@ static int apple_soc_cpufreq_init(struct cpufreq_policy *policy) transition_latency =dev_pm_opp_get_max_transition_latency (cpu_dev);if (!transition_latency) - transition_latency =CPUFREQ_ETERNAL ; + transition_latency =APPLE_DVFS_TRANSITION_TIMEOUT *1000 ; policy->cpuinfo.transition_latency = transition_latency; policy->dvfs_possible_from_any_cpu = true;
Re: [PATCH v2 6/7] cpufreq: apple-soc: Set fallback transition latency to APPLE_DVFS_TRANSITION_TIMEOUT
Quoted 20 lines · Christian Loehle
Quoted 6 lines · Nick Chan
The driver already assumes transitions will not take longer than
APPLE_DVFS_TRANSITION_TIMEOUTinapple_soc_cpufreq_set_target(), so it makes little sense to setCPUFREQ_ETERNALas the transition latency when the transistion latency is not given by the opp-table.Signed-off-by Nick Chan <[email protected]>Reviewed-by Christian Loehle <[email protected]>Quoted 10 lines
--- drivers/cpufreq/apple-soc-cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cpufreq/apple-soc-cpufreq.c +0
-0@@ -291,7 +291,7 @@ static int apple_soc_cpufreq_init(struct cpufreq_policy *policy)
Quoted 4 lines
drivers/cpufreq/apple-soc-cpufreq.c static int apple_soc_cpufreq_init(struct cpufreq_policy *policy) · line 294
Quoted 4 lines
drivers/cpufreq/apple-soc-cpufreq.c +1
-1transition_latency =dev_pm_opp_get_max_transition_latency (cpu_dev);if (!transition_latency) - transition_latency =CPUFREQ_ETERNAL ; + transition_latency =APPLE_DVFS_TRANSITION_TIMEOUT *1000 ;
s/1000/NSEC_PER_USEC would have been the cleaner choice in case you respin.
Quoted 5 lines
Quoted 3 lines
drivers/cpufreq/apple-soc-cpufreq.c +0
-0policy->cpuinfo.transition_latency = transition_latency; policy->dvfs_possible_from_any_cpu = true;
PATCH v2 7/7 cpufreq: apple-soc: Add Apple A7-A8X SoC cpufreq support
In reply to Nick ChanThese SoCs only use 3 bits for p-states, and have a different APPLE_DVFS_CMD_PS1 mask value.
--- drivers/cpufreq/apple-soc-cpufreq.c | 30 +++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-)
drivers/cpufreq/apple-soc-cpufreq.c +24 -6
@@ -22,12 +22,14 @@#include <linux/pm_opp.h> #include <linux/slab.h> -#define APPLE_DVFS_CMD 0x20 -#define APPLE_DVFS_CMD_BUSY BIT(31) -#define APPLE_DVFS_CMD_SET BIT(25) -#define APPLE_DVFS_CMD_PS2 GENMASK(15, 12) -#define APPLE_DVFS_CMD_PS1 GENMASK(4, 0) -#define APPLE_DVFS_CMD_PS1_SHIFT 0 +#define APPLE_DVFS_CMD 0x20 +#define APPLE_DVFS_CMD_BUSY BIT(31) +#define APPLE_DVFS_CMD_SET BIT(25) +#define APPLE_DVFS_CMD_PS1_S5L8960X GENMASK(24, 22) +#define APPLE_DVFS_CMD_PS1_S5L8960X_SHIFT 22 +#define APPLE_DVFS_CMD_PS2 GENMASK(15, 12) +#define APPLE_DVFS_CMD_PS1 GENMASK(4, 0) +#define APPLE_DVFS_CMD_PS1_SHIFT 0/* Same timebase as CPU counter (24MHz) */ #define APPLE_DVFS_LAST_CHG_TIME 0x38
@@ -36,6 +38,9 @@* Apple ran out of bits and had to shift this in T8112... */ #define APPLE_DVFS_STATUS 0x50 +#define APPLE_DVFS_STATUS_CUR_PS_S5L8960X GENMASK(5, 3) +#define APPLE_DVFS_STATUS_CUR_PS_SHIFT_S5L8960X 3 +#define APPLE_DVFS_STATUS_TGT_PS_S5L8960X GENMASK(2, 0)#define APPLE_DVFS_STATUS_CUR_PS_T8103 GENMASK(7, 4)#define APPLE_DVFS_STATUS_CUR_PS_SHIFT_T8103 4#define APPLE_DVFS_STATUS_TGT_PS_T8103 GENMASK(3, 0)
@@ -72,6 +77,15 @@ struct apple_cpu_priv {static struct cpufreq_driver apple_soc_cpufreq_driver; +static const struct apple_soc_cpufreq_info soc_s5l8960x_info = { + .has_ps2 = false, + .max_pstate =7 , + .cur_pstate_mask =APPLE_DVFS_STATUS_CUR_PS_S5L8960X , + .cur_pstate_shift =APPLE_DVFS_STATUS_CUR_PS_SHIFT_S5L8960X , + .ps1_mask =APPLE_DVFS_CMD_PS1_S5L8960X , + .ps1_shift =APPLE_DVFS_CMD_PS1_S5L8960X_SHIFT , +}; +static const struct apple_soc_cpufreq_info soc_t8103_info = { .has_ps2 = true, .max_pstate =15 ,
@@ -99,6 +113,10 @@ static const struct apple_soc_cpufreq_info soc_default_info = { };static const struct of_device_id apple_soc_cpufreq_of_match[]__maybe_unused = { + { + .compatible ="apple,s5l8960x-cluster-cpufreq" , + .data = &soc_s5l8960x_info, + }, { .compatible ="apple,t8103-cluster-cpufreq" , .data = &soc_t8103_info,
Signature · 1 line
2.47.1