@@ -64,6 +64,8 @@ struct devfreq_cooling_device {
struct em_perf_domain *em_pd;
};
+static int get_perf_idx(struct em_perf_domain *em_pd, unsigned long freq);
+
static int devfreq_cooling_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
@@ -74,6 +76,36 @@ static int devfreq_cooling_get_max_state(struct thermal_cooling_device *cdev,
return 0;
}
+static int
+devfreq_cooling_get_user_min_state(struct thermal_cooling_device *cdev,
+ unsigned long *state)
+{
+ struct devfreq_cooling_device *dfc = cdev->devdata;
+ struct devfreq *df = dfc->devfreq;
+ struct device *dev = df->dev.parent;
+ struct dev_pm_opp *opp;
+ unsigned long freq;
+ int ret;
+
+ mutex_lock(&df->lock);
+ freq = df->user_max_freq;
+ mutex_unlock(&df->lock);
+
+ opp = dev_pm_opp_find_freq_floor(dev, &freq);
+ if (IS_ERR(opp))
+ return -EINVAL;
+
+ dev_pm_opp_put(opp);
+
+ ret = get_perf_idx(dfc->em_pd, freq / 1000);
+ if (ret < 0)
+ return -EINVAL;
+
+ *state = dfc->max_state - ret;
+
+ return 0;
+}
+
static int devfreq_cooling_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
@@ -297,6 +329,7 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev,
static struct thermal_cooling_device_ops devfreq_cooling_ops = {
.get_max_state = devfreq_cooling_get_max_state,
+ .get_user_min_state = devfreq_cooling_get_user_min_state,
.get_cur_state = devfreq_cooling_get_cur_state,
.set_cur_state = devfreq_cooling_set_cur_state,
};
@@ -82,6 +82,7 @@ struct thermal_zone_device_ops {
struct thermal_cooling_device_ops {
int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
+ int (*get_user_min_state) (struct thermal_cooling_device *, unsigned long *);
int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
int (*get_requested_power)(struct thermal_cooling_device *, u32 *);
User can limit the maximum frequency of the device via sysfs interface. It limits also corresponding maximum allowed power consumption. The IPA governor needs to know maximum power of the device to split the budget. If the user limit is not provided, some power is wasted while it could be added to other capable device. This new callback helps to solve such scenario. Signed-off-by: Lukasz Luba <lukasz.luba@arm.com> --- drivers/thermal/devfreq_cooling.c | 33 +++++++++++++++++++++++++++++++ include/linux/thermal.h | 1 + 2 files changed, 34 insertions(+)