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.
This commit is contained in:
Norman Feske 2022-10-06 18:31:34 +02:00 committed by Christian Helmuth
parent add4990044
commit eb6a745a18
3 changed files with 21 additions and 0 deletions

View File

@ -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(); }
};
};

View File

@ -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_ */

View File

@ -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_ */