Commit 82a1faa9 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

Merge tag 'pullreq_20171026' of...

Merge tag 'pullreq_20171026' of https://git.kernel.org/pub/scm/linux/kernel/git/mzx/devfreq into pm-devfreq

Pull devfreq changes for v4.15 from MyungJoo Ham.

* tag 'pullreq_20171026' of https://git.kernel.org/pub/scm/linux/kernel/git/mzx/devfreq:
  PM / devfreq: Define the constant governor name
  PM / devfreq: Remove unneeded conditional statement
  PM / devfreq: Show the all available frequencies
  PM / devfreq: Change return type of devfreq_set_freq_table()
  PM / devfreq: Use the available min/max frequency
  Revert "PM / devfreq: Add show_one macro to delete the duplicate code"
  PM / devfreq: Set min/max_freq when adding the devfreq device
parents 0b07194b aa7c352f
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
#include <linux/of.h> #include <linux/of.h>
#include "governor.h" #include "governor.h"
#define MAX(a,b) ((a > b) ? a : b)
#define MIN(a,b) ((a < b) ? a : b)
static struct class *devfreq_class; static struct class *devfreq_class;
/* /*
...@@ -69,6 +72,34 @@ static struct devfreq *find_device_devfreq(struct device *dev) ...@@ -69,6 +72,34 @@ static struct devfreq *find_device_devfreq(struct device *dev)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
} }
static unsigned long find_available_min_freq(struct devfreq *devfreq)
{
struct dev_pm_opp *opp;
unsigned long min_freq = 0;
opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &min_freq);
if (IS_ERR(opp))
min_freq = 0;
else
dev_pm_opp_put(opp);
return min_freq;
}
static unsigned long find_available_max_freq(struct devfreq *devfreq)
{
struct dev_pm_opp *opp;
unsigned long max_freq = ULONG_MAX;
opp = dev_pm_opp_find_freq_floor(devfreq->dev.parent, &max_freq);
if (IS_ERR(opp))
max_freq = 0;
else
dev_pm_opp_put(opp);
return max_freq;
}
/** /**
* devfreq_get_freq_level() - Lookup freq_table for the frequency * devfreq_get_freq_level() - Lookup freq_table for the frequency
* @devfreq: the devfreq instance * @devfreq: the devfreq instance
...@@ -85,11 +116,7 @@ static int devfreq_get_freq_level(struct devfreq *devfreq, unsigned long freq) ...@@ -85,11 +116,7 @@ static int devfreq_get_freq_level(struct devfreq *devfreq, unsigned long freq)
return -EINVAL; return -EINVAL;
} }
/** static int set_freq_table(struct devfreq *devfreq)
* devfreq_set_freq_table() - Initialize freq_table for the frequency
* @devfreq: the devfreq instance
*/
static void devfreq_set_freq_table(struct devfreq *devfreq)
{ {
struct devfreq_dev_profile *profile = devfreq->profile; struct devfreq_dev_profile *profile = devfreq->profile;
struct dev_pm_opp *opp; struct dev_pm_opp *opp;
...@@ -99,7 +126,7 @@ static void devfreq_set_freq_table(struct devfreq *devfreq) ...@@ -99,7 +126,7 @@ static void devfreq_set_freq_table(struct devfreq *devfreq)
/* Initialize the freq_table from OPP table */ /* Initialize the freq_table from OPP table */
count = dev_pm_opp_get_opp_count(devfreq->dev.parent); count = dev_pm_opp_get_opp_count(devfreq->dev.parent);
if (count <= 0) if (count <= 0)
return; return -EINVAL;
profile->max_state = count; profile->max_state = count;
profile->freq_table = devm_kcalloc(devfreq->dev.parent, profile->freq_table = devm_kcalloc(devfreq->dev.parent,
...@@ -108,7 +135,7 @@ static void devfreq_set_freq_table(struct devfreq *devfreq) ...@@ -108,7 +135,7 @@ static void devfreq_set_freq_table(struct devfreq *devfreq)
GFP_KERNEL); GFP_KERNEL);
if (!profile->freq_table) { if (!profile->freq_table) {
profile->max_state = 0; profile->max_state = 0;
return; return -ENOMEM;
} }
for (i = 0, freq = 0; i < profile->max_state; i++, freq++) { for (i = 0, freq = 0; i < profile->max_state; i++, freq++) {
...@@ -116,11 +143,13 @@ static void devfreq_set_freq_table(struct devfreq *devfreq) ...@@ -116,11 +143,13 @@ static void devfreq_set_freq_table(struct devfreq *devfreq)
if (IS_ERR(opp)) { if (IS_ERR(opp)) {
devm_kfree(devfreq->dev.parent, profile->freq_table); devm_kfree(devfreq->dev.parent, profile->freq_table);
profile->max_state = 0; profile->max_state = 0;
return; return PTR_ERR(opp);
} }
dev_pm_opp_put(opp); dev_pm_opp_put(opp);
profile->freq_table[i] = freq; profile->freq_table[i] = freq;
} }
return 0;
} }
/** /**
...@@ -227,7 +256,7 @@ static int devfreq_notify_transition(struct devfreq *devfreq, ...@@ -227,7 +256,7 @@ static int devfreq_notify_transition(struct devfreq *devfreq,
int update_devfreq(struct devfreq *devfreq) int update_devfreq(struct devfreq *devfreq)
{ {
struct devfreq_freqs freqs; struct devfreq_freqs freqs;
unsigned long freq, cur_freq; unsigned long freq, cur_freq, min_freq, max_freq;
int err = 0; int err = 0;
u32 flags = 0; u32 flags = 0;
...@@ -245,19 +274,21 @@ int update_devfreq(struct devfreq *devfreq) ...@@ -245,19 +274,21 @@ int update_devfreq(struct devfreq *devfreq)
return err; return err;
/* /*
* Adjust the frequency with user freq and QoS. * Adjust the frequency with user freq, QoS and available freq.
* *
* List from the highest priority * List from the highest priority
* max_freq * max_freq
* min_freq * min_freq
*/ */
max_freq = MIN(devfreq->scaling_max_freq, devfreq->max_freq);
min_freq = MAX(devfreq->scaling_min_freq, devfreq->min_freq);
if (devfreq->min_freq && freq < devfreq->min_freq) { if (min_freq && freq < min_freq) {
freq = devfreq->min_freq; freq = min_freq;
flags &= ~DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use GLB */ flags &= ~DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use GLB */
} }
if (devfreq->max_freq && freq > devfreq->max_freq) { if (max_freq && freq > max_freq) {
freq = devfreq->max_freq; freq = max_freq;
flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */ flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */
} }
...@@ -280,10 +311,9 @@ int update_devfreq(struct devfreq *devfreq) ...@@ -280,10 +311,9 @@ int update_devfreq(struct devfreq *devfreq)
freqs.new = freq; freqs.new = freq;
devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE); devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE);
if (devfreq->profile->freq_table) if (devfreq_update_status(devfreq, freq))
if (devfreq_update_status(devfreq, freq)) dev_err(&devfreq->dev,
dev_err(&devfreq->dev, "Couldn't update frequency transition information.\n");
"Couldn't update frequency transition information.\n");
devfreq->previous_freq = freq; devfreq->previous_freq = freq;
return err; return err;
...@@ -466,6 +496,19 @@ static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type, ...@@ -466,6 +496,19 @@ static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type,
int ret; int ret;
mutex_lock(&devfreq->lock); mutex_lock(&devfreq->lock);
devfreq->scaling_min_freq = find_available_min_freq(devfreq);
if (!devfreq->scaling_min_freq) {
mutex_unlock(&devfreq->lock);
return -EINVAL;
}
devfreq->scaling_max_freq = find_available_max_freq(devfreq);
if (!devfreq->scaling_max_freq) {
mutex_unlock(&devfreq->lock);
return -EINVAL;
}
ret = update_devfreq(devfreq); ret = update_devfreq(devfreq);
mutex_unlock(&devfreq->lock); mutex_unlock(&devfreq->lock);
...@@ -555,10 +598,28 @@ struct devfreq *devfreq_add_device(struct device *dev, ...@@ -555,10 +598,28 @@ struct devfreq *devfreq_add_device(struct device *dev,
if (!devfreq->profile->max_state && !devfreq->profile->freq_table) { if (!devfreq->profile->max_state && !devfreq->profile->freq_table) {
mutex_unlock(&devfreq->lock); mutex_unlock(&devfreq->lock);
devfreq_set_freq_table(devfreq); err = set_freq_table(devfreq);
if (err < 0)
goto err_out;
mutex_lock(&devfreq->lock); mutex_lock(&devfreq->lock);
} }
devfreq->min_freq = find_available_min_freq(devfreq);
if (!devfreq->min_freq) {
mutex_unlock(&devfreq->lock);
err = -EINVAL;
goto err_dev;
}
devfreq->scaling_min_freq = devfreq->min_freq;
devfreq->max_freq = find_available_max_freq(devfreq);
if (!devfreq->max_freq) {
mutex_unlock(&devfreq->lock);
err = -EINVAL;
goto err_dev;
}
devfreq->scaling_max_freq = devfreq->max_freq;
dev_set_name(&devfreq->dev, "devfreq%d", dev_set_name(&devfreq->dev, "devfreq%d",
atomic_inc_return(&devfreq_no)); atomic_inc_return(&devfreq_no));
err = device_register(&devfreq->dev); err = device_register(&devfreq->dev);
...@@ -1082,6 +1143,14 @@ static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr, ...@@ -1082,6 +1143,14 @@ static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr,
return ret; return ret;
} }
static ssize_t min_freq_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct devfreq *df = to_devfreq(dev);
return sprintf(buf, "%lu\n", MAX(df->scaling_min_freq, df->min_freq));
}
static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr, static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
...@@ -1108,17 +1177,15 @@ static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr, ...@@ -1108,17 +1177,15 @@ static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr,
mutex_unlock(&df->lock); mutex_unlock(&df->lock);
return ret; return ret;
} }
static DEVICE_ATTR_RW(min_freq);
#define show_one(name) \ static ssize_t max_freq_show(struct device *dev, struct device_attribute *attr,
static ssize_t name##_show \ char *buf)
(struct device *dev, struct device_attribute *attr, char *buf) \ {
{ \ struct devfreq *df = to_devfreq(dev);
return sprintf(buf, "%lu\n", to_devfreq(dev)->name); \
}
show_one(min_freq);
show_one(max_freq);
static DEVICE_ATTR_RW(min_freq); return sprintf(buf, "%lu\n", MIN(df->scaling_max_freq, df->max_freq));
}
static DEVICE_ATTR_RW(max_freq); static DEVICE_ATTR_RW(max_freq);
static ssize_t available_frequencies_show(struct device *d, static ssize_t available_frequencies_show(struct device *d,
...@@ -1126,22 +1193,16 @@ static ssize_t available_frequencies_show(struct device *d, ...@@ -1126,22 +1193,16 @@ static ssize_t available_frequencies_show(struct device *d,
char *buf) char *buf)
{ {
struct devfreq *df = to_devfreq(d); struct devfreq *df = to_devfreq(d);
struct device *dev = df->dev.parent;
struct dev_pm_opp *opp;
ssize_t count = 0; ssize_t count = 0;
unsigned long freq = 0; int i;
do { mutex_lock(&df->lock);
opp = dev_pm_opp_find_freq_ceil(dev, &freq);
if (IS_ERR(opp))
break;
dev_pm_opp_put(opp); for (i = 0; i < df->profile->max_state; i++)
count += scnprintf(&buf[count], (PAGE_SIZE - count - 2), count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
"%lu ", freq); "%lu ", df->profile->freq_table[i]);
freq++;
} while (1);
mutex_unlock(&df->lock);
/* Truncate the trailing space */ /* Truncate the trailing space */
if (count) if (count)
count--; count--;
......
...@@ -436,7 +436,8 @@ static int exynos_bus_probe(struct platform_device *pdev) ...@@ -436,7 +436,8 @@ static int exynos_bus_probe(struct platform_device *pdev)
ondemand_data->downdifferential = 5; ondemand_data->downdifferential = 5;
/* Add devfreq device to monitor and handle the exynos bus */ /* Add devfreq device to monitor and handle the exynos bus */
bus->devfreq = devm_devfreq_add_device(dev, profile, "simple_ondemand", bus->devfreq = devm_devfreq_add_device(dev, profile,
DEVFREQ_GOV_SIMPLE_ONDEMAND,
ondemand_data); ondemand_data);
if (IS_ERR(bus->devfreq)) { if (IS_ERR(bus->devfreq)) {
dev_err(dev, "failed to add devfreq device\n"); dev_err(dev, "failed to add devfreq device\n");
...@@ -488,7 +489,7 @@ static int exynos_bus_probe(struct platform_device *pdev) ...@@ -488,7 +489,7 @@ static int exynos_bus_probe(struct platform_device *pdev)
passive_data->parent = parent_devfreq; passive_data->parent = parent_devfreq;
/* Add devfreq device for exynos bus with passive governor */ /* Add devfreq device for exynos bus with passive governor */
bus->devfreq = devm_devfreq_add_device(dev, profile, "passive", bus->devfreq = devm_devfreq_add_device(dev, profile, DEVFREQ_GOV_PASSIVE,
passive_data); passive_data);
if (IS_ERR(bus->devfreq)) { if (IS_ERR(bus->devfreq)) {
dev_err(dev, dev_err(dev,
......
...@@ -183,7 +183,7 @@ static int devfreq_passive_event_handler(struct devfreq *devfreq, ...@@ -183,7 +183,7 @@ static int devfreq_passive_event_handler(struct devfreq *devfreq,
} }
static struct devfreq_governor devfreq_passive = { static struct devfreq_governor devfreq_passive = {
.name = "passive", .name = DEVFREQ_GOV_PASSIVE,
.immutable = 1, .immutable = 1,
.get_target_freq = devfreq_passive_get_target_freq, .get_target_freq = devfreq_passive_get_target_freq,
.event_handler = devfreq_passive_event_handler, .event_handler = devfreq_passive_event_handler,
......
...@@ -42,7 +42,7 @@ static int devfreq_performance_handler(struct devfreq *devfreq, ...@@ -42,7 +42,7 @@ static int devfreq_performance_handler(struct devfreq *devfreq,
} }
static struct devfreq_governor devfreq_performance = { static struct devfreq_governor devfreq_performance = {
.name = "performance", .name = DEVFREQ_GOV_PERFORMANCE,
.get_target_freq = devfreq_performance_func, .get_target_freq = devfreq_performance_func,
.event_handler = devfreq_performance_handler, .event_handler = devfreq_performance_handler,
}; };
......
...@@ -39,7 +39,7 @@ static int devfreq_powersave_handler(struct devfreq *devfreq, ...@@ -39,7 +39,7 @@ static int devfreq_powersave_handler(struct devfreq *devfreq,
} }
static struct devfreq_governor devfreq_powersave = { static struct devfreq_governor devfreq_powersave = {
.name = "powersave", .name = DEVFREQ_GOV_POWERSAVE,
.get_target_freq = devfreq_powersave_func, .get_target_freq = devfreq_powersave_func,
.event_handler = devfreq_powersave_handler, .event_handler = devfreq_powersave_handler,
}; };
......
...@@ -125,7 +125,7 @@ static int devfreq_simple_ondemand_handler(struct devfreq *devfreq, ...@@ -125,7 +125,7 @@ static int devfreq_simple_ondemand_handler(struct devfreq *devfreq,
} }
static struct devfreq_governor devfreq_simple_ondemand = { static struct devfreq_governor devfreq_simple_ondemand = {
.name = "simple_ondemand", .name = DEVFREQ_GOV_SIMPLE_ONDEMAND,
.get_target_freq = devfreq_simple_ondemand_func, .get_target_freq = devfreq_simple_ondemand_func,
.event_handler = devfreq_simple_ondemand_handler, .event_handler = devfreq_simple_ondemand_handler,
}; };
......
...@@ -87,7 +87,7 @@ static struct attribute *dev_entries[] = { ...@@ -87,7 +87,7 @@ static struct attribute *dev_entries[] = {
NULL, NULL,
}; };
static const struct attribute_group dev_attr_group = { static const struct attribute_group dev_attr_group = {
.name = "userspace", .name = DEVFREQ_GOV_USERSPACE,
.attrs = dev_entries, .attrs = dev_entries,
}; };
......
...@@ -431,7 +431,7 @@ static int rk3399_dmcfreq_probe(struct platform_device *pdev) ...@@ -431,7 +431,7 @@ static int rk3399_dmcfreq_probe(struct platform_device *pdev)
data->devfreq = devm_devfreq_add_device(dev, data->devfreq = devm_devfreq_add_device(dev,
&rk3399_devfreq_dmc_profile, &rk3399_devfreq_dmc_profile,
"simple_ondemand", DEVFREQ_GOV_SIMPLE_ONDEMAND,
&data->ondemand_data); &data->ondemand_data);
if (IS_ERR(data->devfreq)) if (IS_ERR(data->devfreq))
return PTR_ERR(data->devfreq); return PTR_ERR(data->devfreq);
......
...@@ -19,6 +19,13 @@ ...@@ -19,6 +19,13 @@
#define DEVFREQ_NAME_LEN 16 #define DEVFREQ_NAME_LEN 16
/* DEVFREQ governor name */
#define DEVFREQ_GOV_SIMPLE_ONDEMAND "simple_ondemand"
#define DEVFREQ_GOV_PERFORMANCE "performance"
#define DEVFREQ_GOV_POWERSAVE "powersave"
#define DEVFREQ_GOV_USERSPACE "userspace"
#define DEVFREQ_GOV_PASSIVE "passive"
/* DEVFREQ notifier interface */ /* DEVFREQ notifier interface */
#define DEVFREQ_TRANSITION_NOTIFIER (0) #define DEVFREQ_TRANSITION_NOTIFIER (0)
...@@ -84,8 +91,9 @@ struct devfreq_dev_status { ...@@ -84,8 +91,9 @@ struct devfreq_dev_status {
* from devfreq_remove_device() call. If the user * from devfreq_remove_device() call. If the user
* has registered devfreq->nb at a notifier-head, * has registered devfreq->nb at a notifier-head,
* this is the time to unregister it. * this is the time to unregister it.
* @freq_table: Optional list of frequencies to support statistics. * @freq_table: Optional list of frequencies to support statistics
* @max_state: The size of freq_table. * and freq_table must be generated in ascending order.
* @max_state: The size of freq_table.
*/ */
struct devfreq_dev_profile { struct devfreq_dev_profile {
unsigned long initial_freq; unsigned long initial_freq;
...@@ -120,6 +128,8 @@ struct devfreq_dev_profile { ...@@ -120,6 +128,8 @@ struct devfreq_dev_profile {
* touch this. * touch this.
* @min_freq: Limit minimum frequency requested by user (0: none) * @min_freq: Limit minimum frequency requested by user (0: none)
* @max_freq: Limit maximum frequency requested by user (0: none) * @max_freq: Limit maximum frequency requested by user (0: none)
* @scaling_min_freq: Limit minimum frequency requested by OPP interface
* @scaling_max_freq: Limit maximum frequency requested by OPP interface
* @stop_polling: devfreq polling status of a device. * @stop_polling: devfreq polling status of a device.
* @total_trans: Number of devfreq transitions * @total_trans: Number of devfreq transitions
* @trans_table: Statistics of devfreq transitions * @trans_table: Statistics of devfreq transitions
...@@ -153,6 +163,8 @@ struct devfreq { ...@@ -153,6 +163,8 @@ struct devfreq {
unsigned long min_freq; unsigned long min_freq;
unsigned long max_freq; unsigned long max_freq;
unsigned long scaling_min_freq;
unsigned long scaling_max_freq;
bool stop_polling; bool stop_polling;
/* information for device frequency transition */ /* information for device frequency transition */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment