2019-06-13 10:10:36 +00:00
|
|
|
===================================
|
2008-04-30 16:19:02 +00:00
|
|
|
Regulator Consumer Driver Interface
|
|
|
|
===================================
|
|
|
|
|
|
|
|
This text describes the regulator interface for consumer device drivers.
|
|
|
|
Please see overview.txt for a description of the terms used in this text.
|
|
|
|
|
|
|
|
|
|
|
|
1. Consumer Regulator Access (static & dynamic drivers)
|
|
|
|
=======================================================
|
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
A consumer driver can get access to its supply regulator by calling ::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
regulator = regulator_get(dev, "Vcc");
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2010-04-22 22:08:02 +00:00
|
|
|
The consumer passes in its struct device pointer and power supply ID. The core
|
2008-04-30 16:19:02 +00:00
|
|
|
then finds the correct regulator by consulting a machine specific lookup table.
|
|
|
|
If the lookup is successful then this call will return a pointer to the struct
|
|
|
|
regulator that supplies this consumer.
|
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
To release the regulator the consumer driver should call ::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
regulator_put(regulator);
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
Consumers can be supplied by more than one regulator e.g. codec consumer with
|
2019-06-13 10:10:36 +00:00
|
|
|
analog and digital supplies ::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
digital = regulator_get(dev, "Vcc"); /* digital core */
|
|
|
|
analog = regulator_get(dev, "Avdd"); /* analog */
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
The regulator access functions regulator_get() and regulator_put() will
|
|
|
|
usually be called in your device drivers probe() and remove() respectively.
|
|
|
|
|
|
|
|
|
|
|
|
2. Regulator Output Enable & Disable (static & dynamic drivers)
|
2019-06-13 10:10:36 +00:00
|
|
|
===============================================================
|
|
|
|
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
A consumer can enable its power supply by calling::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_enable(regulator);
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
NOTE:
|
|
|
|
The supply may already be enabled before regulator_enabled() is called.
|
|
|
|
This may happen if the consumer shares the regulator or the regulator has been
|
|
|
|
previously enabled by bootloader or kernel board initialization code.
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
A consumer can determine if a regulator is enabled by calling::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_is_enabled(regulator);
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
This will return > zero when the regulator is enabled.
|
|
|
|
|
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
A consumer can disable its supply when no longer needed by calling::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_disable(regulator);
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
NOTE:
|
|
|
|
This may not disable the supply if it's shared with other consumers. The
|
|
|
|
regulator will only be disabled when the enabled reference count is zero.
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
Finally, a regulator can be forcefully disabled in the case of an emergency::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_force_disable(regulator);
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
NOTE:
|
|
|
|
this will immediately and forcefully shutdown the regulator output. All
|
|
|
|
consumers will be powered off.
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
3. Regulator Voltage Control & Status (dynamic drivers)
|
2019-06-13 10:10:36 +00:00
|
|
|
=======================================================
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
Some consumer drivers need to be able to dynamically change their supply
|
|
|
|
voltage to match system operating points. e.g. CPUfreq drivers can scale
|
|
|
|
voltage along with frequency to save power, SD drivers may need to select the
|
|
|
|
correct card voltage, etc.
|
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
Consumers can control their supply voltage by calling::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_set_voltage(regulator, min_uV, max_uV);
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
Where min_uV and max_uV are the minimum and maximum acceptable voltages in
|
|
|
|
microvolts.
|
|
|
|
|
|
|
|
NOTE: this can be called when the regulator is enabled or disabled. If called
|
|
|
|
when enabled, then the voltage changes instantly, otherwise the voltage
|
|
|
|
configuration changes and the voltage is physically set when the regulator is
|
|
|
|
next enabled.
|
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
The regulators configured voltage output can be found by calling::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_get_voltage(regulator);
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
NOTE:
|
|
|
|
get_voltage() will return the configured output voltage whether the
|
|
|
|
regulator is enabled or disabled and should NOT be used to determine regulator
|
|
|
|
output state. However this can be used in conjunction with is_enabled() to
|
|
|
|
determine the regulator physical output voltage.
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
4. Regulator Current Limit Control & Status (dynamic drivers)
|
2019-06-13 10:10:36 +00:00
|
|
|
=============================================================
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
Some consumer drivers need to be able to dynamically change their supply
|
|
|
|
current limit to match system operating points. e.g. LCD backlight driver can
|
|
|
|
change the current limit to vary the backlight brightness, USB drivers may want
|
|
|
|
to set the limit to 500mA when supplying power.
|
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
Consumers can control their supply current limit by calling::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_set_current_limit(regulator, min_uA, max_uA);
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
Where min_uA and max_uA are the minimum and maximum acceptable current limit in
|
|
|
|
microamps.
|
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
NOTE:
|
|
|
|
this can be called when the regulator is enabled or disabled. If called
|
|
|
|
when enabled, then the current limit changes instantly, otherwise the current
|
|
|
|
limit configuration changes and the current limit is physically set when the
|
|
|
|
regulator is next enabled.
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
A regulators current limit can be found by calling::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_get_current_limit(regulator);
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
NOTE:
|
|
|
|
get_current_limit() will return the current limit whether the regulator
|
|
|
|
is enabled or disabled and should not be used to determine regulator current
|
|
|
|
load.
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
5. Regulator Operating Mode Control & Status (dynamic drivers)
|
2019-06-13 10:10:36 +00:00
|
|
|
==============================================================
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
Some consumers can further save system power by changing the operating mode of
|
|
|
|
their supply regulator to be more efficient when the consumers operating state
|
|
|
|
changes. e.g. consumer driver is idle and subsequently draws less current
|
|
|
|
|
|
|
|
Regulator operating mode can be changed indirectly or directly.
|
|
|
|
|
|
|
|
Indirect operating mode control.
|
|
|
|
--------------------------------
|
|
|
|
Consumer drivers can request a change in their supply regulator operating mode
|
2019-06-13 10:10:36 +00:00
|
|
|
by calling::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_set_load(struct regulator *regulator, int load_uA);
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
This will cause the core to recalculate the total load on the regulator (based
|
2010-04-22 22:08:02 +00:00
|
|
|
on all its consumers) and change operating mode (if necessary and permitted)
|
2008-04-30 16:19:02 +00:00
|
|
|
to best match the current operating load.
|
|
|
|
|
2014-08-25 08:47:51 +00:00
|
|
|
The load_uA value can be determined from the consumer's datasheet. e.g. most
|
|
|
|
datasheets have tables showing the maximum current consumed in certain
|
|
|
|
situations.
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
Most consumers will use indirect operating mode control since they have no
|
|
|
|
knowledge of the regulator or whether the regulator is shared with other
|
|
|
|
consumers.
|
|
|
|
|
|
|
|
Direct operating mode control.
|
|
|
|
------------------------------
|
2019-06-13 10:10:36 +00:00
|
|
|
|
2008-04-30 16:19:02 +00:00
|
|
|
Bespoke or tightly coupled drivers may want to directly control regulator
|
|
|
|
operating mode depending on their operating point. This can be achieved by
|
2019-06-13 10:10:36 +00:00
|
|
|
calling::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_set_mode(struct regulator *regulator, unsigned int mode);
|
|
|
|
unsigned int regulator_get_mode(struct regulator *regulator);
|
2008-04-30 16:19:02 +00:00
|
|
|
|
|
|
|
Direct mode will only be used by consumers that *know* about the regulator and
|
|
|
|
are not sharing the regulator with other consumers.
|
|
|
|
|
|
|
|
|
|
|
|
6. Regulator Events
|
|
|
|
===================
|
2019-06-13 10:10:36 +00:00
|
|
|
|
2008-04-30 16:19:02 +00:00
|
|
|
Regulators can notify consumers of external events. Events could be received by
|
|
|
|
consumers under regulator stress or failure conditions.
|
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
Consumers can register interest in regulator events by calling::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_register_notifier(struct regulator *regulator,
|
|
|
|
struct notifier_block *nb);
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
Consumers can unregister interest by calling::
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_unregister_notifier(struct regulator *regulator,
|
|
|
|
struct notifier_block *nb);
|
2008-04-30 16:19:02 +00:00
|
|
|
|
2009-04-27 13:06:31 +00:00
|
|
|
Regulators use the kernel notifier framework to send event to their interested
|
2008-04-30 16:19:02 +00:00
|
|
|
consumers.
|
2014-07-21 15:38:48 +00:00
|
|
|
|
|
|
|
7. Regulator Direct Register Access
|
|
|
|
===================================
|
2019-06-13 10:10:36 +00:00
|
|
|
|
2014-07-21 15:38:48 +00:00
|
|
|
Some kinds of power management hardware or firmware are designed such that
|
|
|
|
they need to do low-level hardware access to regulators, with no involvement
|
|
|
|
from the kernel. Examples of such devices are:
|
|
|
|
|
|
|
|
- clocksource with a voltage-controlled oscillator and control logic to change
|
|
|
|
the supply voltage over I2C to achieve a desired output clock rate
|
|
|
|
- thermal management firmware that can issue an arbitrary I2C transaction to
|
|
|
|
perform system poweroff during overtemperature conditions
|
|
|
|
|
|
|
|
To set up such a device/firmware, various parameters like I2C address of the
|
|
|
|
regulator, addresses of various regulator registers etc. need to be configured
|
|
|
|
to it. The regulator framework provides the following helpers for querying
|
|
|
|
these details.
|
|
|
|
|
|
|
|
Bus-specific details, like I2C addresses or transfer rates are handled by the
|
2019-06-13 10:10:36 +00:00
|
|
|
regmap framework. To get the regulator's regmap (if supported), use::
|
2014-07-21 15:38:48 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
struct regmap *regulator_get_regmap(struct regulator *regulator);
|
2014-07-21 15:38:48 +00:00
|
|
|
|
|
|
|
To obtain the hardware register offset and bitmask for the regulator's voltage
|
2019-06-13 10:10:36 +00:00
|
|
|
selector register, use::
|
2014-07-21 15:38:48 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_get_hardware_vsel_register(struct regulator *regulator,
|
|
|
|
unsigned *vsel_reg,
|
|
|
|
unsigned *vsel_mask);
|
2014-07-21 15:38:48 +00:00
|
|
|
|
|
|
|
To convert a regulator framework voltage selector code (used by
|
|
|
|
regulator_list_voltage) to a hardware-specific voltage selector that can be
|
2019-06-13 10:10:36 +00:00
|
|
|
directly written to the voltage selector register, use::
|
2014-07-21 15:38:48 +00:00
|
|
|
|
2019-06-13 10:10:36 +00:00
|
|
|
int regulator_list_hardware_vsel(struct regulator *regulator,
|
|
|
|
unsigned selector);
|