summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorYi Chou <yich@google.com>2023-04-01 01:43:53 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-04-25 13:23:44 +0000
commit80e13ae8a591cd2ab68a77a5b1526d933ec02d33 (patch)
treeadc37a4fb6aee2efd988b67bf58caa9be33134da /include
parent438865216dc3e4b7c86da0af5817040b10e78778 (diff)
downloadchrome-ec-80e13ae8a591cd2ab68a77a5b1526d933ec02d33.tar.gz
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 <yich@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4345046 Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/scoped_fast_cpu.h36
1 files changed, 36 insertions, 0 deletions
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 */