1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
// SPDX-License-Identifier: GPL-2.0
#include <linux/arm-smccc.h>
#include <linux/bitfield.h>
#include <linux/clk-provider.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/pm_domain.h>
#include <linux/slab.h>
#define AIROHA_SIP_AVS_HANDLE 0x82000301
#define AIROHA_AVS_OP_BASE 0xddddddd0
#define AIROHA_AVS_OP_MASK GENMASK(1, 0)
#define AIROHA_AVS_OP_FREQ_DYN_ADJ (AIROHA_AVS_OP_BASE | \
FIELD_PREP(AIROHA_AVS_OP_MASK, 0x1))
#define AIROHA_AVS_OP_GET_FREQ (AIROHA_AVS_OP_BASE | \
FIELD_PREP(AIROHA_AVS_OP_MASK, 0x2))
struct airoha_cpu_pmdomain_priv {
struct clk_hw hw;
struct generic_pm_domain pd;
};
static long airoha_cpu_pmdomain_clk_round(struct clk_hw *hw, unsigned long rate,
unsigned long *parent_rate)
{
return rate;
}
static unsigned long airoha_cpu_pmdomain_clk_get(struct clk_hw *hw,
unsigned long parent_rate)
{
struct arm_smccc_res res;
arm_smccc_1_1_invoke(AIROHA_SIP_AVS_HANDLE, AIROHA_AVS_OP_GET_FREQ,
0, 0, 0, 0, 0, 0, &res);
/* SMCCC returns freq in MHz */
return (int)(res.a0 * 1000 * 1000);
}
/* Airoha CPU clk SMCC is always enabled */
static int airoha_cpu_pmdomain_clk_is_enabled(struct clk_hw *hw)
{
return true;
}
static const struct clk_ops airoha_cpu_pmdomain_clk_ops = {
.recalc_rate = airoha_cpu_pmdomain_clk_get,
.is_enabled = airoha_cpu_pmdomain_clk_is_enabled,
.round_rate = airoha_cpu_pmdomain_clk_round,
};
static int airoha_cpu_pmdomain_set_performance_state(struct generic_pm_domain *domain,
unsigned int state)
{
struct arm_smccc_res res;
arm_smccc_1_1_invoke(AIROHA_SIP_AVS_HANDLE, AIROHA_AVS_OP_FREQ_DYN_ADJ,
0, state, 0, 0, 0, 0, &res);
/* SMC signal correct apply by unsetting BIT 0 */
return res.a0 & BIT(0) ? -EINVAL : 0;
}
static int airoha_cpu_pmdomain_probe(struct platform_device *pdev)
{
struct airoha_cpu_pmdomain_priv *priv;
struct device *dev = &pdev->dev;
const struct clk_init_data init = {
.name = "cpu",
.ops = &airoha_cpu_pmdomain_clk_ops,
/* Clock with no set_rate, can't cache */
.flags = CLK_GET_RATE_NOCACHE,
};
struct generic_pm_domain *pd;
int ret;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
/* Init and register a get-only clk for Cpufreq */
priv->hw.init = &init;
ret = devm_clk_hw_register(dev, &priv->hw);
if (ret)
return ret;
ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get,
&priv->hw);
if (ret)
return ret;
/* Init and register a PD for CPU */
pd = &priv->pd;
pd->name = "cpu_pd";
pd->flags = GENPD_FLAG_ALWAYS_ON;
pd->set_performance_state = airoha_cpu_pmdomain_set_performance_state;
ret = pm_genpd_init(pd, NULL, false);
if (ret)
return ret;
ret = of_genpd_add_provider_simple(dev->of_node, pd);
if (ret)
goto err_add_provider;
platform_set_drvdata(pdev, priv);
return 0;
err_add_provider:
pm_genpd_remove(pd);
return ret;
}
static void airoha_cpu_pmdomain_remove(struct platform_device *pdev)
{
struct airoha_cpu_pmdomain_priv *priv = platform_get_drvdata(pdev);
of_genpd_del_provider(pdev->dev.of_node);
pm_genpd_remove(&priv->pd);
}
static const struct of_device_id airoha_cpu_pmdomain_of_match[] = {
{ .compatible = "airoha,en7581-cpufreq" },
{ },
};
MODULE_DEVICE_TABLE(of, airoha_cpu_pmdomain_of_match);
static struct platform_driver airoha_cpu_pmdomain_driver = {
.probe = airoha_cpu_pmdomain_probe,
.remove = airoha_cpu_pmdomain_remove,
.driver = {
.name = "airoha-cpu-pmdomain",
.of_match_table = airoha_cpu_pmdomain_of_match,
},
};
module_platform_driver(airoha_cpu_pmdomain_driver);
MODULE_AUTHOR("Christian Marangi <ansuelsmth@gmail.com>");
MODULE_DESCRIPTION("CPU PM domain driver for Airoha SoCs");
MODULE_LICENSE("GPL");
|