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

Commit aef86b2e authored by Santosh Mardi's avatar Santosh Mardi
Browse files

devfreq: add support to handle device suspend state



bwmon governor does not differentiate with device
suspend / resume state of the device, there will
be a requirement with some bw monitor device,
to not access it's register space when device is
in suspend state.

Avoid accessing bw monitor register space when
the device is in suspend state, add device suspend
state intelligence in bwmon governor.

Change-Id: Iba6e0475809b663fbd4c3d56fc086bf4c93c164d
Signed-off-by: default avatarSantosh Mardi <gsantosh@codeaurora.org>
parent b451f2e9
Loading
Loading
Loading
Loading
+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);