From 80e13ae8a591cd2ab68a77a5b1526d933ec02d33 Mon Sep 17 00:00:00 2001 From: Yi Chou Date: Sat, 1 Apr 2023 01:43:53 +0800 Subject: clock: Add ScopedFastCpu Add a helper class to scope the range of boosting CPU. BUG=b:248508087 TEST=make V=1 BOARD=bloonchipper -j BRANCH=none Change-Id: Ic3dc59bb71e75aec8efb0eb1f2b035ef2867bd42 Signed-off-by: Yi Chou Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4345046 Reviewed-by: Tom Hughes --- include/scoped_fast_cpu.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 include/scoped_fast_cpu.h (limited to 'include') diff --git a/include/scoped_fast_cpu.h b/include/scoped_fast_cpu.h new file mode 100644 index 0000000000..5c291362b9 --- /dev/null +++ b/include/scoped_fast_cpu.h @@ -0,0 +1,36 @@ +/* Copyright 2023 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* A class to scope the range of boosting CPU. */ + +#ifndef __CROS_EC_SCOPED_FAST_CPU_H +#define __CROS_EC_SCOPED_FAST_CPU_H + +#include "clock.h" + +class ScopedFastCpu { + public: + ScopedFastCpu() + : previous_state_(current_state_) + { + if (current_state_ != 1) { + clock_enable_module(MODULE_FAST_CPU, 1); + current_state_ = 1; + } + } + ~ScopedFastCpu() + { + if (current_state_ != previous_state_) { + clock_enable_module(MODULE_FAST_CPU, previous_state_); + current_state_ = previous_state_; + } + } + + private: + int previous_state_; + static inline int current_state_; +}; + +#endif /* __CROS_EC_SCOPED_FAST_CPU_H */ -- cgit v1.2.1