PebbleOS
Loading...
Searching...
No Matches
Regulator

Power rail class. More...

Modules

 nPM1300 regulators
 Regulator rails of the nPM1300, cells of nPM1300.
 

Data Structures

struct  pbl_regulator_ops
 Regulator driver operations. More...
 
struct  pbl_regulator
 A power rail. More...
 

Macros

#define PBL_REGULATOR_STATE_DEFINE(sym)
 Define the class state of regulator sym, for the PBL_*_REGULATOR_DEFINE() macro of a driver.
 
#define PBL_REGULATOR_INIT(sym, _name, _parent, _ops, _always_on)
 Initializer for the struct pbl_regulator of regulator sym.
 

Functions

int pbl_regulator_dev_init (const struct pbl_device *dev)
 Device init of every regulator: applies the driver's init, then switches the rail on if always-on, off otherwise.
 
int pbl_regulator_enable (const struct pbl_regulator *reg)
 Take a reference on a rail, switching it on for the first user.
 
int pbl_regulator_disable (const struct pbl_regulator *reg)
 Drop a reference on a rail, switching it off after the last user.
 
bool pbl_regulator_is_enabled (const struct pbl_regulator *reg)
 Check whether a rail is on.
 

Detailed Description

Power rail class.

A power rail is a struct pbl_regulator device. Consumers enable and disable it with a use count; a rail marked always-on is switched on at init and stays on, and any other rail starts off.

// use the device
int pbl_regulator_enable(const struct pbl_regulator *reg)
Take a reference on a rail, switching it on for the first user.
int pbl_regulator_disable(const struct pbl_regulator *reg)
Drop a reference on a rail, switching it off after the last user.

Data Structure Documentation

◆ pbl_regulator

struct pbl_regulator

A power rail.

Data Fields
bool always_on Switched on at init and never off.
struct pbl_device dev Device.
const struct pbl_regulator_ops * ops Driver operations.
struct pbl_regulator_state * state Runtime state.

Macro Definition Documentation

◆ PBL_REGULATOR_INIT

#define PBL_REGULATOR_INIT (   sym,
  _name,
  _parent,
  _ops,
  _always_on 
)
Value:
{ \
.dev = PBL_DEVICE_INIT(sym, _name, pbl_regulator_dev_init, _parent, nullptr), \
.ops = (_ops), \
.state = &sym##_regulator_state, \
.always_on = (_always_on), \
}
#define PBL_DEVICE_INIT(sym, _name, _init, _parent, _deps)
Initializer for the struct pbl_device of device instance sym.
Definition device.h:142
int pbl_regulator_dev_init(const struct pbl_device *dev)
Device init of every regulator: applies the driver's init, then switches the rail on if always-on,...

Initializer for the struct pbl_regulator of regulator sym.

Parameters
symSymbol of the regulator instance, with its state defined by PBL_REGULATOR_STATE_DEFINE().
_nameName.
_parentParent device, or NULL.
_opsDriver operations.
_always_onSwitched on at init and never off.

◆ PBL_REGULATOR_STATE_DEFINE

#define PBL_REGULATOR_STATE_DEFINE (   sym)
Value:
static struct pbl_regulator_state sym##_regulator_state
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:109

Define the class state of regulator sym, for the PBL_*_REGULATOR_DEFINE() macro of a driver.

Parameters
symSymbol of the regulator instance.

Function Documentation

◆ pbl_regulator_dev_init()

int pbl_regulator_dev_init ( const struct pbl_device *  dev)

Device init of every regulator: applies the driver's init, then switches the rail on if always-on, off otherwise.

Parameters
devRegulator device.
Returns
0 or a negative errno.

◆ pbl_regulator_disable()

int pbl_regulator_disable ( const struct pbl_regulator *  reg)

Drop a reference on a rail, switching it off after the last user.

Must balance a successful pbl_regulator_enable().

Parameters
regRegulator.
Returns
0 or a negative errno.

◆ pbl_regulator_enable()

int pbl_regulator_enable ( const struct pbl_regulator *  reg)

Take a reference on a rail, switching it on for the first user.

Parameters
regRegulator.
Returns
0 or a negative errno.

◆ pbl_regulator_is_enabled()

bool pbl_regulator_is_enabled ( const struct pbl_regulator *  reg)

Check whether a rail is on.

Parameters
regRegulator.
Returns
True if the rail is always-on or has users.