Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c36e8ff authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "devfreq: add support to handle device suspend state"

parents 02b56508 aef86b2e
Loading
Loading
Loading
Loading
+3 −19
Original line number Diff line number Diff line
@@ -1070,10 +1070,6 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
	}

	mutex_lock(&df->event_lock);
	if (df->dev_suspended) {
		ret = -EINVAL;
		goto gov_stop_out;
	}
	if (df->governor) {
		ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL);
		if (ret) {
@@ -1187,16 +1183,14 @@ static ssize_t polling_interval_store(struct device *dev,
	unsigned int value;
	int ret;

	if (!df->governor)
		return -EINVAL;

	ret = sscanf(buf, "%u", &value);
	if (ret != 1)
		return -EINVAL;

	mutex_lock(&df->event_lock);
	if (!df->governor || df->dev_suspended) {
		dev_warn(dev, "device suspended, operation not allowed\n");
		mutex_unlock(&df->event_lock);
		return -EINVAL;
	}
	df->governor->event_handler(df, DEVFREQ_GOV_INTERVAL, &value);
	ret = count;
	mutex_unlock(&df->event_lock);
@@ -1217,11 +1211,6 @@ static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr,
		return -EINVAL;

	mutex_lock(&df->event_lock);
	if (df->dev_suspended) {
		dev_warn(dev, "device suspended, min freq not allowed\n");
		mutex_unlock(&df->event_lock);
		return -EINVAL;
	}
	mutex_lock(&df->lock);

	if (value) {
@@ -1268,11 +1257,6 @@ static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr,
		return -EINVAL;

	mutex_lock(&df->event_lock);
	if (df->dev_suspended) {
		mutex_unlock(&df->event_lock);
		dev_warn(dev, "device suspended, max freq not allowed\n");
		return -EINVAL;
	}
	mutex_lock(&df->lock);

	if (value) {
+17 −4
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2013-2018, 2019, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013-2018, 2019-2020, The Linux Foundation. All rights reserved.
 */

#define pr_fmt(fmt) "bw-hwmon: " fmt
@@ -62,6 +62,7 @@ struct hwmon_node {
	ktime_t hist_max_ts;
	bool sampled;
	bool mon_started;
	bool init_pending;
	struct list_head list;
	void *orig_data;
	struct bw_hwmon *hw;
@@ -539,8 +540,15 @@ static int start_monitor(struct devfreq *df, bool init)
	unsigned long mbps;
	int ret;

	node->prev_ts = ktime_get();
	if (init && df->dev_suspended) {
		node->init_pending = true;
		return 0;
	} else if (!init && node->init_pending) {
		init = true;
		node->init_pending = false;
	}

	node->prev_ts = ktime_get();
	if (init) {
		node->prev_ab = 0;
		node->resume_freq = 0;
@@ -580,6 +588,7 @@ static void stop_monitor(struct devfreq *df, bool init)

	if (init) {
		devfreq_monitor_stop(df);
		if (!df->dev_suspended)
			hw->stop_hwmon(hw);
	} else {
		devfreq_monitor_suspend(df);
@@ -705,7 +714,7 @@ static int devfreq_bw_hwmon_get_freq(struct devfreq *df,
	struct hwmon_node *node = df->data;

	/* Suspend/resume sequence */
	if (node && !node->mon_started) {
	if ((node && !node->mon_started) || df->dev_suspended) {
		*freq = node->resume_freq;
		*node->dev_ab = node->resume_ab;
		return 0;
@@ -877,6 +886,10 @@ static int devfreq_bw_hwmon_ev_handler(struct devfreq *df,
		 */
		hw = node->hw;

		if (!node->mon_started || df->dev_suspended) {
			devfreq_interval_update(df, &sample_ms);
			break;
		}
		mutex_lock(&node->mon_lock);
		node->mon_started = false;
		mutex_unlock(&node->mon_lock);