summaryrefslogtreecommitdiff
path: root/drivers/cpufreq/cpufreq.c
diff options
context:
space:
mode:
authorLukasz Majewski <l.majewski@samsung.com>2013-07-19 13:33:13 +0200
committerChanho Park <chanho61.park@samsung.com>2014-11-18 11:45:03 +0900
commitf59b635ea9c767fb7bcd77e13e29cce4be96cc7c (patch)
treedac68c5cc0e9f40824def1ad6d1cfd88a7dbe2a0 /drivers/cpufreq/cpufreq.c
parent712466001bbac86602ae072e94f96389a7f95ef5 (diff)
downloadlinux-3.10-f59b635ea9c767fb7bcd77e13e29cce4be96cc7c.tar.gz
linux-3.10-f59b635ea9c767fb7bcd77e13e29cce4be96cc7c.tar.bz2
linux-3.10-f59b635ea9c767fb7bcd77e13e29cce4be96cc7c.zip
cpufreq: Add boost frequency support in core
This commit adds boost frequency support in cpufreq core (Hardware & Software). Some SoC (like Exynos4 - e.g. 4x12) allow setting frequency above its normal operation limits. Such a mode shall be only used for a short time. Overclocking (boost) support is essentially provided by platform dependent cpufreq driver. This commit unifies support for SW and HW (Intel) overclocking solutions in the core cpufreq driver. Previously the "boost" sysfs attribute was defined at acpi driver code. By default boost is disabled. One global attribute is available at: /sys/devices/system/cpu/cpufreq/boost. It only shows up when cpufreq driver supports overclocking. Under the hood frequencies dedicated for boosting are marked with a special flag (CPUFREQ_BOOST_FREQ) at driver's frequency table. It is the user's concern to enable/disable overclocking with proper call to sysfs. Signed-off-by: Lukasz Majewski <l.majewski@samsung.com> Signed-off-by: Myungjoo Ham <myungjoo.ham@samsung.com> Changes for v6: - Remove sysfs boost attribute when subsys_iterface_unregister() fails - Move global boost_enabled variable from cpufreq.c to platform dependent struct cpufreq_driver - pr_err() message is also printed when boost disable fails Changes for v5: - Rename cpufreq_boost_trigger_state_sw() to cpufreq_boost_enable_sw() - Extent cpufreq_register_driver() to check if cpufreq driver provided boost_enable callback. If not provided, then use cpufreq_boost_enable_sw() - Use single call to cpufreq_driver->enable_boost() with cpufreq driver provided callback or default SW boost enable routine - Move pr_debug call to store_boost() from cpufreq_boost_trigger_state() - Change the user_policy.max value when SW boost is toggled. It is necessary for proper operation of e.g. thermal subsystem. - Add check if cpufreq_driver pointer is not NULL at cpufreq_boost_supported() routine - Add EXPORT_SYMBOL_GPL for cpufreq_boost_supported() and cpufreq_boost_enabled() - Remove extra check for cpufreq_boost_supported() at cpufreq_freq_table_cpuinfo() - Explanation of show boost logic at show_available_freqs() - Add cpufreq_set_boost_enabled() method to set initial value of boost_enabled global flag Changes for v4: - Remove boost parameter from cpufreq_frequency_table_cpuinfo() function - Introduce cpufreq_boost_supported() method - Use of cpufreq_boost_supported() and cpufreq_boost_enabled() to decide if frequency shall be skipped - Rename set_boost_freq() to enable_boost() - cpufreq_attr_available_freq() moved to freq_table.c - Use policy list to get access to cpufreq policies - Rename global boost flag (cpufreq_boost_enabled -> boost_enabled) - pr_err corrected ( %sable) - Remove sanity check at cpufreq_boost_trigger_state() entrance [to test if boost is supported] - Use either HW (boost_enable) callback or SW managed boost - Introduce new cpufreq_boost_trigger_state_sw() method to handle boost at SW. - Protect boost_enabled manipulation with lock. Changes for v3: - Method for reading boost status - Removal of cpufreq_frequency_table_max() - Extent cpufreq_frequency_table_cpuinfo() to support boost parameter - boost_supported flag added to cpufreq_driver struct - "boost" sysfs attribute control flag removed - One global flag describing state of the boost defined at cpufreq core - Rename cpufreq_driver's low_level_boost field to set_boost_freq() - Usage of cpufreq_sysfs_{remove|add}_file() routines Changes for v2: - Removal of cpufreq_boost structure and move its fields to cpufreq_driver structure - Flag to indicate if global boost attribute is already defined - Extent the pr_{err|debbug} functions to show current function names
Diffstat (limited to 'drivers/cpufreq/cpufreq.c')
-rw-r--r--drivers/cpufreq/cpufreq.c110
1 files changed, 109 insertions, 1 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 7a64d8b95c5..eb57f0ccd88 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -317,6 +317,32 @@ EXPORT_SYMBOL_GPL(cpufreq_notify_transition);
/*********************************************************************
* SYSFS INTERFACE *
*********************************************************************/
+ssize_t show_boost(struct kobject *kobj,
+ struct attribute *attr, char *buf)
+{
+ return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled);
+}
+
+static ssize_t store_boost(struct kobject *kobj, struct attribute *attr,
+ const char *buf, size_t count)
+{
+ int ret, enable;
+
+ ret = sscanf(buf, "%d", &enable);
+ if (ret != 1 || enable < 0 || enable > 1)
+ return -EINVAL;
+
+ if (cpufreq_boost_trigger_state(enable)) {
+ pr_err("%s: Cannot enable boost!\n", __func__);
+ return -EINVAL;
+ }
+
+ pr_debug("%s: cpufreq BOOST %s\n", __func__,
+ enable ? "enabled" : "disabled");
+
+ return count;
+}
+define_one_global_rw(boost);
static struct cpufreq_governor *__find_governor(const char *str_governor)
{
@@ -1926,6 +1952,66 @@ static struct notifier_block __refdata cpufreq_cpu_notifier = {
};
/*********************************************************************
+ * BOOST *
+ *********************************************************************/
+static int cpufreq_boost_enable_sw(int state)
+{
+ struct cpufreq_frequency_table *freq_table;
+ struct cpufreq_policy *policy;
+ int ret = -EINVAL;
+
+ list_for_each_entry(policy, &cpufreq_policy_list, policy_list) {
+ freq_table = cpufreq_frequency_get_table(policy->cpu);
+ if (freq_table) {
+ ret = cpufreq_frequency_table_cpuinfo(policy,
+ freq_table);
+ if (!ret)
+ policy->user_policy.max = policy->max;
+ }
+ }
+
+ return ret;
+}
+
+int cpufreq_boost_trigger_state(int state)
+{
+ unsigned long flags;
+ int ret = 0;
+
+ if (cpufreq_driver->boost_enabled != state) {
+ write_lock_irqsave(&cpufreq_driver_lock, flags);
+ cpufreq_driver->boost_enabled = state;
+
+ ret = cpufreq_driver->enable_boost(state);
+ if (ret)
+ cpufreq_driver->boost_enabled = 0;
+
+ write_unlock_irqrestore(&cpufreq_driver_lock, flags);
+
+ if (ret)
+ pr_err("%s: BOOST cannot %s\n", __func__,
+ state ? "enabled" : "disabled");
+ }
+
+ return ret;
+}
+
+int cpufreq_boost_supported(void)
+{
+ if (cpufreq_driver)
+ return cpufreq_driver->boost_supported;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(cpufreq_boost_supported);
+
+int cpufreq_boost_enabled(void)
+{
+ return cpufreq_driver->boost_enabled;
+}
+EXPORT_SYMBOL_GPL(cpufreq_boost_enabled);
+
+/*********************************************************************
* REGISTER / UNREGISTER CPUFREQ DRIVER *
*********************************************************************/
@@ -1964,9 +2050,25 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
cpufreq_driver = driver_data;
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
+ if (cpufreq_driver->boost_supported) {
+ /*
+ * Check if boost driver provides function to enable boost -
+ * if not, use cpufreq_boost_enable_sw as default
+ */
+ if (!cpufreq_driver->enable_boost)
+ cpufreq_driver->enable_boost = cpufreq_boost_enable_sw;
+
+ ret = cpufreq_sysfs_create_file(&(boost.attr));
+ if (ret) {
+ pr_err("%s: cannot register global boost sysfs file\n",
+ __func__);
+ goto err_null_driver;
+ }
+ }
+
ret = subsys_interface_register(&cpufreq_interface);
if (ret)
- goto err_null_driver;
+ goto err_boost_unreg;
if (!(cpufreq_driver->flags & CPUFREQ_STICKY)) {
int i;
@@ -1993,6 +2095,9 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
return 0;
err_if_unreg:
subsys_interface_unregister(&cpufreq_interface);
+err_boost_unreg:
+ if (cpufreq_driver->boost_supported)
+ cpufreq_sysfs_remove_file(&(boost.attr));
err_null_driver:
write_lock_irqsave(&cpufreq_driver_lock, flags);
cpufreq_driver = NULL;
@@ -2020,6 +2125,9 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver)
pr_debug("unregistering driver %s\n", driver->name);
subsys_interface_unregister(&cpufreq_interface);
+ if (cpufreq_driver->boost_supported)
+ cpufreq_sysfs_remove_file(&(boost.attr));
+
unregister_hotcpu_notifier(&cpufreq_cpu_notifier);
write_lock_irqsave(&cpufreq_driver_lock, flags);