Struct OptionalClk

Source
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

Source

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>§

Source

pub fn as_raw(&self) -> *mut clk

Obtain the raw [struct clk] pointer.

Source

pub fn enable(&self) -> Result

Enable the clock.

Equivalent to the kernel’s clk_enable API.

Source

pub fn disable(&self)

Disable the clock.

Equivalent to the kernel’s clk_disable API.

Source

pub fn prepare(&self) -> Result

Prepare the clock.

Equivalent to the kernel’s clk_prepare API.

Source

pub fn unprepare(&self)

Unprepare the clock.

Equivalent to the kernel’s clk_unprepare API.

Source

pub fn prepare_enable(&self) -> Result

Prepare and enable the clock.

Equivalent to calling Clk::prepare followed by Clk::enable.

Source

pub fn disable_unprepare(&self)

Disable and unprepare the clock.

Equivalent to calling Clk::disable followed by Clk::unprepare.

Source

pub fn rate(&self) -> Hertz

Get clock’s rate.

Equivalent to the kernel’s clk_get_rate API.

Source

pub fn set_rate(&self, rate: Hertz) -> Result

Set clock’s rate.

Equivalent to the kernel’s clk_set_rate API.

Trait Implementations§

Source§

impl Deref for OptionalClk

Source§

type Target = Clk

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Clk

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, E> Init<T, E> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, E> PinInit<T, E> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.