2 * System Control and Power Interface (SCPI) based CPUFreq Interface driver
4 * It provides necessary ops to arm_big_little cpufreq driver.
6 * Copyright (C) 2015 ARM Ltd.
7 * Sudeep Holla <sudeep.holla@arm.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
14 * kind, whether express or implied; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/cpufreq.h>
22 #include <linux/module.h>
23 #include <linux/platform_device.h>
24 #include <linux/pm_opp.h>
25 #include <linux/scpi_protocol.h>
26 #include <linux/types.h>
28 #include "arm_big_little.h"
30 static struct scpi_ops
*scpi_ops
;
32 static struct scpi_dvfs_info
*scpi_get_dvfs_info(struct device
*cpu_dev
)
34 int domain
= topology_physical_package_id(cpu_dev
->id
);
37 return ERR_PTR(-EINVAL
);
38 return scpi_ops
->dvfs_get_info(domain
);
41 static int scpi_opp_table_ops(struct device
*cpu_dev
, bool remove
)
45 struct scpi_dvfs_info
*info
= scpi_get_dvfs_info(cpu_dev
);
53 for (opp
= info
->opps
, idx
= 0; idx
< info
->count
; idx
++, opp
++) {
55 dev_pm_opp_remove(cpu_dev
, opp
->freq
);
57 ret
= dev_pm_opp_add(cpu_dev
, opp
->freq
,
60 dev_warn(cpu_dev
, "failed to add opp %uHz %umV\n",
61 opp
->freq
, opp
->m_volt
);
63 dev_pm_opp_remove(cpu_dev
, (--opp
)->freq
);
70 static int scpi_get_transition_latency(struct device
*cpu_dev
)
72 struct scpi_dvfs_info
*info
= scpi_get_dvfs_info(cpu_dev
);
79 static int scpi_init_opp_table(struct device
*cpu_dev
)
81 return scpi_opp_table_ops(cpu_dev
, false);
84 static void scpi_free_opp_table(struct device
*cpu_dev
)
86 scpi_opp_table_ops(cpu_dev
, true);
89 static struct cpufreq_arm_bL_ops scpi_cpufreq_ops
= {
91 .get_transition_latency
= scpi_get_transition_latency
,
92 .init_opp_table
= scpi_init_opp_table
,
93 .free_opp_table
= scpi_free_opp_table
,
96 static int scpi_cpufreq_probe(struct platform_device
*pdev
)
98 scpi_ops
= get_scpi_ops();
102 return bL_cpufreq_register(&scpi_cpufreq_ops
);
105 static int scpi_cpufreq_remove(struct platform_device
*pdev
)
107 bL_cpufreq_unregister(&scpi_cpufreq_ops
);
112 static struct platform_driver scpi_cpufreq_platdrv
= {
114 .name
= "scpi-cpufreq",
115 .owner
= THIS_MODULE
,
117 .probe
= scpi_cpufreq_probe
,
118 .remove
= scpi_cpufreq_remove
,
120 module_platform_driver(scpi_cpufreq_platdrv
);
122 MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
123 MODULE_DESCRIPTION("ARM SCPI CPUFreq interface driver");
124 MODULE_LICENSE("GPL v2");