pub struct OptionalClk(/* private fields */);
Expand description
A reference-counted optional clock.
A lightweight wrapper around an optional Clk
. An OptionalClk
represents a Clk
that
a driver can function without but may improve performance or enable additional features when
available.
§Invariants
An OptionalClk
instance encapsulates a Clk
with either a valid struct clk
or NULL
pointer.
Instances of this type are reference-counted. Calling OptionalClk::get
ensures that the
allocation remains valid for the lifetime of the OptionalClk
.
§Examples
The following example demonstrates how to obtain and configure an optional clock for a device. The code functions correctly whether or not the clock is available.
use kernel::c_str;
use kernel::clk::{OptionalClk, Hertz};
use kernel::device::Device;
use kernel::error::Result;
fn configure_clk(dev: &Device) -> Result {
let clk = OptionalClk::get(dev, Some(c_str!("apb_clk")))?;
clk.prepare_enable()?;
let expected_rate = Hertz::from_ghz(1);
if clk.rate() != expected_rate {
clk.set_rate(expected_rate)?;
}
clk.disable_unprepare();
Ok(())
}
Implementations§
Source§impl OptionalClk
impl OptionalClk
Sourcepub fn get(dev: &Device, name: Option<&CStr>) -> Result<Self>
pub fn get(dev: &Device, name: Option<&CStr>) -> Result<Self>
Gets OptionalClk
corresponding to a Device
and a connection id.
Equivalent to the kernel’s clk_get_optional
API.
Methods from Deref<Target = Clk>§
Sourcepub fn enable(&self) -> Result
pub fn enable(&self) -> Result
Enable the clock.
Equivalent to the kernel’s clk_enable
API.
Sourcepub fn disable(&self)
pub fn disable(&self)
Disable the clock.
Equivalent to the kernel’s clk_disable
API.
Sourcepub fn prepare(&self) -> Result
pub fn prepare(&self) -> Result
Prepare the clock.
Equivalent to the kernel’s clk_prepare
API.
Sourcepub fn unprepare(&self)
pub fn unprepare(&self)
Unprepare the clock.
Equivalent to the kernel’s clk_unprepare
API.
Sourcepub fn prepare_enable(&self) -> Result
pub fn prepare_enable(&self) -> Result
Prepare and enable the clock.
Equivalent to calling Clk::prepare
followed by Clk::enable
.
Sourcepub fn disable_unprepare(&self)
pub fn disable_unprepare(&self)
Disable and unprepare the clock.
Equivalent to calling Clk::disable
followed by Clk::unprepare
.
Sourcepub fn rate(&self) -> Hertz
pub fn rate(&self) -> Hertz
Get clock’s rate.
Equivalent to the kernel’s clk_get_rate
API.
Sourcepub fn set_rate(&self, rate: Hertz) -> Result
pub fn set_rate(&self, rate: Hertz) -> Result
Set clock’s rate.
Equivalent to the kernel’s clk_set_rate
API.