Voltage and current regulator API

Author:

Liam Girdwood

Author:

Mark Brown

Introduction

This framework is designed to provide a standard kernel interface tocontrol voltage and current regulators.

The intention is to allow systems to dynamically control regulator poweroutput in order to save power and prolong battery life. This applies toboth voltage regulators (where voltage output is controllable) andcurrent sinks (where current limit is controllable).

Note that additional (and currently more complete) documentation isavailable in the Linux kernel source underDocumentation/power/regulator.

Glossary

The regulator API uses a number of terms which may not be familiar:

Regulator

Electronic device that supplies power to other devices. Most regulatorscan enable and disable their output and some can also control theiroutput voltage or current.

Consumer

Electronic device which consumes power provided by a regulator. Thesemay either be static, requiring only a fixed supply, or dynamic,requiring active management of the regulator at runtime.

Power Domain

The electronic circuit supplied by a given regulator, including theregulator and all consumer devices. The configuration of the regulatoris shared between all the components in the circuit.

Power Management Integrated Circuit (PMIC)

An IC which contains numerous regulators and often also othersubsystems. In an embedded system the primary PMIC is often equivalentto a combination of the PSU and southbridge in a desktop system.

Consumer driver interface

This offers a similar API to the kernel clock framework. Consumerdrivers useget andput operations to acquire and releaseregulators. Functions are provided toenableanddisable the regulator and to get andset the runtime parameters of the regulator.

When requesting regulators consumers use symbolic names for theirsupplies, such as “Vcc”, which are mapped into actual regulator devicesby the machine interface.

A stub version of this API is provided when the regulator framework isnot in use in order to minimise the need to use ifdefs.

Enabling and disabling

The regulator API provides reference counted enabling and disabling ofregulators. Consumer devices use theregulator_enable() andregulator_disable() functions to enable and disableregulators. Calls to the two functions must be balanced.

Note that since multiple consumers may be using a regulator and machineconstraints may not allow the regulator to be disabled there is noguarantee that callingregulator_disable() will actuallycause the supply provided by the regulator to be disabled. Consumerdrivers should assume that the regulator may be enabled at all times.

Configuration

Some consumer devices may need to be able to dynamically configure theirsupplies. For example, MMC drivers may need to select the correctoperating voltage for their cards. This may be done while the regulatoris enabled or disabled.

Theregulator_set_voltage() andregulator_set_current_limit() functions provide the primaryinterface for this. Both take ranges of voltages and currents, supportingdrivers that do not require a specific value (eg, CPU frequency scalingnormally permits the CPU to use a wider range of supply voltages at lowerfrequencies but does not require that the supply voltage be lowered). Wherean exact value is required both minimum and maximum values should beidentical.

Callbacks

Callbacks may also be registered for events such as regulation failures.

Regulator driver interface

Drivers for regulator chips register the regulators with the regulatorcore, providing operations structures to the core. A notifier interfaceallows error conditions to be reported to the core.

Registration should be triggered by explicit setup done by the platform,supplying astructregulator_init_data for the regulatorcontaining constraint and supply information.

Machine interface

This interface provides a way to define how regulators are connected toconsumers on a given system and what the valid operating parameters arefor the system.

Supplies

Regulator supplies are specified using structregulator_consumer_supply. This is done at driver registrationtime as part of the machine constraints.

Constraints

As well as defining the connections the machine interface also providesconstraints defining the operations that clients are allowed to performand the parameters that may be set. This is required since generallyregulator devices will offer more flexibility than it is safe to use ona given system, for example supporting higher supply voltages than theconsumers are rated for.

This is done at driver registration time` by providing astructregulation_constraints.

The constraints may also specify an initial configuration for theregulator in the constraints, which is particularly useful for use withstatic consumers.

API reference

Due to limitations of the kernel documentation framework and theexisting layout of the source code the entire regulator API isdocumented here.

structpre_voltage_change_data

Data sent with PRE_VOLTAGE_CHANGE event

Definition:

struct pre_voltage_change_data {    unsigned long old_uV;    unsigned long min_uV;    unsigned long max_uV;};

Members

old_uV

Current voltage before change.

min_uV

Min voltage we’ll change to.

max_uV

Max voltage we’ll change to.

structregulator_bulk_data

Data used for bulk regulator operations.

Definition:

struct regulator_bulk_data {    const char *supply;    struct regulator *consumer;    int init_load_uA;};

Members

supply

The name of the supply. Initialised by the user beforeusing the bulk regulator APIs.

consumer

The regulator consumer for the supply. This will be managedby the bulk API.

init_load_uA

After getting the regulator,regulator_set_load() will becalled with this load. Initialised by the user beforeusing the bulk regulator APIs.

Description

The regulator APIs provide a series ofregulator_bulk_() API calls asa convenience to consumers which require multiple supplies. Thisstructure is used to manage data for these calls.

structregulator_state

regulator state during low power system states

Definition:

struct regulator_state {    int uV;    int min_uV;    int max_uV;    unsigned int mode;    int enabled;    bool changeable;};

Members

uV

Default operating voltage during suspend, it can be adjustedamong <min_uV, max_uV>.

min_uV

Minimum suspend voltage may be set.

max_uV

Maximum suspend voltage may be set.

mode

Operating mode during suspend.

enabled

operations during suspend.- DO_NOTHING_IN_SUSPEND- DISABLE_IN_SUSPEND- ENABLE_IN_SUSPEND

changeable

Is this state can be switched between enabled/disabled,

Description

This describes a regulators state during a system wide low powerstate. One of enabled or disabled must be set for theconfiguration to be applied.

structregulation_constraints

regulator operating constraints.

Definition:

struct regulation_constraints {    const char *name;    int min_uV;    int max_uV;    int uV_offset;    int min_uA;    int max_uA;    int ilim_uA;    int pw_budget_mW;    int system_load;    u32 *max_spread;    int max_uV_step;    unsigned int valid_modes_mask;    unsigned int valid_ops_mask;    int input_uV;    struct regulator_state state_disk;    struct regulator_state state_mem;    struct regulator_state state_standby;    struct notification_limit over_curr_limits;    struct notification_limit over_voltage_limits;    struct notification_limit under_voltage_limits;    struct notification_limit temp_limits;    suspend_state_t initial_state;    unsigned int initial_mode;    unsigned int ramp_delay;    unsigned int settling_time;    unsigned int settling_time_up;    unsigned int settling_time_down;    unsigned int enable_time;    unsigned int uv_less_critical_window_ms;    unsigned int active_discharge;    unsigned always_on:1;    unsigned boot_on:1;    unsigned apply_uV:1;    unsigned ramp_disable:1;    unsigned soft_start:1;    unsigned pull_down:1;    unsigned system_critical:1;    unsigned over_current_protection:1;    unsigned over_current_detection:1;    unsigned over_voltage_detection:1;    unsigned under_voltage_detection:1;    unsigned over_temp_detection:1;};

Members

name

Descriptive name for the constraints, used for display purposes.

min_uV

Smallest voltage consumers may set.

max_uV

Largest voltage consumers may set.

uV_offset

Offset applied to voltages from consumer to compensate forvoltage drops.

min_uA

Smallest current consumers may set.

max_uA

Largest current consumers may set.

ilim_uA

Maximum input current.

pw_budget_mW

Power budget for the regulator in mW.

system_load

Load that isn’t captured by any consumer requests.

max_spread

Max possible spread between coupled regulators

max_uV_step

Max possible step change in voltage

valid_modes_mask

Mask of modes which may be configured by consumers.

valid_ops_mask

Operations which may be performed by consumers.

input_uV

Input voltage for regulator when supplied by another regulator.

state_disk

State for regulator when system is suspended in disk mode.

state_mem

State for regulator when system is suspended in mem mode.

state_standby

State for regulator when system is suspended in standbymode.

over_curr_limits

Limits for acting on over current.

over_voltage_limits

Limits for acting on over voltage.

under_voltage_limits

Limits for acting on under voltage.

temp_limits

Limits for acting on over temperature.

initial_state

Suspend state to set by default.

initial_mode

Mode to set at startup.

ramp_delay

Time to settle down after voltage change (unit: uV/us)

settling_time

Time to settle down after voltage change when voltagechange is non-linear (unit: microseconds).

settling_time_up

Time to settle down after voltage increase when voltagechange is non-linear (unit: microseconds).

settling_time_down

Time to settle down after voltage decrease whenvoltage change is non-linear (unit: microseconds).

enable_time

Turn-on time of the rails (unit: microseconds)

uv_less_critical_window_ms

Specifies the time window (in milliseconds)following a critical under-voltage (UV) eventduring which less critical actions can besafely carried out by the system (for examplelogging). After this time window more criticalactions should be done (for example preventHW damage).

active_discharge

Enable/disable active discharge. Theenumregulator_active_discharge values are used forinitialisation.

always_on

Set if the regulator should never be disabled.

boot_on

Set if the regulator is enabled when the system is initiallystarted. If the regulator is not enabled by the hardware orbootloader then it will be enabled when the constraints areapplied.

apply_uV

Apply the voltage constraint when initialising.

ramp_disable

Disable ramp delay when initialising or when setting voltage.

soft_start

Enable soft start so that voltage ramps slowly.

pull_down

Enable pull down when regulator is disabled.

system_critical

Set if the regulator is critical to system stability orfunctionality.

over_current_protection

Auto disable on over current event.

over_current_detection

Configure over current limits.

over_voltage_detection

Configure over voltage limits.

under_voltage_detection

Configure under voltage limits.

over_temp_detection

Configure over temperature limits.

Description

Thisstructdescribes regulator and board/machine specific constraints.

structregulator_consumer_supply

supply -> device mapping

Definition:

struct regulator_consumer_supply {    const char *dev_name;    const char *supply;};

Members

dev_name

Result ofdev_name() for the consumer.

supply

Name for the supply.

Description

This maps a supply name to a device. Use of dev_name allows support forbuses which makestructdevice available late such as I2C.

structregulator_init_data

regulator platform initialisation data.

Definition:

struct regulator_init_data {    const char *supply_regulator;    struct regulation_constraints constraints;    int num_consumer_supplies;    struct regulator_consumer_supply *consumer_supplies;    void *driver_data;};

Members

supply_regulator

Parent regulator. Specified using the regulator nameas it appears in the name field in sysfs, which canbe explicitly set using the constraints field ‘name’.

constraints

Constraints. These must be specified for the regulator tobe usable.

num_consumer_supplies

Number of consumer device supplies.

consumer_supplies

Consumer device supply configuration.

driver_data

Data passed to regulator_init.

Description

Initialisation constraints, our supply and consumers supplies.

structregulator_ops

regulator operations.

Definition:

struct regulator_ops {    int (*list_voltage) (struct regulator_dev *, unsigned selector);    int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV, unsigned *selector);    int (*map_voltage)(struct regulator_dev *, int min_uV, int max_uV);    int (*set_voltage_sel) (struct regulator_dev *, unsigned selector);    int (*get_voltage) (struct regulator_dev *);    int (*get_voltage_sel) (struct regulator_dev *);    int (*set_current_limit) (struct regulator_dev *, int min_uA, int max_uA);    int (*get_current_limit) (struct regulator_dev *);    int (*set_input_current_limit) (struct regulator_dev *, int lim_uA);    int (*set_over_current_protection)(struct regulator_dev *, int lim_uA, int severity, bool enable);    int (*set_over_voltage_protection)(struct regulator_dev *, int lim_uV, int severity, bool enable);    int (*set_under_voltage_protection)(struct regulator_dev *, int lim_uV, int severity, bool enable);    int (*set_thermal_protection)(struct regulator_dev *, int lim, int severity, bool enable);    int (*set_active_discharge)(struct regulator_dev *, bool enable);    int (*enable) (struct regulator_dev *);    int (*disable) (struct regulator_dev *);    int (*is_enabled) (struct regulator_dev *);    int (*set_mode) (struct regulator_dev *, unsigned int mode);    unsigned int (*get_mode) (struct regulator_dev *);    int (*get_error_flags)(struct regulator_dev *, unsigned int *flags);    int (*enable_time) (struct regulator_dev *);    int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay);    int (*set_voltage_time) (struct regulator_dev *, int old_uV, int new_uV);    int (*set_voltage_time_sel) (struct regulator_dev *, unsigned int old_selector, unsigned int new_selector);    int (*set_soft_start) (struct regulator_dev *);    int (*get_status)(struct regulator_dev *);    unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, int output_uV, int load_uA);    int (*set_load)(struct regulator_dev *, int load_uA);    int (*set_bypass)(struct regulator_dev *dev, bool enable);    int (*get_bypass)(struct regulator_dev *dev, bool *enable);    int (*set_suspend_voltage) (struct regulator_dev *, int uV);    int (*set_suspend_enable) (struct regulator_dev *);    int (*set_suspend_disable) (struct regulator_dev *);    int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode);    int (*resume)(struct regulator_dev *rdev);    int (*set_pull_down) (struct regulator_dev *);};

Members

list_voltage

Return one of the supported voltages, in microvolts; zeroif the selector indicates a voltage that is unusable on this system;or negative errno. Selectors range from zero to one less thanregulator_desc.n_voltages. Voltages may be reported in any order.

set_voltage

Set the voltage for the regulator within the range specified.The driver should select the voltage closest to min_uV.

map_voltage

Convert a voltage into a selector

set_voltage_sel

Set the voltage for the regulator using the specifiedselector.

get_voltage

Return the currently configured voltage for the regulator;return -ENOTRECOVERABLE if regulator can’t be read atbootup and hasn’t been set yet.

get_voltage_sel

Return the currently configured voltage selector for theregulator; return -ENOTRECOVERABLE if regulator can’tbe read at bootup and hasn’t been set yet.

set_current_limit

Configure a limit for a current-limited regulator.The driver should select the current closest to max_uA.

get_current_limit

Get the configured limit for a current-limited regulator.

set_input_current_limit

Configure an input limit.

set_over_current_protection

Support enabling of and setting limits for overcurrent situation detection. Detection can be configured for threelevels of severity.

set_over_voltage_protection

Support enabling of and setting limits for overvoltage situation detection. Detection can be configured for sameseverities as over current protection. Units of uV.

set_under_voltage_protection

Support enabling of and setting limits forunder voltage situation detection. Detection can be configured for sameseverities as over current protection. Units of uV.

set_thermal_protection

Support enabling of and setting limits for overtemperature situation detection.Detection can be configured for sameseverities as over current protection. Units of degree Kelvin.

set_active_discharge

Set active discharge enable/disable of regulators.

enable

Configure the regulator as enabled.

disable

Configure the regulator as disabled.

is_enabled

Return 1 if the regulator is enabled, 0 if not.May also return negative errno.

set_mode

Set the configured operating mode for the regulator.

get_mode

Get the configured operating mode for the regulator.

get_error_flags

Get the current error(s) for the regulator.

enable_time

Time taken for the regulator voltage output voltage tostabilise after being enabled, in microseconds.

set_ramp_delay

Set the ramp delay for the regulator. The driver shouldselect ramp delay equal to or less than(closest) ramp_delay.

set_voltage_time

Time taken for the regulator voltage output voltageto stabilise after being set to a new value, in microseconds.The function receives the from and to voltage as input, itshould return the worst case.

set_voltage_time_sel

Time taken for the regulator voltage output voltageto stabilise after being set to a new value, in microseconds.The function receives the from and to voltage selector asinput, it should return the worst case.

set_soft_start

Enable soft start for the regulator.

get_status

Return actual (not as-configured) status of regulator, as aREGULATOR_STATUS value (or negative errno)

get_optimum_mode

Get the most efficient operating mode for the regulatorwhen running with the specified parameters.

set_load

Set the load for the regulator.

set_bypass

Set the regulator in bypass mode.

get_bypass

Get the regulator bypass mode state.

set_suspend_voltage

Set the voltage for the regulator when the systemis suspended.

set_suspend_enable

Mark the regulator as enabled when the system issuspended.

set_suspend_disable

Mark the regulator as disabled when the system issuspended.

set_suspend_mode

Set the operating mode for the regulator when thesystem is suspended.

resume

Resume operation of suspended regulator.

set_pull_down

Configure the regulator to pull down when the regulatoris disabled.

Description

  • REGULATOR_SEVERITY_PROT should automatically shut down the regulator(s).

  • REGULATOR_SEVERITY_ERR should indicate that over-current situation is

    caused by an unrecoverable error but HW does not performautomatic shut down.

  • REGULATOR_SEVERITY_WARN should indicate situation where hardware is

    still believed to not be damaged but that a board sepcificrecovery action is needed. If lim_uA is 0 the limit should notbe changed but the detection should just be enabled/disabled asis requested.

Thisstructdescribes regulator operations which can be implemented byregulator chip drivers.

structregulator_desc

Static regulator descriptor

Definition:

struct regulator_desc {    const char *name;    const char *supply_name;    const char *of_match;    bool of_match_full_name;    const char *regulators_node;    int (*of_parse_cb)(struct device_node *, const struct regulator_desc *, struct regulator_config *);    int (*init_cb)(struct regulator_dev *, struct regulator_config *);    int id;    unsigned int continuous_voltage_range:1;    unsigned n_voltages;    unsigned int n_current_limits;    const struct regulator_ops *ops;    int irq;    enum regulator_type type;    struct module *owner;    unsigned int min_uV;    unsigned int uV_step;    unsigned int linear_min_sel;    int fixed_uV;    unsigned int ramp_delay;    int min_dropout_uV;    const struct linear_range *linear_ranges;    const unsigned int *linear_range_selectors_bitfield;    int n_linear_ranges;    const unsigned int *volt_table;    const unsigned int *curr_table;    unsigned int vsel_range_reg;    unsigned int vsel_range_mask;    bool range_applied_by_vsel;    unsigned int vsel_reg;    unsigned int vsel_mask;    unsigned int vsel_step;    unsigned int csel_reg;    unsigned int csel_mask;    unsigned int apply_reg;    unsigned int apply_bit;    unsigned int enable_reg;    unsigned int enable_mask;    unsigned int enable_val;    unsigned int disable_val;    bool enable_is_inverted;    unsigned int bypass_reg;    unsigned int bypass_mask;    unsigned int bypass_val_on;    unsigned int bypass_val_off;    unsigned int active_discharge_on;    unsigned int active_discharge_off;    unsigned int active_discharge_mask;    unsigned int active_discharge_reg;    unsigned int soft_start_reg;    unsigned int soft_start_mask;    unsigned int soft_start_val_on;    unsigned int pull_down_reg;    unsigned int pull_down_mask;    unsigned int pull_down_val_on;    unsigned int ramp_reg;    unsigned int ramp_mask;    const unsigned int *ramp_delay_table;    unsigned int n_ramp_values;    unsigned int enable_time;    unsigned int off_on_delay;    unsigned int poll_enabled_time;    unsigned int (*of_map_mode)(unsigned int mode);};

Members

name

Identifying name for the regulator.

supply_name

Identifying the regulator supply

of_match

Name used to identify regulator in DT.

of_match_full_name

A flag to indicate that the of_match string, ifpresent, should be matched against the node full_name.

regulators_node

Name of node containing regulator definitions in DT.

of_parse_cb

Optional callback called only if of_match is present.Will be called for each regulator parsed from DT, duringinit_data parsing.The regulator_config passed as argument to the callback willbe a copy of config passed to regulator_register, valid onlyfor this particular call. Callback may freely change theconfig but it cannot store it for later usage.Callback should return 0 on success or negative ERRNOindicating failure.

init_cb

Optional callback called after the parsing of init_data.Allows the regulator to perform runtime init if necessary,such as synching the regulator and the parsed constraints.Callback should return 0 on success or negative ERRNOindicating failure.

id

Numerical identifier for the regulator.

continuous_voltage_range

Indicates if the regulator can set anyvoltage within constrains range.

n_voltages

Number of selectors available for ops.list_voltage().

n_current_limits

Number of selectors available for current limits

ops

Regulator operations table.

irq

Interrupt number for the regulator.

type

Indicates if the regulator is a voltage or current regulator.

owner

Module providing the regulator, used for refcounting.

min_uV

Voltage given by the lowest selector (if linear mapping)

uV_step

Voltage increase with each selector (if linear mapping)

linear_min_sel

Minimal selector for starting linear mapping

fixed_uV

Fixed voltage of rails.

ramp_delay

Time to settle down after voltage change (unit: uV/us)

min_dropout_uV

The minimum dropout voltage this regulator can handle

linear_ranges

A constant table of possible voltage ranges.

linear_range_selectors_bitfield

A constant table of voltage rangeselectors as bitfield values. Ifpickable ranges are used each rangemust have corresponding selector here.

n_linear_ranges

Number of entries in thelinear_ranges (and inlinear_range_selectors_bitfield if used) table(s).

volt_table

Voltage mapping table (if table based mapping)

curr_table

Current limit mapping table (if table based mapping)

vsel_range_reg

Register for range selector when using pickable rangesandregulator_map_*_voltage_*_pickable functions.

vsel_range_mask

Mask for register bitfield used for range selector

range_applied_by_vsel

A flag to indicate that changes to vsel_range_regare only effective after vsel_reg is written

vsel_reg

Register for selector when usingregulator_map_*_voltage_*

vsel_mask

Mask for register bitfield used for selector

vsel_step

Specify the resolution of selector stepping when settingvoltage. If 0, then no stepping is done (requested selector isset directly), if >0 then the regulator API will ramp thevoltage up/down gradually each time increasing/decreasing theselector by the specified step value.

csel_reg

Register for current limit selector using regmap set_current_limit

csel_mask

Mask for register bitfield used for current limit selector

apply_reg

Register for initiate voltage change on the output whenusing regulator_set_voltage_sel_regmap

apply_bit

Register bitfield used for initiate voltage change on theoutput when using regulator_set_voltage_sel_regmap

enable_reg

Register for control when using regmap enable/disable ops

enable_mask

Mask for control when using regmap enable/disable ops

enable_val

Enabling value for control when using regmap enable/disable ops

disable_val

Disabling value for control when using regmap enable/disable ops

enable_is_inverted

A flag to indicate set enable_mask bits to disablewhen using regulator_enable_regmap and friends APIs.

bypass_reg

Register for control when using regmap set_bypass

bypass_mask

Mask for control when using regmap set_bypass

bypass_val_on

Enabling value for control when using regmap set_bypass

bypass_val_off

Disabling value for control when using regmap set_bypass

active_discharge_on

Disabling value for control when using regmapset_active_discharge

active_discharge_off

Enabling value for control when using regmapset_active_discharge

active_discharge_mask

Mask for control when using regmapset_active_discharge

active_discharge_reg

Register for control when using regmapset_active_discharge

soft_start_reg

Register for control when using regmap set_soft_start

soft_start_mask

Mask for control when using regmap set_soft_start

soft_start_val_on

Enabling value for control when using regmapset_soft_start

pull_down_reg

Register for control when using regmap set_pull_down

pull_down_mask

Mask for control when using regmap set_pull_down

pull_down_val_on

Enabling value for control when using regmapset_pull_down

ramp_reg

Register for controlling the regulator ramp-rate.

ramp_mask

Bitmask for the ramp-rate control register.

ramp_delay_table

Table for mapping the regulator ramp-rate values. Valuesshould be given in units of V/S (uV/uS). See theregulator_set_ramp_delay_regmap().

n_ramp_values

number of elements atramp_delay_table.

enable_time

Time taken for initial enable of regulator (in uS).

off_on_delay

guard time (in uS), before re-enabling a regulator

poll_enabled_time

The polling interval (in uS) to use while checking thatthe regulator was actually enabled. Max upto enable_time.

of_map_mode

Maps a hardware mode defined in a DeviceTree to a standard mode

Description

Each regulator registered with the core is described with astructure of this type and astructregulator_config. Thisstructure contains the non-varying parts of the regulatordescription.

structregulator_config

Dynamic regulator descriptor

Definition:

struct regulator_config {    struct device *dev;    const struct regulator_init_data *init_data;    void *driver_data;    struct device_node *of_node;    struct regmap *regmap;    struct gpio_desc *ena_gpiod;};

Members

dev

structdevice for the regulator

init_data

platform provided init data, passed through by driver

driver_data

private regulator data

of_node

OpenFirmware node to parse for device tree bindings (may beNULL).

regmap

regmap to use for core regmap helpers ifdev_get_regmap() isinsufficient.

ena_gpiod

GPIO controlling regulator enable.

Description

Each regulator registered with the core is described with astructure of this type and astructregulator_desc. This structurecontains the runtime variable parts of the regulator description.

structregulator_err_state

regulator error/notification status

Definition:

struct regulator_err_state {    struct regulator_dev *rdev;    unsigned long notifs;    unsigned long errors;    int possible_errs;};

Members

rdev

Regulator which status thestructindicates.

notifs

Events which have occurred on the regulator.

errors

Errors which are active on the regulator.

possible_errs

Errors which can be signaled (by given IRQ).

structregulator_irq_data

regulator error/notification status data

Definition:

struct regulator_irq_data {    struct regulator_err_state *states;    int num_states;    void *data;    long opaque;};

Members

states

Status structs for each of the associated regulators.

num_states

Amount of associated regulators.

data

Driver data pointer given at regulator_irq_desc.

opaque

Value storage for IC driver. Core does not update this. ICsmay want to store status register value here at map_event andcompare contents at ‘renable’ callback to see if new problemshave been added to status. If that is the case it may bedesirable to return REGULATOR_ERROR_CLEARED and notREGULATOR_ERROR_ON to allow IRQ fire again and to generatenotifications also for the new issues.

Description

This structure is passed to ‘map_event’ and ‘renable’ callbacks forreporting regulator status to core.

structregulator_irq_desc

notification sender for IRQ based events.

Definition:

struct regulator_irq_desc {    const char *name;    int fatal_cnt;    int reread_ms;    int irq_off_ms;    bool skip_off;    bool high_prio;    void *data;    int (*die)(struct regulator_irq_data *rid);    int (*map_event)(int irq, struct regulator_irq_data *rid, unsigned long *dev_mask);    int (*renable)(struct regulator_irq_data *rid);};

Members

name

The visible name for the IRQ

fatal_cnt

If this IRQ is used to signal HW damaging condition it may bebest to shut-down regulator(s) or reboot the SOC if errorhandling is repeatedly failing. If fatal_cnt is given the IRQhandling is aborted if it fails for fatal_cnt times anddie()callback (if populated) is called. Ifdie() is not populatedpoweroff for the system is attempted in order to prevent anyfurther damage.

reread_ms

The time which is waited before attempting to re-read statusat the worker if IC reading fails. Immediate re-read is doneif time is not specified.

irq_off_ms

The time which IRQ is kept disabled before re-evaluating thestatus for devices which keep IRQ disabled for duration of theerror. If this is not given the IRQ is left enabled and renableis not called.

skip_off

If set to true the IRQ handler will attempt to check if any ofthe associated regulators are enabled prior to taking otheractions. If no regulators are enabled and this is set to truea spurious IRQ is assumed and IRQ_NONE is returned.

high_prio

Boolean to indicate that high priority WQ should be used.

data

Driver private data pointer which will be passed as such tothe renable, map_event and die callbacks in regulator_irq_data.

die

Protection callback. If IC status reading or recovery actionsfail fatal_cnt times this callback is called or system ispowered off. This callback should implement a final protectionattempt like disabling the regulator. If protection succeededdie() may return 0. If anything else is returned the coreassumes final protection failed and attempts to perform apoweroff as a last resort.

map_event

Driver callback to map IRQ status into regulator devices withevents / errors. NOTE: callback MUST initialize both theerrors and notifs for all rdevs which it signals havingactive events as core does not clean the map data.REGULATOR_FAILED_RETRY can be returned to indicate that thestatus reading from IC failed. If this is repeated forfatal_cnt times the core will calldie() callback or power-offthe system as a last resort to protect the HW.

renable

Optional callback to check status (if HW supports that) beforere-enabling IRQ. If implemented this should clear the errorflags so that errors fetched byregulator_get_error_flags()are updated. If callback is not implemented then errors areassumed to be cleared and IRQ is re-enabled.REGULATOR_FAILED_RETRY can be returned toindicate that the status reading from IC failed. If this isrepeated for ‘fatal_cnt’ times the core will calldie()callback or ifdie() is not populated then attempt to power-offthe system as a last resort to protect the HW.Returning zero indicates that the problem in HW has been solvedand IRQ will be re-enabled. Returning REGULATOR_ERROR_ONindicates the error condition is still active and keeps IRQdisabled. Please note that returning REGULATOR_ERROR_ON doesnot retrigger evaluating what events are active or resendingnotifications. If this is needed you probably want to returnzero and allow IRQ to retrigger causing events to bere-evaluated and re-sent.

Description

This structure is used for registering regulator IRQ notification helper.

structregulator*regulator_get(structdevice*dev,constchar*id)

lookup and obtain a reference to a regulator.

Parameters

structdevice*dev

device for regulator “consumer”

constchar*id

Supply name or regulator ID.

Description

Use of supply names configured viaset_consumer_device_supply() isstrongly encouraged. It is recommended that the supply name usedshould match the name used for the supply and/or the relevantdevice pins in the datasheet.

Return

Pointer to astructregulator corresponding to the regulatorproducer, or anERR_PTR() encoded negative error number.

structregulator*regulator_get_exclusive(structdevice*dev,constchar*id)

obtain exclusive access to a regulator.

Parameters

structdevice*dev

device for regulator “consumer”

constchar*id

Supply name or regulator ID.

Description

Other consumers will be unable to obtain this regulator while thisreference is held and the use count for the regulator will beinitialised to reflect the current state of the regulator.

This is intended for use by consumers which cannot tolerate shareduse of the regulator such as those which need to force theregulator off for correct operation of the hardware they arecontrolling.

Use of supply names configured viaset_consumer_device_supply() isstrongly encouraged. It is recommended that the supply name usedshould match the name used for the supply and/or the relevantdevice pins in the datasheet.

Return

Pointer to astructregulator corresponding to the regulatorproducer, or anERR_PTR() encoded negative error number.

structregulator*regulator_get_optional(structdevice*dev,constchar*id)

obtain optional access to a regulator.

Parameters

structdevice*dev

device for regulator “consumer”

constchar*id

Supply name or regulator ID.

Description

This is intended for use by consumers for devices which can havesome supplies unconnected in normal use, such as some MMC devices.It can allow the regulator core to provide stub supplies for othersupplies requested using normalregulator_get() calls withoutdisrupting the operation of drivers that can handle absentsupplies.

Use of supply names configured viaset_consumer_device_supply() isstrongly encouraged. It is recommended that the supply name usedshould match the name used for the supply and/or the relevantdevice pins in the datasheet.

Return

Pointer to astructregulator corresponding to the regulatorproducer, or anERR_PTR() encoded negative error number.

voidregulator_put(structregulator*regulator)

“free” the regulator source

Parameters

structregulator*regulator

regulator source

Note

drivers must ensure that all regulator_enable calls made on thisregulator source are balanced by regulator_disable calls prior to callingthis function.

intregulator_register_supply_alias(structdevice*dev,constchar*id,structdevice*alias_dev,constchar*alias_id)

Provide device alias for supply lookup

Parameters

structdevice*dev

device that will be given as the regulator “consumer”

constchar*id

Supply name or regulator ID

structdevice*alias_dev

device that should be used to lookup the supply

constchar*alias_id

Supply name or regulator ID that should be used to lookup thesupply

Description

All lookups for id on dev will instead be conducted for alias_id onalias_dev.

Return

0 on success or a negative error number on failure.

voidregulator_unregister_supply_alias(structdevice*dev,constchar*id)

Remove device alias

Parameters

structdevice*dev

device that will be given as the regulator “consumer”

constchar*id

Supply name or regulator ID

Description

Remove a lookup alias if one exists for id on dev.

intregulator_bulk_register_supply_alias(structdevice*dev,constchar*const*id,structdevice*alias_dev,constchar*const*alias_id,intnum_id)

register multiple aliases

Parameters

structdevice*dev

device that will be given as the regulator “consumer”

constchar*const*id

List of supply names or regulator IDs

structdevice*alias_dev

device that should be used to lookup the supply

constchar*const*alias_id

List of supply names or regulator IDs that should be used tolookup the supply

intnum_id

Number of aliases to register

Description

This helper function allows drivers to register several supplyaliases in one operation. If any of the aliases cannot beregistered any aliases that were registered will be removedbefore returning to the caller.

Return

0 on success or a negative error number on failure.

voidregulator_bulk_unregister_supply_alias(structdevice*dev,constchar*const*id,intnum_id)

unregister multiple aliases

Parameters

structdevice*dev

device that will be given as the regulator “consumer”

constchar*const*id

List of supply names or regulator IDs

intnum_id

Number of aliases to unregister

Description

This helper function allows drivers to unregister several supplyaliases in one operation.

intregulator_enable(structregulator*regulator)

enable regulator output

Parameters

structregulator*regulator

regulator source

Description

Request that the regulator be enabled with the regulator output atthe predefined voltage or current value. Calls toregulator_enable()must be balanced with calls toregulator_disable().

NOTE

the output value can be set by other drivers, boot loader or may behardwired in the regulator.

Return

0 on success or a negative error number on failure.

intregulator_disable(structregulator*regulator)

disable regulator output

Parameters

structregulator*regulator

regulator source

Description

Disable the regulator output voltage or current. Calls toregulator_enable() must be balanced with calls toregulator_disable().

NOTE

this will only disable the regulator output if no other consumerdevices have it enabled, the regulator device supports disabling andmachine constraints permit this operation.

Return

0 on success or a negative error number on failure.

intregulator_force_disable(structregulator*regulator)

force disable regulator output

Parameters

structregulator*regulator

regulator source

Description

Forcibly disable the regulator output voltage or current.

NOTE

thiswill disable the regulator output even if other consumerdevices have it enabled. This should be used for situations when devicedamage will likely occur if the regulator is not disabled (e.g. over temp).

Return

0 on success or a negative error number on failure.

intregulator_disable_deferred(structregulator*regulator,intms)

disable regulator output with delay

Parameters

structregulator*regulator

regulator source

intms

milliseconds until the regulator is disabled

Description

Executeregulator_disable() on the regulator after a delay. Thisis intended for use with devices that require some time to quiesce.

NOTE

this will only disable the regulator output if no other consumerdevices have it enabled, the regulator device supports disabling andmachine constraints permit this operation.

Return

0 on success or a negative error number on failure.

intregulator_is_enabled(structregulator*regulator)

is the regulator output enabled

Parameters

structregulator*regulator

regulator source

Description

Note that the device backing this regulator handle can have multipleusers, so it might be enabled even ifregulator_enable() was nevercalled for this particular source.

Return

Positive if the regulator driver backing the source/clienthas requested that the device be enabled, zero if it hasn’t,else a negative error number.

intregulator_count_voltages(structregulator*regulator)

countregulator_list_voltage() selectors

Parameters

structregulator*regulator

regulator source

Return

Number of selectors forregulator, or negative error number.

Description

Selectors are numbered starting at zero, and typically correspond tobitfields in hardware registers.

intregulator_list_voltage(structregulator*regulator,unsignedselector)

enumerate supported voltages

Parameters

structregulator*regulator

regulator source

unsignedselector

identify voltage to list

Context

can sleep

Return

Voltage forselector that can be passed toregulator_set_voltage(),0 ifselector can’t be used on this system, or a negative errornumber on failure.

structregmap*regulator_get_regmap(structregulator*regulator)

get the regulator’s register map

Parameters

structregulator*regulator

regulator source

Return

Pointer to thestructregmap forregulator, orERR_PTR()encoded -EOPNOTSUPP ifregulator doesn’t use regmap.

intregulator_get_hardware_vsel_register(structregulator*regulator,unsigned*vsel_reg,unsigned*vsel_mask)

get the HW voltage selector register

Parameters

structregulator*regulator

regulator source

unsigned*vsel_reg

voltage selector register, output parameter

unsigned*vsel_mask

mask for voltage selector bitfield, output parameter

Description

Returns the hardware register offset and bitmask used for setting theregulator voltage. This might be useful when configuring voltage-scalinghardware or firmware that can make I2C requests behind the kernel’s back,for example.

On success, the output parametersvsel_reg andvsel_mask are filled inand 0 is returned, otherwise a negative error number is returned.

Return

0 on success, or -EOPNOTSUPP if the regulator does not supportvoltage selectors.

intregulator_list_hardware_vsel(structregulator*regulator,unsignedselector)

get the HW-specific register value for a selector

Parameters

structregulator*regulator

regulator source

unsignedselector

identify voltage to list

Description

Converts the selector to a hardware-specific voltage selector that can bedirectly written to the regulator registers. The address of the voltageregister can be determined by callingregulator_get_hardware_vsel_register.

Return

0 on success, -EINVAL if the selector is outside the supportedrange, or -EOPNOTSUPP if the regulator does not support voltageselectors.

intregulator_hardware_enable(structregulator*regulator,boolenable)

access the HW for enable/disable regulator

Parameters

structregulator*regulator

regulator source

boolenable

true for enable, false for disable

Description

Request that the regulator be enabled/disabled with the regulator output atthe predefined voltage or current value.

Return

0 on success or a negative error number on failure.

unsignedintregulator_get_linear_step(structregulator*regulator)

return the voltage step size between VSEL values

Parameters

structregulator*regulator

regulator source

Return

The voltage step size between VSEL values for linear regulators,or 0 if the regulator isn’t a linear regulator.

intregulator_is_supported_voltage(structregulator*regulator,intmin_uV,intmax_uV)

check if a voltage range can be supported

Parameters

structregulator*regulator

Regulator to check.

intmin_uV

Minimum required voltage in uV.

intmax_uV

Maximum required voltage in uV.

Return

1 if the voltage range is supported, 0 if not, or a negative errornumber ifregulator’s voltage can’t be changed and voltage readbackfailed.

intregulator_set_voltage(structregulator*regulator,intmin_uV,intmax_uV)

set regulator output voltage

Parameters

structregulator*regulator

regulator source

intmin_uV

Minimum required voltage in uV

intmax_uV

Maximum acceptable voltage in uV

Description

Sets a voltage regulator to the desired output voltage. This can be setduring any regulator state. IOW, regulator can be disabled or enabled.

If the regulator is enabled then the voltage will change to the new valueimmediately otherwise if the regulator is disabled the regulator willoutput at the new voltage when enabled.

NOTE

If the regulator is shared between several devices then the lowestrequest voltage that meets the system constraints will be used.Regulator system constraints must be set for this regulator beforecalling this function otherwise this call will fail.

Return

0 on success or a negative error number on failure.

intregulator_set_voltage_time(structregulator*regulator,intold_uV,intnew_uV)

get raise/fall time

Parameters

structregulator*regulator

regulator source

intold_uV

starting voltage in microvolts

intnew_uV

target voltage in microvolts

Description

Provided with the starting and ending voltage, this function attempts tocalculate the time in microseconds required to rise or fall to this newvoltage.

Return

ramp time in microseconds, or a negative error number if calculation failed.

intregulator_set_voltage_time_sel(structregulator_dev*rdev,unsignedintold_selector,unsignedintnew_selector)

get raise/fall time

Parameters

structregulator_dev*rdev

regulator source device

unsignedintold_selector

selector for starting voltage

unsignedintnew_selector

selector for target voltage

Description

Provided with the starting and target voltage selectors, this functionreturns time in microseconds required to rise or fall to this new voltage

Drivers providing ramp_delay in regulation_constraints can use this as theirset_voltage_time_sel() operation.

Return

ramp time in microseconds, or a negative error number if calculation failed.

intregulator_sync_voltage(structregulator*regulator)

re-apply last regulator output voltage

Parameters

structregulator*regulator

regulator source

Description

Re-apply the last configured voltage. This is intended to be usedwhere some external control source the consumer is cooperating withhas caused the configured voltage to change.

Return

0 on success or a negative error number on failure.

intregulator_get_voltage(structregulator*regulator)

get regulator output voltage

Parameters

structregulator*regulator

regulator source

Return

Current regulator voltage in uV, or a negative error number on failure.

NOTE

If the regulator is disabled it will return the voltage value. Thisfunction should not be used to determine regulator state.

intregulator_set_current_limit(structregulator*regulator,intmin_uA,intmax_uA)

set regulator output current limit

Parameters

structregulator*regulator

regulator source

intmin_uA

Minimum supported current in uA

intmax_uA

Maximum supported current in uA

Description

Sets current sink to the desired output current. This can be set duringany regulator state. IOW, regulator can be disabled or enabled.

If the regulator is enabled then the current will change to the new valueimmediately otherwise if the regulator is disabled the regulator willoutput at the new current when enabled.

NOTE

Regulator system constraints must be set for this regulator beforecalling this function otherwise this call will fail.

Return

0 on success or a negative error number on failure.

intregulator_get_current_limit(structregulator*regulator)

get regulator output current

Parameters

structregulator*regulator

regulator source

Return

Current supplied by the specified current sink in uA,or a negative error number on failure.

NOTE

If the regulator is disabled it will return the current value. Thisfunction should not be used to determine regulator state.

intregulator_get_unclaimed_power_budget(structregulator*regulator)

get regulator unclaimed power budget

Parameters

structregulator*regulator

regulator source

Return

Unclaimed power budget of the regulator in mW.

intregulator_request_power_budget(structregulator*regulator,unsignedintpw_req)

request power budget on a regulator

Parameters

structregulator*regulator

regulator source

unsignedintpw_req

Power requested

Return

0 on success or a negative error number on failure.

voidregulator_free_power_budget(structregulator*regulator,unsignedintpw)

free power budget on a regulator

Parameters

structregulator*regulator

regulator source

unsignedintpw

Power to be released.

Return

Power budget of the regulator in mW.

intregulator_set_mode(structregulator*regulator,unsignedintmode)

set regulator operating mode

Parameters

structregulator*regulator

regulator source

unsignedintmode

operating mode - one of the REGULATOR_MODE constants

Description

Set regulator operating mode to increase regulator efficiency or improveregulation performance.

NOTE

Regulator system constraints must be set for this regulator beforecalling this function otherwise this call will fail.

Return

0 on success or a negative error number on failure.

unsignedintregulator_get_mode(structregulator*regulator)

get regulator operating mode

Parameters

structregulator*regulator

regulator source

Description

Get the current regulator operating mode.

Return

Current operating mode asREGULATOR_MODE_* values,or a negative error number on failure.

intregulator_get_error_flags(structregulator*regulator,unsignedint*flags)

get regulator error information

Parameters

structregulator*regulator

regulator source

unsignedint*flags

pointer to store error flags

Description

Get the current regulator error information.

Return

0 on success or a negative error number on failure.

intregulator_set_load(structregulator*regulator,intuA_load)

set regulator load

Parameters

structregulator*regulator

regulator source

intuA_load

load current

Description

Notifies the regulator core of a new device load. This is then used byDRMS (if enabled by constraints) to set the most efficient regulatoroperating mode for the new regulator loading.

Consumer devices notify their supply regulator of the maximum powerthey will require (can be taken from device datasheet in the powerconsumption tables) when they change operational status and hence powerstate. Examples of operational state changes that can affect powerconsumption are :-

o Device is opened / closed.o Device I/O is about to begin or has just finished.o Device is idling in between work.

This information is also exported via sysfs to userspace.

DRMS will sum the total requested load on the regulator and changeto the most efficient operating mode if platform constraints allow.

NOTE

when a regulator consumer requests to have a regulatordisabled then any load that consumer requested no longer countstoward the total requested load. If the regulator is re-enabledthen the previously requested load will start counting again.

If a regulator is an always-on regulator then an individual consumer’sload will still be removed if that consumer is fully disabled.

Return

0 on success or a negative error number on failure.

intregulator_allow_bypass(structregulator*regulator,boolenable)

allow the regulator to go into bypass mode

Parameters

structregulator*regulator

Regulator to configure

boolenable

enable or disable bypass mode

Description

Allow the regulator to go into bypass mode if all other consumersfor the regulator also enable bypass mode and the machineconstraints allow this. Bypass mode means that the regulator issimply passing the input directly to the output with no regulation.

Return

0 on success or if changing bypass is not possible, ora negative error number on failure.

intregulator_register_notifier(structregulator*regulator,structnotifier_block*nb)

register regulator event notifier

Parameters

structregulator*regulator

regulator source

structnotifier_block*nb

notifier block

Description

Register notifier block to receive regulator events.

Return

0 on success or a negative error number on failure.

intregulator_unregister_notifier(structregulator*regulator,structnotifier_block*nb)

unregister regulator event notifier

Parameters

structregulator*regulator

regulator source

structnotifier_block*nb

notifier block

Description

Unregister regulator event notifier block.

Return

0 on success or a negative error number on failure.

intregulator_bulk_get(structdevice*dev,intnum_consumers,structregulator_bulk_data*consumers)

get multiple regulator consumers

Parameters

structdevice*dev

Device to supply

intnum_consumers

Number of consumers to register

structregulator_bulk_data*consumers

Configuration of consumers; clients are stored here.

Description

This helper function allows drivers to get several regulatorconsumers in one operation. If any of the regulators cannot beacquired then any regulators that were allocated will be freedbefore returning to the caller.

Return

0 on success or a negative error number on failure.

intregulator_bulk_enable(intnum_consumers,structregulator_bulk_data*consumers)

enable multiple regulator consumers

Parameters

intnum_consumers

Number of consumers

structregulator_bulk_data*consumers

Consumer data; clients are stored here.

Description

This convenience API allows consumers to enable multiple regulatorclients in a single API call. If any consumers cannot be enabledthen any others that were enabled will be disabled again prior toreturn.

Return

0 on success or a negative error number on failure.

intregulator_bulk_disable(intnum_consumers,structregulator_bulk_data*consumers)

disable multiple regulator consumers

Parameters

intnum_consumers

Number of consumers

structregulator_bulk_data*consumers

Consumer data; clients are stored here.

Description

This convenience API allows consumers to disable multiple regulatorclients in a single API call. If any consumers cannot be disabledthen any others that were disabled will be enabled again prior toreturn.

Return

0 on success or a negative error number on failure.

intregulator_bulk_force_disable(intnum_consumers,structregulator_bulk_data*consumers)

force disable multiple regulator consumers

Parameters

intnum_consumers

Number of consumers

structregulator_bulk_data*consumers

Consumer data; clients are stored here.

Description

This convenience API allows consumers to forcibly disable multiple regulatorclients in a single API call.

NOTE

This should be used for situations when device damage willlikely occur if the regulators are not disabled (e.g. over temp).Although regulator_force_disable function call for some consumers canreturn error numbers, the function is called for all consumers.

Return

0 on success or a negative error number on failure.

voidregulator_bulk_free(intnum_consumers,structregulator_bulk_data*consumers)

free multiple regulator consumers

Parameters

intnum_consumers

Number of consumers

structregulator_bulk_data*consumers

Consumer data; clients are stored here.

Description

This convenience API allows consumers to free multiple regulatorclients in a single API call.

intregulator_notifier_call_chain(structregulator_dev*rdev,unsignedlongevent,void*data)

call regulator event notifier

Parameters

structregulator_dev*rdev

regulator source

unsignedlongevent

notifier block

void*data

callback-specific data.

Description

Called by regulator drivers to notify clients a regulator event hasoccurred.

Return

NOTIFY_DONE.

intregulator_mode_to_status(unsignedintmode)

convert a regulator mode into a status

Parameters

unsignedintmode

Mode to convert

Description

Convert a regulator mode into a status.

Return

REGULATOR_STATUS_* value corresponding to given mode.

structregulator_dev*regulator_register(structdevice*dev,conststructregulator_desc*regulator_desc,conststructregulator_config*cfg)

register regulator

Parameters

structdevice*dev

the device that drive the regulator

conststructregulator_desc*regulator_desc

regulator to register

conststructregulator_config*cfg

runtime configuration for regulator

Description

Called by regulator drivers to register a regulator.

Return

Pointer to a validstructregulator_dev on success oranERR_PTR() encoded negative error number on failure.

voidregulator_unregister(structregulator_dev*rdev)

unregister regulator

Parameters

structregulator_dev*rdev

regulator to unregister

Description

Called by regulator drivers to unregister a regulator.

voidregulator_has_full_constraints(void)

the system has fully specified constraints

Parameters

void

no arguments

Description

Calling this function will cause the regulator API to disable allregulators which have a zero use count and don’t have an always_onconstraint in a late_initcall.

The intention is that this will become the default behaviour in afuture kernel release so users are encouraged to use this facilitynow.

void*rdev_get_drvdata(structregulator_dev*rdev)

get rdev regulator driver data

Parameters

structregulator_dev*rdev

regulator

Description

Get rdev regulator driver private data. This call can be used in theregulator driver context.

Return

Pointer to regulator driver private data.

void*regulator_get_drvdata(structregulator*regulator)

get regulator driver data

Parameters

structregulator*regulator

regulator

Description

Get regulator driver private data. This call can be used in the consumerdriver context when non API regulator specific functions need to be called.

Return

Pointer to regulator driver private data.

voidregulator_set_drvdata(structregulator*regulator,void*data)

set regulator driver data

Parameters

structregulator*regulator

regulator

void*data

data

intrdev_get_id(structregulator_dev*rdev)

get regulator ID

Parameters

structregulator_dev*rdev

regulator

Return

Regulator ID forrdev.