Lines Matching +full:cpufreq +full:- +full:hw
1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/cpufreq.h>
61 policy = cpufreq_cpu_get_raw(cpu_dev->id); in mtk_cpufreq_get_cpu_power()
65 data = policy->driver_data; in mtk_cpufreq_get_cpu_power()
67 for (i = 0; i < data->nr_opp; i++) { in mtk_cpufreq_get_cpu_power()
68 if (data->table[i].frequency < *KHz) in mtk_cpufreq_get_cpu_power()
71 i--; in mtk_cpufreq_get_cpu_power()
73 *KHz = data->table[i].frequency; in mtk_cpufreq_get_cpu_power()
74 /* Provide micro-Watts value to the Energy Model */ in mtk_cpufreq_get_cpu_power()
75 *uW = readl_relaxed(data->reg_bases[REG_EM_POWER_TBL] + in mtk_cpufreq_get_cpu_power()
84 struct mtk_cpufreq_data *data = policy->driver_data; in mtk_cpufreq_hw_target_index()
86 writel_relaxed(index, data->reg_bases[REG_FREQ_PERF_STATE]); in mtk_cpufreq_hw_target_index()
101 data = policy->driver_data; in mtk_cpufreq_hw_get()
103 index = readl_relaxed(data->reg_bases[REG_FREQ_PERF_STATE]); in mtk_cpufreq_hw_get()
104 index = min(index, LUT_MAX_ENTRIES - 1); in mtk_cpufreq_hw_get()
106 return data->table[index].frequency; in mtk_cpufreq_hw_get()
112 struct mtk_cpufreq_data *data = policy->driver_data; in mtk_cpufreq_hw_fast_switch()
117 writel_relaxed(index, data->reg_bases[REG_FREQ_PERF_STATE]); in mtk_cpufreq_hw_fast_switch()
119 return policy->freq_table[index].frequency; in mtk_cpufreq_hw_fast_switch()
125 struct device *dev = &pdev->dev; in mtk_cpu_create_freq_table()
129 data->table = devm_kcalloc(dev, LUT_MAX_ENTRIES + 1, in mtk_cpu_create_freq_table()
130 sizeof(*data->table), GFP_KERNEL); in mtk_cpu_create_freq_table()
131 if (!data->table) in mtk_cpu_create_freq_table()
132 return -ENOMEM; in mtk_cpu_create_freq_table()
134 base_table = data->reg_bases[REG_FREQ_LUT_TABLE]; in mtk_cpu_create_freq_table()
143 data->table[i].frequency = freq; in mtk_cpu_create_freq_table()
145 dev_dbg(dev, "index=%d freq=%d\n", i, data->table[i].frequency); in mtk_cpu_create_freq_table()
150 data->table[i].frequency = CPUFREQ_TABLE_END; in mtk_cpu_create_freq_table()
151 data->nr_opp = i; in mtk_cpu_create_freq_table()
161 struct device *dev = &pdev->dev; in mtk_cpu_resources_init()
169 return -ENOMEM; in mtk_cpu_resources_init()
171 index = of_perf_domain_get_sharing_cpumask(policy->cpu, "performance-domains", in mtk_cpu_resources_init()
172 "#performance-domain-cells", in mtk_cpu_resources_init()
173 policy->cpus); in mtk_cpu_resources_init()
180 return -ENODEV; in mtk_cpu_resources_init()
183 if (!request_mem_region(res->start, resource_size(res), res->name)) { in mtk_cpu_resources_init()
185 return -EBUSY; in mtk_cpu_resources_init()
188 base = ioremap(res->start, resource_size(res)); in mtk_cpu_resources_init()
191 ret = -ENOMEM; in mtk_cpu_resources_init()
195 data->base = base; in mtk_cpu_resources_init()
196 data->res = res; in mtk_cpu_resources_init()
199 data->reg_bases[i] = base + offsets[i]; in mtk_cpu_resources_init()
203 dev_info(dev, "Domain-%d failed to create freq table\n", index); in mtk_cpu_resources_init()
207 policy->freq_table = data->table; in mtk_cpu_resources_init()
208 policy->driver_data = data; in mtk_cpu_resources_init()
212 release_mem_region(res->start, resource_size(res)); in mtk_cpu_resources_init()
224 /* Get the bases of cpufreq for domains */ in mtk_cpufreq_hw_cpu_init()
227 dev_info(&pdev->dev, "CPUFreq resource init failed\n"); in mtk_cpufreq_hw_cpu_init()
231 data = policy->driver_data; in mtk_cpufreq_hw_cpu_init()
233 latency = readl_relaxed(data->reg_bases[REG_FREQ_LATENCY]) * 1000; in mtk_cpufreq_hw_cpu_init()
237 policy->cpuinfo.transition_latency = latency; in mtk_cpufreq_hw_cpu_init()
238 policy->fast_switch_possible = true; in mtk_cpufreq_hw_cpu_init()
240 /* HW should be in enabled state to proceed now */ in mtk_cpufreq_hw_cpu_init()
241 writel_relaxed(0x1, data->reg_bases[REG_FREQ_ENABLE]); in mtk_cpufreq_hw_cpu_init()
242 if (readl_poll_timeout(data->reg_bases[REG_FREQ_HW_STATE], sig, in mtk_cpufreq_hw_cpu_init()
246 pr_info("cpufreq hardware of CPU%d is not enabled\n", in mtk_cpufreq_hw_cpu_init()
247 policy->cpu); in mtk_cpufreq_hw_cpu_init()
248 return -ENODEV; in mtk_cpufreq_hw_cpu_init()
251 pr_info("SVS of CPU%d is not enabled\n", policy->cpu); in mtk_cpufreq_hw_cpu_init()
259 struct mtk_cpufreq_data *data = policy->driver_data; in mtk_cpufreq_hw_cpu_exit()
260 struct resource *res = data->res; in mtk_cpufreq_hw_cpu_exit()
261 void __iomem *base = data->base; in mtk_cpufreq_hw_cpu_exit()
263 /* HW should be in paused state now */ in mtk_cpufreq_hw_cpu_exit()
264 writel_relaxed(0x0, data->reg_bases[REG_FREQ_ENABLE]); in mtk_cpufreq_hw_cpu_exit()
266 release_mem_region(res->start, resource_size(res)); in mtk_cpufreq_hw_cpu_exit()
274 struct mtk_cpufreq_data *data = policy->driver_data; in mtk_cpufreq_register_em()
276 em_dev_register_perf_domain(get_cpu_device(policy->cpu), data->nr_opp, in mtk_cpufreq_register_em()
277 &em_cb, policy->cpus, true); in mtk_cpufreq_register_em()
291 .name = "mtk-cpufreq-hw",
300 data = of_device_get_match_data(&pdev->dev); in mtk_cpufreq_hw_driver_probe()
302 return -EINVAL; in mtk_cpufreq_hw_driver_probe()
309 dev_err(&pdev->dev, "CPUFreq HW driver failed to register\n"); in mtk_cpufreq_hw_driver_probe()
320 { .compatible = "mediatek,cpufreq-hw", .data = &cpufreq_mtk_offsets },
328 .name = "mtk-cpufreq-hw",
335 MODULE_DESCRIPTION("Mediatek cpufreq-hw driver");