cpufreq: opp: Add device tree based lookup of boost mode frequency
v5 cover cpufreq: opp: Add device tree based lookup of boost mode frequency
Changes since v5:
- Code improvements suggested by Viresh Kumar.
Changes since v4:
- Includes cleanup changes suggested by Viresh Kumar.
Changes since v3:
- Minor changes as suggested in the last version.
Changes since v2:
- Reworked based on the "PM / OPP: move cpufreq specific helpers out of OPP layer" patch series posted by Nishanth Menon <[email protected]>.
Changes since v1:
- Boost mode frequencies are specfied as a set of frequencies instead of specifying them as OPPs. Thanks to Nishanth, Lukasz and Rob for the feedback.
Commit 6f19efc0 ("cpufreq: Add boost frequency support in core") adds support for CPU boost mode for CPUfreq drivers. To use the new boost mode, CPUfreq drivers have to specify the boost mode frequency and voltage within the CPUfreq driver, which is the case for Exynos4x12 CPUfreq driver.
But for CPUfreq drivers which obtain the OPPs from cpus node, this patch series adds support to specify boost mode frequencies in the cpu device tree node. This requirement came up when Lukasz pointed out the regression caused by the Exynos CPUfreq driver consolidation patches.
PATCH v5 1/2 cpufreq / OPP: Allow boost frequency to be looked up from device tree
From: Thomas Abraham <[email protected]>
Commit 6f19efc0 ("cpufreq: Add boost frequency support in core") adds support for CPU boost mode. This patch adds support for finding available boost frequencies from device tree and marking them as usable in boost mode.
--- drivers/cpufreq/cpufreq_opp.c | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
drivers/cpufreq/cpufreq_opp.c +45 -0
@@ -19,6 +19,7 @@#include <linux/pm_opp.h> #include <linux/rcupdate.h> #include <linux/slab.h> +#include <linux/of.h> /** * dev_pm_opp_init_cpufreq_table() - create a cpufreq table for a device
@@ -51,6 +52,11 @@ int dev_pm_opp_init_cpufreq_table(struct device *dev,struct cpufreq_frequency_table *freq_table =NULL ;int i, max_opps, ret =0 ;unsigned long rate; +#ifdef CONFIG_CPU_FREQ_BOOST_SW +struct cpufreq_frequency_table *ft; +int len, count; +u32 *boost_freqs =NULL ; +#endif rcu_read_lock ();
@@ -82,6 +88,45 @@ int dev_pm_opp_init_cpufreq_table(struct device *dev, *table = &freq_table[0 ]; +#ifdef CONFIG_CPU_FREQ_BOOST_SW +if (!of_find_property (dev->of_node,"boost-frequencies" , &len)) + goto out; + +if (!len || !IS_ALIGNED (len,sizeof (u32))) { +dev_err (dev,"%s: invalid boost frequency\n" , __func__); + ret = -EINVAL ; + goto out; + } + + boost_freqs =kmalloc (len,GFP_KERNEL ); +if (!boost_freqs) { +dev_err (dev,"%s: no memory for boost freq table\n" , __func__); + ret = -ENOMEM ; + goto out; + } + + count = len /sizeof (u32); +of_property_read_u32_array (dev->of_node,"boost-frequencies" , + boost_freqs, count); + +for (i =0 ; i < count; i++) { +cpufreq_for_each_valid_entry (ft, *table) { +if (boost_freqs[i] == ft->frequency) { + ft->flags |=CPUFREQ_BOOST_FREQ ; +pr_debug ("%s: marked %d as boost frequency\n" , + __func__, boost_freqs[i]); +break ; + } + } + +if (ft->frequency ==CPUFREQ_TABLE_END ) +dev_err (dev,"%s: invalid boost frequency %d\n" , + __func__, boost_freqs[i]); + } + +kfree (boost_freqs); +#endif + out:rcu_read_unlock ();if (ret)
Signature · 1 line
1.7.9.5
PATCH v5 1/2 cpufreq / OPP: Allow boost frequency to be looked up from device tree
Quoted 74 lines · Thomas Abraham
From: Thomas Abraham <[email protected]>
Commit
6f19efc0("cpufreq: Add boost frequency support in core") adds support for CPU boost mode. This patch adds support for finding available boost frequencies from device tree and marking them as usable in boost mode.Cc Nishanth Menon <[email protected]>Cc Lukasz Majewski <[email protected]>Signed-off-by Thomas Abraham <[email protected]>--- drivers/cpufreq/cpufreq_opp.c | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)drivers/cpufreq/cpufreq_opp.c +38
-0@@ -19,6 +19,7 @@#include <linux/pm_opp.h> #include <linux/rcupdate.h> #include <linux/slab.h> +#include <linux/of.h> /** * dev_pm_opp_init_cpufreq_table() - create a cpufreq table for a device @@ -51,6 +52,11 @@ int dev_pm_opp_init_cpufreq_table(struct device *dev,struct cpufreq_frequency_table *freq_table =NULL ;int i, max_opps, ret =0 ;unsigned long rate; +#ifdef CONFIG_CPU_FREQ_BOOST_SW +struct cpufreq_frequency_table *ft; +int len, count; +u32 *boost_freqs =NULL ; +#endif rcu_read_lock ();@@ -82,6 +88,45 @@ int dev_pm_opp_init_cpufreq_table(struct device *dev, *table = &freq_table[0 ]; +#ifdef CONFIG_CPU_FREQ_BOOST_SW +if (!of_find_property (dev->of_node,"boost-frequencies" , &len)) + goto out; + +if (!len || !IS_ALIGNED (len,sizeof (u32))) { +dev_err (dev,"%s: invalid boost frequency\n" , __func__); + ret = -EINVAL ; + goto out; + } + + boost_freqs =kmalloc (len,GFP_KERNEL ); +if (!boost_freqs) { +dev_err (dev,"%s: no memory for boost freq table\n" , __func__); + ret = -ENOMEM ; + goto out; + } + + count = len /sizeof (u32); +of_property_read_u32_array (dev->of_node,"boost-frequencies" , + boost_freqs, count); + +for (i =0 ; i < count; i++) { +cpufreq_for_each_valid_entry (ft, *table) { +if (boost_freqs[i] == ft->frequency) { + ft->flags |=CPUFREQ_BOOST_FREQ ; +pr_debug ("%s: marked %d as boost frequency\n" , + __func__, boost_freqs[i]); +break ; + } + } + +if (ft->frequency ==CPUFREQ_TABLE_END )
drivers/cpufreq/cpufreq_opp.c int dev_pm_opp_init_cpufreq_table(struct device *dev, · line 132
Quoted 10 lines
drivers/cpufreq/cpufreq_opp.c +7
-0+dev_err (dev,"%s: invalid boost frequency %d\n" , + __func__, boost_freqs[i]); + } + +kfree (boost_freqs); +#endif + out:rcu_read_unlock ();if (ret)
I suggest the following checkpatch --strict warnings should be fixed.
@@ -0,0 +1,10 @@
+CHECK: Alignment should match open parenthesis +#65: FILE: drivers/cpufreq/cpufreq_opp.c:110:
++ of_property_read_u32_array(dev->of_node, "boost-frequencies",
++ boost_freqs, count);
+CHECK: Alignment should match open parenthesis +#72: FILE: drivers/cpufreq/cpufreq_opp.c:117:
++ pr_debug("%s: marked %d as boost
frequency\n",
++ __func__, boost_freqs[i]);
+If any of these errors are false positives, please report +them to the maintainer, see CHECKPATCH in MAINTAINERS.
Otherwise,
For the entire series:
Signature · 2 lines
Regards, Nishanth Menon
PATCH v5 1/2 cpufreq / OPP: Allow boost frequency to be looked up from device tree
In reply to Thomas AbrahamHi Thomas,
Quoted 81 lines
From: Thomas Abraham <[email protected]>
Commit
6f19efc0("cpufreq: Add boost frequency support in core") adds support for CPU boost mode. This patch adds support for finding available boost frequencies from device tree and marking them as usable in boost mode.Cc Nishanth Menon <[email protected]>Cc Lukasz Majewski <[email protected]>Signed-off-by Thomas Abraham <[email protected]>--- drivers/cpufreq/cpufreq_opp.c | 45+++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
(quoted diff) +0
-0
b/drivers/cpufreq/cpufreq_opp.cindex c0c6f4a..05fb115 100644drivers/cpufreq/cpufreq_opp.c +1
-0@@ -19,6 +19,7 @@#include <linux/pm_opp.h> #include <linux/rcupdate.h> #include <linux/slab.h> +#include <linux/of.h> /** * dev_pm_opp_init_cpufreq_table() - create a cpufreq table for a device @@ -51,6 +52,11 @@ int dev_pm_opp_init_cpufreq_table(struct device *dev, struct
cpufreq_frequency_table*freq_table= NULL;drivers/cpufreq/cpufreq_opp.c +31
-0int i, max_opps, ret =0 ;unsigned long rate; +#ifdef CONFIG_CPU_FREQ_BOOST_SW +struct cpufreq_frequency_table *ft; +int len, count; +u32 *boost_freqs =NULL ; +#endif rcu_read_lock ();@@ -82,6 +88,45 @@ int dev_pm_opp_init_cpufreq_table(struct device *dev, *table = &freq_table[0 ]; +#ifdef CONFIG_CPU_FREQ_BOOST_SW +if (!of_find_property (dev->of_node,"boost-frequencies" , &len)) + goto out; + +if (!len || !IS_ALIGNED (len,sizeof (u32))) { +dev_err (dev,"%s: invalid boost frequency\n" , __func__); + ret = -EINVAL ; + goto out; + } + + boost_freqs =kmalloc (len,GFP_KERNEL ); +if (!boost_freqs) { +dev_err (dev,"%s: no memory for boost freq table\n" , __func__); + ret = -ENOMEM ; + goto out; + } + + count = len /sizeof (u32); +of_property_read_u32_array (dev->of_node,"boost-frequencies" , + boost_freqs, count); + +for (i =0 ; i < count; i++) { +cpufreq_for_each_valid_entry (ft, *table) { +if (boost_freqs[i] == ft->frequency) { + ft->flags |=CPUFREQ_BOOST_FREQ ; + pr_debug("%s: marked %d as boostfrequency\n",
drivers/cpufreq/cpufreq_opp.c +7
-0+ __func__, boost_freqs[i]); +break ; + } + } + +if (ft->frequency ==CPUFREQ_TABLE_END ) + dev_err(dev, "%s: invalid boost frequency%d\n",
drivers/cpufreq/cpufreq_opp.c int dev_pm_opp_init_cpufreq_table(struct device *dev, · line 132
Quoted 9 lines
drivers/cpufreq/cpufreq_opp.c +6
-0+ __func__, boost_freqs[i]); + } + +kfree (boost_freqs); +#endif + out:rcu_read_unlock ();if (ret)
Thomas, thanks for this patch.
Signature · 5 lines
Best regards, Lukasz Majewski Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
PATCH v5 2/2 Documentation: devicetree: Add boost-frequency binding to list boost mode frequency
In reply to Thomas AbrahamFrom: Thomas Abraham <[email protected]>
Add a new optional boost-frequency binding for specifying the frequencies usable in boost mode.
--- .../devicetree/bindings/cpufreq/cpufreq-boost.txt | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/cpufreq/cpufreq-boost.txt
Documentation/devicetree/bindings/cpufreq/cpufreq-boost.txt new file +38 -0
@@ -0,0 +1,38 @@ +* Device tree binding for CPU boost frequency (aka over-clocking) + +Certain CPU's can be operated in optional 'boost' mode (or sometimes referred as +overclocking) in which the CPU can operate at frequencies which are not +specified by the manufacturer as CPU's operating frequency. + +Optional Properties: +- boost-frequencies: list of frequencies in KHz to be used only in boost mode. + This list should be a subset of frequencies listed in "operating-points" + property. Refer to Documentation/devicetree/bindings/power/opp.txt for + details about "operating-points" property. + +Example: + + cpus { + #address-cells = <1>; + #size-cells = <0>; + cpu at 0 { + device_type = "cpu"; + compatible = "arm,cortex-a9"; + reg = <0>; + + operating-points = < + 1500000 1350000 + 1400000 1287500 + 1300000 1250000 + 1200000 1187500 + 1100000 1137500 + 1000000 1087500 + >; + boost-frequencies = <1500000 1400000>; + }; + cpu at 1 { + device_type = "cpu"; + compatible = "arm,cortex-a9"; + reg = <1>; + }; + };
Signature · 1 line
1.7.9.5
PATCH v5 2/2 Documentation: devicetree: Add boost-frequency binding to list boost mode frequency
Hi Thomas,
Quoted 57 lines
From: Thomas Abraham <[email protected]>
Add a new optional boost-frequency binding for specifying the frequencies usable in boost mode.
Cc Nishanth Menon <[email protected]>Cc Lukasz Majewski <[email protected]>Cc Rob Herring <[email protected]>Cc Pawel Moll <[email protected]>Cc Mark Rutland <[email protected]>Cc Ian Campbell <[email protected]>Cc Kumar Gala <[email protected]>Signed-off-by Thomas Abraham <[email protected]>Acked-by Viresh Kumar <[email protected]>--- .../devicetree/bindings/cpufreq/cpufreq-boost.txt | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644
Documentation/devicetree/bindings/cpufreq/cpufreq-boost.txtdiff --git
a/Documentation/devicetree/bindings/cpufreq/cpufreq-boost.txtb/Documentation/devicetree/bindings/cpufreq/cpufreq-boost.txtnew file mode 100644 index 0000000..63ed0fc ---/dev/null+++b/Documentation/devicetree/bindings/cpufreq/cpufreq-boost.txtDocumentation/devicetree/bindings/cpufreq/cpufreq-boost.txt new file +3
-0@@ -0,0 +1,38 @@ +* Device tree binding for CPU boost frequency (aka over-clocking) + +Certain CPU's can be operated in optional 'boost' mode (or sometimesreferred as +overclocking) in which the CPU can operate at frequencies which are not +specified by the manufacturer as CPU's operating frequency. +
+Optional Properties:
+- boost-frequencies: list of frequencies in KHz to be used only in boost mode.
+ This list should be a subset of frequencies listed in "operating-points"
+ property. Refer toDocumentation/devicetree/bindings/power/opp.txtforDocumentation/devicetree/bindings/cpufreq/cpufreq-boost.txt new file +18
-0+ details about "operating-points" property. + +Example: + + cpus { + #address-cells = <1>; + #size-cells = <0>; + cpu at 0 { + device_type = "cpu"; + compatible = "arm,cortex-a9"; + reg = <0>; + + operating-points = < + 1500000 1350000 + 1400000 1287500 + 1300000 1250000 + 1200000 1187500 + 1100000 1137500
Documentation/devicetree/bindings/cpufreq/cpufreq-boost.txt line 38
Quoted 10 lines
Documentation/devicetree/bindings/cpufreq/cpufreq-boost.txt new file +10
-0+ 1000000 1087500 + >; + boost-frequencies = <1500000 1400000>; + }; + cpu at 1 { + device_type = "cpu"; + compatible = "arm,cortex-a9"; + reg = <1>; + }; + };
Signature · 5 lines
Best regards, Lukasz Majewski Samsung R&D Institute Poland (SRPOL) | Linux Platform Group