Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * System Control and Power Interface (SCMI) based CPUFreq Interface driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2018 ARM Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Sudeep Holla <sudeep.holla@arm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/clk-provider.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/cpufreq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/energy_model.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/pm_opp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/scmi_protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) struct scmi_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	int domain_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct device *cpu_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static struct scmi_protocol_handle *ph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static const struct scmi_perf_proto_ops *perf_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static unsigned int scmi_cpufreq_get_rate(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct scmi_data *priv = policy->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	unsigned long rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	ret = perf_ops->freq_get(ph, priv->domain_id, &rate, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return rate / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * perf_ops->freq_set is not a synchronous, the actual OPP change will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * happen asynchronously and can get notified if the events are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * subscribed for by the SCMI firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) scmi_cpufreq_set_target(struct cpufreq_policy *policy, unsigned int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct scmi_data *priv = policy->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	u64 freq = policy->freq_table[index].frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return perf_ops->freq_set(ph, priv->domain_id, freq * 1000, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static unsigned int scmi_cpufreq_fast_switch(struct cpufreq_policy *policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 					     unsigned int target_freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct scmi_data *priv = policy->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (!perf_ops->freq_set(ph, priv->domain_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 				target_freq * 1000, true))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return target_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) scmi_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	int cpu, domain, tdomain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct device *tcpu_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	domain = perf_ops->device_domain_id(cpu_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (domain < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	for_each_possible_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		if (cpu == cpu_dev->id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		tcpu_dev = get_cpu_device(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		if (!tcpu_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		tdomain = perf_ops->device_domain_id(tcpu_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if (tdomain == domain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			cpumask_set_cpu(cpu, cpumask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) static int __maybe_unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) scmi_get_cpu_power(unsigned long *power, unsigned long *KHz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		   struct device *cpu_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	unsigned long Hz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	int ret, domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	domain = perf_ops->device_domain_id(cpu_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (domain < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	/* Get the power cost of the performance domain. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	Hz = *KHz * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	ret = perf_ops->est_power_get(ph, domain, &Hz, power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/* The EM framework specifies the frequency in KHz. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	*KHz = Hz / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int scmi_cpufreq_init(struct cpufreq_policy *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	int ret, nr_opp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	unsigned int latency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct device *cpu_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct scmi_data *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct cpufreq_frequency_table *freq_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct em_data_callback em_cb = EM_DATA_CB(scmi_get_cpu_power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	bool power_scale_mw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	cpu_dev = get_cpu_device(policy->cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (!cpu_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		pr_err("failed to get cpu%d device\n", policy->cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	ret = perf_ops->device_opps_add(ph, cpu_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		dev_warn(cpu_dev, "failed to add opps to the device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	ret = scmi_get_sharing_cpus(cpu_dev, policy->cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		dev_warn(cpu_dev, "failed to get sharing cpumask\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	ret = dev_pm_opp_set_sharing_cpus(cpu_dev, policy->cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		dev_err(cpu_dev, "%s: failed to mark OPPs as shared: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			__func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	nr_opp = dev_pm_opp_get_opp_count(cpu_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (nr_opp <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		dev_dbg(cpu_dev, "OPP table is not ready, deferring probe\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		ret = -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		goto out_free_opp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (!priv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		goto out_free_opp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		goto out_free_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	priv->cpu_dev = cpu_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	priv->domain_id = perf_ops->device_domain_id(cpu_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	policy->driver_data = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	policy->freq_table = freq_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/* SCMI allows DVFS request for any domain from any CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	policy->dvfs_possible_from_any_cpu = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	latency = perf_ops->transition_latency_get(ph, cpu_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (!latency)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		latency = CPUFREQ_ETERNAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	policy->cpuinfo.transition_latency = latency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	policy->fast_switch_possible =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		perf_ops->fast_switch_possible(ph, cpu_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	power_scale_mw = perf_ops->power_scale_mw_get(ph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	em_dev_register_perf_domain(cpu_dev, nr_opp, &em_cb, policy->cpus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 				    power_scale_mw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) out_free_priv:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	kfree(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) out_free_opp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	dev_pm_opp_remove_all_dynamic(cpu_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static int scmi_cpufreq_exit(struct cpufreq_policy *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct scmi_data *priv = policy->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	dev_pm_opp_remove_all_dynamic(priv->cpu_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	kfree(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static struct cpufreq_driver scmi_cpufreq_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	.name	= "scmi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	.flags	= CPUFREQ_STICKY | CPUFREQ_HAVE_GOVERNOR_PER_POLICY |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		  CPUFREQ_NEED_INITIAL_FREQ_CHECK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		  CPUFREQ_IS_COOLING_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	.verify	= cpufreq_generic_frequency_table_verify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	.attr	= cpufreq_generic_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	.target_index	= scmi_cpufreq_set_target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	.fast_switch	= scmi_cpufreq_fast_switch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	.get	= scmi_cpufreq_get_rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	.init	= scmi_cpufreq_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	.exit	= scmi_cpufreq_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static int scmi_cpufreq_probe(struct scmi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct device *dev = &sdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	const struct scmi_handle *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	handle = sdev->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (!handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	perf_ops = handle->devm_get_protocol(sdev, SCMI_PROTOCOL_PERF, &ph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (IS_ERR(perf_ops))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		return PTR_ERR(perf_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #ifdef CONFIG_COMMON_CLK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	/* dummy clock provider as needed by OPP if clocks property is used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (of_find_property(dev->of_node, "#clock-cells", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	ret = cpufreq_register_driver(&scmi_cpufreq_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		dev_err(dev, "%s: registering cpufreq failed, err: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			__func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static void scmi_cpufreq_remove(struct scmi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	cpufreq_unregister_driver(&scmi_cpufreq_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static const struct scmi_device_id scmi_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	{ SCMI_PROTOCOL_PERF, "cpufreq" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) MODULE_DEVICE_TABLE(scmi, scmi_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static struct scmi_driver scmi_cpufreq_drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	.name		= "scmi-cpufreq",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	.probe		= scmi_cpufreq_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	.remove		= scmi_cpufreq_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	.id_table	= scmi_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) module_scmi_driver(scmi_cpufreq_drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) MODULE_DESCRIPTION("ARM SCMI CPUFreq interface driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) MODULE_LICENSE("GPL v2");