!to_devfreq(dev)->governor->no_central_polling);
}
+static ssize_t store_min_freq(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct devfreq *df = to_devfreq(dev);
+ unsigned long value;
+ int ret;
+ unsigned long max;
+
+ ret = sscanf(buf, "%lu", &value);
+ if (ret != 1)
+ goto out;
+
+ mutex_lock(&df->lock);
+ max = df->max_freq;
+ if (value && max && value > max) {
+ ret = -EINVAL;
+ goto unlock;
+ }
+
+ df->min_freq = value;
+ update_devfreq(df);
+ ret = count;
+unlock:
+ mutex_unlock(&df->lock);
+out:
+ return ret;
+}
+
+static ssize_t show_min_freq(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ return sprintf(buf, "%lu\n", to_devfreq(dev)->min_freq);
+}
+
+static ssize_t store_max_freq(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct devfreq *df = to_devfreq(dev);
+ unsigned long value;
+ int ret;
+ unsigned long min;
+
+ ret = sscanf(buf, "%lu", &value);
+ if (ret != 1)
+ goto out;
+
+ mutex_lock(&df->lock);
+ min = df->min_freq;
+ if (value && min && value < min) {
+ ret = -EINVAL;
+ goto unlock;
+ }
+
+ df->max_freq = value;
+ update_devfreq(df);
+ ret = count;
+unlock:
+ mutex_unlock(&df->lock);
+out:
+ return ret;
+}
+
+static ssize_t show_max_freq(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ return sprintf(buf, "%lu\n", to_devfreq(dev)->max_freq);
+}
+
static struct device_attribute devfreq_attrs[] = {
__ATTR(governor, S_IRUGO, show_governor, NULL),
__ATTR(cur_freq, S_IRUGO, show_freq, NULL),
__ATTR(central_polling, S_IRUGO, show_central_polling, NULL),
__ATTR(polling_interval, S_IRUGO | S_IWUSR, show_polling_interval,
store_polling_interval),
+ __ATTR(min_freq, S_IRUGO | S_IWUSR, show_min_freq, store_min_freq),
+ __ATTR(max_freq, S_IRUGO | S_IWUSR, show_max_freq, store_max_freq),
{ },
};
unsigned int dfso_upthreshold = DFSO_UPTHRESHOLD;
unsigned int dfso_downdifferential = DFSO_DOWNDIFFERENCTIAL;
struct devfreq_simple_ondemand_data *data = df->data;
+ unsigned long max = (df->max_freq) ? df->max_freq : UINT_MAX;
if (err)
return err;
/* Assume MAX if it is going to be divided by zero */
if (stat.total_time == 0) {
- *freq = UINT_MAX;
+ *freq = max;
return 0;
}
/* Set MAX if it's busy enough */
if (stat.busy_time * 100 >
stat.total_time * dfso_upthreshold) {
- *freq = UINT_MAX;
+ *freq = max;
return 0;
}
/* Set MAX if we do not know the initial frequency */
if (stat.current_frequency == 0) {
- *freq = UINT_MAX;
+ *freq = max;
return 0;
}
b = div_u64(b, (dfso_upthreshold - dfso_downdifferential / 2));
*freq = (unsigned long) b;
+ if (df->min_freq && *freq < df->min_freq)
+ *freq = df->min_freq;
+ if (df->max_freq && *freq > df->max_freq)
+ *freq = df->max_freq;
+
return 0;
}
{
struct userspace_data *data = df->data;
- if (!data->valid)
+ if (data->valid) {
+ unsigned long adjusted_freq = data->user_frequency;
+
+ if (df->max_freq && adjusted_freq > df->max_freq)
+ adjusted_freq = df->max_freq;
+
+ if (df->min_freq && adjusted_freq < df->min_freq)
+ adjusted_freq = df->min_freq;
+
+ *freq = adjusted_freq;
+ } else {
*freq = df->previous_freq; /* No user freq specified yet */
- else
- *freq = data->user_frequency;
+ }
return 0;
}
* touch this.
* @being_removed a flag to mark that this object is being removed in
* order to prevent trying to remove the object multiple times.
+ * @min_freq Limit minimum frequency requested by user (0: none)
+ * @max_freq Limit maximum frequency requested by user (0: none)
*
* This structure stores the devfreq information for a give device.
*
void *data; /* private data for governors */
bool being_removed;
+
+ unsigned long min_freq;
+ unsigned long max_freq;
};
#if defined(CONFIG_PM_DEVFREQ)