Skip to content

Commit 84cf9e5

Browse files
Ansuelvireshk
authored andcommitted
cpufreq: airoha: Add EN7581 CPUFreq SMCCC driver
Add simple CPU Freq driver for Airoha EN7581 SoC that control CPU frequency scaling with SMC APIs and register a generic "cpufreq-dt" device. All CPU share the same frequency and can't be controlled independently. CPU frequency is controlled by the attached PM domain. Add SoC compatible to cpufreq-dt-plat block list as a dedicated cpufreq driver is needed with OPP v2 nodes declared in DTS. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent af6cc45 commit 84cf9e5

File tree

4 files changed

+163
-0
lines changed

4 files changed

+163
-0
lines changed

drivers/cpufreq/Kconfig.arm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ config ARM_ALLWINNER_SUN50I_CPUFREQ_NVMEM
1515
To compile this driver as a module, choose M here: the
1616
module will be called sun50i-cpufreq-nvmem.
1717

18+
config ARM_AIROHA_SOC_CPUFREQ
19+
tristate "Airoha EN7581 SoC CPUFreq support"
20+
depends on ARCH_AIROHA || COMPILE_TEST
21+
select PM_OPP
22+
default ARCH_AIROHA
23+
help
24+
This adds the CPUFreq driver for Airoha EN7581 SoCs.
25+
1826
config ARM_APPLE_SOC_CPUFREQ
1927
tristate "Apple Silicon SoC CPUFreq support"
2028
depends on ARCH_APPLE || (COMPILE_TEST && 64BIT)

drivers/cpufreq/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ obj-$(CONFIG_X86_AMD_FREQ_SENSITIVITY) += amd_freq_sensitivity.o
5353

5454
##################################################################################
5555
# ARM SoC drivers
56+
obj-$(CONFIG_ARM_AIROHA_SOC_CPUFREQ) += airoha-cpufreq.o
5657
obj-$(CONFIG_ARM_APPLE_SOC_CPUFREQ) += apple-soc-cpufreq.o
5758
obj-$(CONFIG_ARM_ARMADA_37XX_CPUFREQ) += armada-37xx-cpufreq.o
5859
obj-$(CONFIG_ARM_ARMADA_8K_CPUFREQ) += armada-8k-cpufreq.o

drivers/cpufreq/airoha-cpufreq.c

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/bitfield.h>
4+
#include <linux/cpufreq.h>
5+
#include <linux/module.h>
6+
#include <linux/platform_device.h>
7+
#include <linux/pm_domain.h>
8+
#include <linux/pm_runtime.h>
9+
#include <linux/slab.h>
10+
11+
#include "cpufreq-dt.h"
12+
13+
struct airoha_cpufreq_priv {
14+
int opp_token;
15+
struct dev_pm_domain_list *pd_list;
16+
struct platform_device *cpufreq_dt;
17+
};
18+
19+
static struct platform_device *cpufreq_pdev;
20+
21+
/* NOP function to disable OPP from setting clock */
22+
static int airoha_cpufreq_config_clks_nop(struct device *dev,
23+
struct opp_table *opp_table,
24+
struct dev_pm_opp *opp,
25+
void *data, bool scaling_down)
26+
{
27+
return 0;
28+
}
29+
30+
static const char * const airoha_cpufreq_clk_names[] = { "cpu", NULL };
31+
static const char * const airoha_cpufreq_pd_names[] = { "perf" };
32+
33+
static int airoha_cpufreq_probe(struct platform_device *pdev)
34+
{
35+
const struct dev_pm_domain_attach_data attach_data = {
36+
.pd_names = airoha_cpufreq_pd_names,
37+
.num_pd_names = ARRAY_SIZE(airoha_cpufreq_pd_names),
38+
.pd_flags = PD_FLAG_DEV_LINK_ON | PD_FLAG_REQUIRED_OPP,
39+
};
40+
struct dev_pm_opp_config config = {
41+
.clk_names = airoha_cpufreq_clk_names,
42+
.config_clks = airoha_cpufreq_config_clks_nop,
43+
};
44+
struct platform_device *cpufreq_dt;
45+
struct airoha_cpufreq_priv *priv;
46+
struct device *dev = &pdev->dev;
47+
struct device *cpu_dev;
48+
int ret;
49+
50+
/* CPUs refer to the same OPP table */
51+
cpu_dev = get_cpu_device(0);
52+
if (!cpu_dev)
53+
return -ENODEV;
54+
55+
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
56+
if (!priv)
57+
return -ENOMEM;
58+
59+
/* Set OPP table conf with NOP config_clks */
60+
priv->opp_token = dev_pm_opp_set_config(cpu_dev, &config);
61+
if (priv->opp_token < 0)
62+
return dev_err_probe(dev, priv->opp_token, "Failed to set OPP config\n");
63+
64+
/* Attach PM for OPP */
65+
ret = dev_pm_domain_attach_list(cpu_dev, &attach_data,
66+
&priv->pd_list);
67+
if (ret)
68+
goto clear_opp_config;
69+
70+
cpufreq_dt = platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
71+
ret = PTR_ERR_OR_ZERO(cpufreq_dt);
72+
if (ret) {
73+
dev_err(dev, "failed to create cpufreq-dt device: %d\n", ret);
74+
goto detach_pm;
75+
}
76+
77+
priv->cpufreq_dt = cpufreq_dt;
78+
platform_set_drvdata(pdev, priv);
79+
80+
return 0;
81+
82+
detach_pm:
83+
dev_pm_domain_detach_list(priv->pd_list);
84+
clear_opp_config:
85+
dev_pm_opp_clear_config(priv->opp_token);
86+
87+
return ret;
88+
}
89+
90+
static void airoha_cpufreq_remove(struct platform_device *pdev)
91+
{
92+
struct airoha_cpufreq_priv *priv = platform_get_drvdata(pdev);
93+
94+
platform_device_unregister(priv->cpufreq_dt);
95+
96+
dev_pm_domain_detach_list(priv->pd_list);
97+
98+
dev_pm_opp_clear_config(priv->opp_token);
99+
}
100+
101+
static struct platform_driver airoha_cpufreq_driver = {
102+
.probe = airoha_cpufreq_probe,
103+
.remove = airoha_cpufreq_remove,
104+
.driver = {
105+
.name = "airoha-cpufreq",
106+
},
107+
};
108+
109+
static const struct of_device_id airoha_cpufreq_match_list[] __initconst = {
110+
{ .compatible = "airoha,en7581" },
111+
{},
112+
};
113+
MODULE_DEVICE_TABLE(of, airoha_cpufreq_match_list);
114+
115+
static int __init airoha_cpufreq_init(void)
116+
{
117+
struct device_node *np = of_find_node_by_path("/");
118+
const struct of_device_id *match;
119+
int ret;
120+
121+
if (!np)
122+
return -ENODEV;
123+
124+
match = of_match_node(airoha_cpufreq_match_list, np);
125+
of_node_put(np);
126+
if (!match)
127+
return -ENODEV;
128+
129+
ret = platform_driver_register(&airoha_cpufreq_driver);
130+
if (unlikely(ret < 0))
131+
return ret;
132+
133+
cpufreq_pdev = platform_device_register_data(NULL, "airoha-cpufreq",
134+
-1, match, sizeof(*match));
135+
ret = PTR_ERR_OR_ZERO(cpufreq_pdev);
136+
if (ret)
137+
platform_driver_unregister(&airoha_cpufreq_driver);
138+
139+
return ret;
140+
}
141+
module_init(airoha_cpufreq_init);
142+
143+
static void __exit airoha_cpufreq_exit(void)
144+
{
145+
platform_device_unregister(cpufreq_pdev);
146+
platform_driver_unregister(&airoha_cpufreq_driver);
147+
}
148+
module_exit(airoha_cpufreq_exit);
149+
150+
MODULE_AUTHOR("Christian Marangi <ansuelsmth@gmail.com>");
151+
MODULE_DESCRIPTION("CPUfreq driver for Airoha SoCs");
152+
MODULE_LICENSE("GPL");

drivers/cpufreq/cpufreq-dt-platdev.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ static const struct of_device_id allowlist[] __initconst = {
103103
* platforms using "operating-points-v2" property.
104104
*/
105105
static const struct of_device_id blocklist[] __initconst = {
106+
{ .compatible = "airoha,en7581", },
107+
106108
{ .compatible = "allwinner,sun50i-a100" },
107109
{ .compatible = "allwinner,sun50i-h6", },
108110
{ .compatible = "allwinner,sun50i-h616", },

0 commit comments

Comments
 (0)