@@ -768,6 +768,48 @@ err_out:
}
EXPORT_SYMBOL(devfreq_remove_governor);
+int devfreq_set_max(struct devfreq *df, unsigned long value)
+{
+ unsigned long min;
+ int ret = 0;
+
+ mutex_lock(&df->lock);
+ min = df->min_freq;
+ if (value && min && value < min) {
+ ret = -EINVAL;
+ goto unlock;
+ }
+
+ df->max_freq = value;
+ update_devfreq(df);
+unlock:
+ mutex_unlock(&df->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL(devfreq_set_max);
+
+int devfreq_set_min(struct devfreq *df, unsigned long value)
+{
+ unsigned long max;
+ int ret = 0;
+
+ mutex_lock(&df->lock);
+ max = df->max_freq;
+ if (value && max && value > max) {
+ ret = -EINVAL;
+ goto unlock;
+ }
+
+ df->min_freq = value;
+ update_devfreq(df);
+unlock:
+ mutex_unlock(&df->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL(devfreq_set_min);
+
static ssize_t governor_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -899,24 +941,15 @@ static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr,
struct devfreq *df = to_devfreq(dev);
unsigned long value;
int ret;
- unsigned long max;
ret = sscanf(buf, "%lu", &value);
if (ret != 1)
return -EINVAL;
- mutex_lock(&df->lock);
- max = df->max_freq;
- if (value && max && value > max) {
- ret = -EINVAL;
- goto unlock;
- }
+ ret = devfreq_set_min(df, value);
+ if (!ret)
+ ret = count;
- df->min_freq = value;
- update_devfreq(df);
- ret = count;
-unlock:
- mutex_unlock(&df->lock);
return ret;
}
@@ -932,24 +965,15 @@ static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr,
struct devfreq *df = to_devfreq(dev);
unsigned long value;
int ret;
- unsigned long min;
ret = sscanf(buf, "%lu", &value);
if (ret != 1)
return -EINVAL;
- mutex_lock(&df->lock);
- min = df->min_freq;
- if (value && min && value < min) {
- ret = -EINVAL;
- goto unlock;
- }
+ ret = devfreq_set_max(df, value);
+ if (!ret)
+ ret = count;
- df->max_freq = value;
- update_devfreq(df);
- ret = count;
-unlock:
- mutex_unlock(&df->lock);
return ret;
}
static DEVICE_ATTR_RW(min_freq);
@@ -204,6 +204,9 @@ extern int devm_devfreq_register_opp_notifier(struct device *dev,
extern void devm_devfreq_unregister_opp_notifier(struct device *dev,
struct devfreq *devfreq);
+int devfreq_set_min(struct devfreq *df, unsigned long value);
+int devfreq_set_max(struct devfreq *df, unsigned long value);
+
#if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND)
/**
* struct devfreq_simple_ondemand_data - void *data fed to struct devfreq
@@ -289,6 +292,16 @@ static inline void devm_devfreq_unregister_opp_notifier(struct device *dev,
struct devfreq *devfreq)
{
}
+
+static inline int devfreq_set_min(struct devfreq *df, unsigned long value)
+{
+ return -EINVAL;
+}
+
+static inline int devfreq_set_max(struct devfreq *df, unsigned long value)
+{
+ return -EINVAL;
+}
#endif /* CONFIG_PM_DEVFREQ */
#endif /* __LINUX_DEVFREQ_H__ */