From eb6a745a18e420b826994847302f942a544a8b65 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 6 Oct 2022 18:31:34 +0200 Subject: [PATCH] platform: add Guard utils for Clock/Reset/Power These utilities simplify the control of clocks, resets, and power domains from within the platform driver. This is needed when driving a low-level device directly from the platform driver, for example for driving the mbox mechanism to access the system-control processor of the PinePhone. --- repos/os/src/drivers/platform/clock.h | 7 +++++++ repos/os/src/drivers/platform/power.h | 7 +++++++ repos/os/src/drivers/platform/reset.h | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/repos/os/src/drivers/platform/clock.h b/repos/os/src/drivers/platform/clock.h index 170d99fbfb..ed9296532c 100644 --- a/repos/os/src/drivers/platform/clock.h +++ b/repos/os/src/drivers/platform/clock.h @@ -60,6 +60,13 @@ class Driver::Clock : Clocks::Element, Interface void enable() { _switch.use(); } void disable() { _switch.unuse(); } + + struct Guard : Genode::Noncopyable + { + Clock &_clock; + Guard(Clock &clock) : _clock(clock) { _clock.enable(); } + ~Guard() { _clock.disable(); } + }; }; diff --git a/repos/os/src/drivers/platform/power.h b/repos/os/src/drivers/platform/power.h index 676dbd90a7..71039fd56f 100644 --- a/repos/os/src/drivers/platform/power.h +++ b/repos/os/src/drivers/platform/power.h @@ -51,6 +51,13 @@ class Driver::Power : Powers::Element, Interface void on() { _switch.use(); } void off() { _switch.unuse(); } + + struct Guard : Genode::Noncopyable + { + Power &_power; + Guard(Power &power) : _power(power) { _power.on(); } + ~Guard() { _power.off(); } + }; }; #endif /* _POWER_H_ */ diff --git a/repos/os/src/drivers/platform/reset.h b/repos/os/src/drivers/platform/reset.h index e89b6f99d6..f2b61fc389 100644 --- a/repos/os/src/drivers/platform/reset.h +++ b/repos/os/src/drivers/platform/reset.h @@ -51,6 +51,13 @@ class Driver::Reset : Resets::Element, Interface void deassert() { _switch.use(); } void assert() { _switch.unuse(); } + + struct Guard : Genode::Noncopyable + { + Reset &_reset; + Guard(Reset &reset) : _reset(reset) { _reset.deassert(); } + ~Guard() { _reset.assert(); } + }; }; #endif /* _RESET_H_ */