Lines Matching defs:Regulator
3 //! Regulator abstractions, providing a standard kernel interface to control
35 /// A trait representing the different states a [`Regulator`] can be in.
41 /// A state where the [`Regulator`] is known to be enabled.
47 /// A state where this [`Regulator`] handle has not specifically asked for the
60 /// A trait that abstracts the ability to check if a [`Regulator`] is enabled.
64 /// An error that can occur when trying to convert a [`Regulator`] between states.
70 pub regulator: Regulator<State>,
78 /// preferred over the [`Regulator<T: RegulatorState>`] API if the caller only
114 /// This example uses [`Regulator<Enabled>`], which is suitable for drivers that
118 /// These users can store [`Regulator<Enabled>`] directly in their driver's
125 /// # use kernel::regulator::{Voltage, Regulator, Disabled, Enabled};
128 /// let regulator: Regulator<Disabled> = Regulator::<Disabled>::get(dev, c_str!("vcc"))?;
143 /// let regulator: Regulator<Enabled> =
169 /// # use kernel::regulator::{Voltage, Regulator, Enabled};
172 /// let regulator: Regulator<Enabled> = Regulator::<Enabled>::get(dev, c_str!("vcc"))?;
212 /// # use kernel::regulator::{Regulator, Enabled, Disabled};
213 /// fn disable(dev: &Device, regulator: Regulator<Enabled>) -> Result {
219 /// let regulator: Regulator<Disabled> =
237 pub struct Regulator<State>
245 impl<T: RegulatorState> Regulator<T> {
250 // SAFETY: Safe as per the type invariants of `Regulator`.
262 // SAFETY: Safe as per the type invariants of `Regulator`.
268 fn get_internal(dev: &Device, name: &CStr) -> Result<Regulator<T>> {
284 // SAFETY: Safe as per the type invariants of `Regulator`.
289 // SAFETY: Safe as per the type invariants of `Regulator`.
294 impl Regulator<Disabled> {
295 /// Obtains a [`Regulator`] instance from the system.
297 Regulator::get_internal(dev, name)
301 pub fn try_into_enabled(self) -> Result<Regulator<Enabled>, Error<Disabled>> {
303 // `Regulator<Enabled>`.
308 .map(|()| Regulator {
319 impl Regulator<Enabled> {
320 /// Obtains a [`Regulator`] instance from the system and enables it.
324 Regulator::<Disabled>::get_internal(dev, name)?
330 pub fn try_into_disabled(self) -> Result<Regulator<Disabled>, Error<Enabled>> {
332 // to `Regulator<Disabled>`.
337 .map(|()| Regulator {
348 impl<T: IsEnabled> Regulator<T> {
351 // SAFETY: Safe as per the type invariants of `Regulator`.
356 impl<T: RegulatorState> Drop for Regulator<T> {
370 // SAFETY: It is safe to send a `Regulator<T>` across threads. In particular, a
371 // Regulator<T> can be dropped from any thread.
372 unsafe impl<T: RegulatorState> Send for Regulator<T> {}
374 // SAFETY: It is safe to send a &Regulator<T> across threads because the C side
376 unsafe impl<T: RegulatorState> Sync for Regulator<T> {}