|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
| 2 | + |
| 3 | +//! SoC Regulators |
| 4 | +
|
| 5 | +pub mod consumer; |
| 6 | + |
| 7 | +use crate::{ |
| 8 | + bindings, |
| 9 | + error::{code::*, Error, Result}, |
| 10 | +}; |
| 11 | + |
| 12 | +/// [`consumer::Regulator`] and [`driver::Regulator`] operating modes |
| 13 | +#[derive(Copy, Clone)] |
| 14 | +#[repr(u32)] |
| 15 | +pub enum Mode { |
| 16 | + /// Invalid mode |
| 17 | + Invalid = bindings::REGULATOR_MODE_INVALID, |
| 18 | + /// Regulator can handle fast changes in it's load |
| 19 | + Fast = bindings::REGULATOR_MODE_FAST, |
| 20 | + /// Normal regulator power supply mode |
| 21 | + Normal = bindings::REGULATOR_MODE_NORMAL, |
| 22 | + /// Regulator runs in a more efficient mode for light loads |
| 23 | + Idle = bindings::REGULATOR_MODE_IDLE, |
| 24 | + /// Regulator runs in the most efficient mode for very light loads |
| 25 | + Standby = bindings::REGULATOR_MODE_STANDBY, |
| 26 | +} |
| 27 | + |
| 28 | +impl TryFrom<core::ffi::c_uint> for Mode { |
| 29 | + type Error = Error; |
| 30 | + |
| 31 | + /// Convert a mode represented as an unsigned integer into its Rust enum equivalent |
| 32 | + /// |
| 33 | + /// If the integer does not match any of the [`Mode`], then [`EINVAL`] is returned |
| 34 | + fn try_from(mode: core::ffi::c_uint) -> Result<Self> { |
| 35 | + match mode { |
| 36 | + bindings::REGULATOR_MODE_FAST => Ok(Self::Fast), |
| 37 | + bindings::REGULATOR_MODE_NORMAL => Ok(Self::Normal), |
| 38 | + bindings::REGULATOR_MODE_IDLE => Ok(Self::Idle), |
| 39 | + bindings::REGULATOR_MODE_STANDBY => Ok(Self::Standby), |
| 40 | + bindings::REGULATOR_MODE_INVALID => Ok(Self::Invalid), |
| 41 | + _ => Err(EINVAL), |
| 42 | + } |
| 43 | + } |
| 44 | +} |
0 commit comments