forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rust: regulator: add regulator consumer abstractions
Add a rust abstraction for the regulator consumer API. Signed-off-by: Fabien Parent <[email protected]>
- Loading branch information
Showing
4 changed files
with
439 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
|
||
//! SoC Regulators | ||
pub mod consumer; | ||
|
||
use crate::{ | ||
bindings, | ||
error::{code::*, Error, Result}, | ||
}; | ||
|
||
/// [`consumer::Regulator`] and [`driver::Regulator`] operating modes | ||
#[derive(Copy, Clone)] | ||
#[repr(u32)] | ||
pub enum Mode { | ||
/// Invalid mode | ||
Invalid = bindings::REGULATOR_MODE_INVALID, | ||
/// Regulator can handle fast changes in it's load | ||
Fast = bindings::REGULATOR_MODE_FAST, | ||
/// Normal regulator power supply mode | ||
Normal = bindings::REGULATOR_MODE_NORMAL, | ||
/// Regulator runs in a more efficient mode for light loads | ||
Idle = bindings::REGULATOR_MODE_IDLE, | ||
/// Regulator runs in the most efficient mode for very light loads | ||
Standby = bindings::REGULATOR_MODE_STANDBY, | ||
} | ||
|
||
impl TryFrom<core::ffi::c_uint> for Mode { | ||
type Error = Error; | ||
|
||
/// Convert a mode represented as an unsigned integer into its Rust enum equivalent | ||
/// | ||
/// If the integer does not match any of the [`Mode`], then [`EINVAL`] is returned | ||
fn try_from(mode: core::ffi::c_uint) -> Result<Self> { | ||
match mode { | ||
bindings::REGULATOR_MODE_FAST => Ok(Self::Fast), | ||
bindings::REGULATOR_MODE_NORMAL => Ok(Self::Normal), | ||
bindings::REGULATOR_MODE_IDLE => Ok(Self::Idle), | ||
bindings::REGULATOR_MODE_STANDBY => Ok(Self::Standby), | ||
bindings::REGULATOR_MODE_INVALID => Ok(Self::Invalid), | ||
_ => Err(EINVAL), | ||
} | ||
} | ||
} |
Oops, something went wrong.