162306a36Sopenharmony_ci=============================================
262306a36Sopenharmony_ciLinux voltage and current regulator framework
362306a36Sopenharmony_ci=============================================
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciAbout
662306a36Sopenharmony_ci=====
762306a36Sopenharmony_ci
862306a36Sopenharmony_ciThis framework is designed to provide a standard kernel interface to control
962306a36Sopenharmony_civoltage and current regulators.
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ciThe intention is to allow systems to dynamically control regulator power output
1262306a36Sopenharmony_ciin order to save power and prolong battery life. This applies to both voltage
1362306a36Sopenharmony_ciregulators (where voltage output is controllable) and current sinks (where
1462306a36Sopenharmony_cicurrent limit is controllable).
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci(C) 2008  Wolfson Microelectronics PLC.
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ciAuthor: Liam Girdwood <lrg@slimlogic.co.uk>
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ciNomenclature
2262306a36Sopenharmony_ci============
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ciSome terms used in this document:
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci  - Regulator
2762306a36Sopenharmony_ci                 - Electronic device that supplies power to other devices.
2862306a36Sopenharmony_ci                   Most regulators can enable and disable their output while
2962306a36Sopenharmony_ci                   some can control their output voltage and or current.
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci                   Input Voltage -> Regulator -> Output Voltage
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci  - PMIC
3562306a36Sopenharmony_ci                 - Power Management IC. An IC that contains numerous
3662306a36Sopenharmony_ci                   regulators and often contains other subsystems.
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci  - Consumer
4062306a36Sopenharmony_ci                 - Electronic device that is supplied power by a regulator.
4162306a36Sopenharmony_ci                   Consumers can be classified into two types:-
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci                   Static: consumer does not change its supply voltage or
4462306a36Sopenharmony_ci                   current limit. It only needs to enable or disable its
4562306a36Sopenharmony_ci                   power supply. Its supply voltage is set by the hardware,
4662306a36Sopenharmony_ci                   bootloader, firmware or kernel board initialisation code.
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci                   Dynamic: consumer needs to change its supply voltage or
4962306a36Sopenharmony_ci                   current limit to meet operation demands.
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci  - Power Domain
5362306a36Sopenharmony_ci                 - Electronic circuit that is supplied its input power by the
5462306a36Sopenharmony_ci                   output power of a regulator, switch or by another power
5562306a36Sopenharmony_ci                   domain.
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci                   The supply regulator may be behind a switch(s). i.e.::
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci                     Regulator -+-> Switch-1 -+-> Switch-2 --> [Consumer A]
6062306a36Sopenharmony_ci                                |             |
6162306a36Sopenharmony_ci                                |             +-> [Consumer B], [Consumer C]
6262306a36Sopenharmony_ci                                |
6362306a36Sopenharmony_ci                                +-> [Consumer D], [Consumer E]
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci                   That is one regulator and three power domains:
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci                   - Domain 1: Switch-1, Consumers D & E.
6862306a36Sopenharmony_ci                   - Domain 2: Switch-2, Consumers B & C.
6962306a36Sopenharmony_ci                   - Domain 3: Consumer A.
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci                   and this represents a "supplies" relationship:
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci                   Domain-1 --> Domain-2 --> Domain-3.
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci                   A power domain may have regulators that are supplied power
7662306a36Sopenharmony_ci                   by other regulators. i.e.::
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci                     Regulator-1 -+-> Regulator-2 -+-> [Consumer A]
7962306a36Sopenharmony_ci                                  |
8062306a36Sopenharmony_ci                                  +-> [Consumer B]
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci                   This gives us two regulators and two power domains:
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci                   - Domain 1: Regulator-2, Consumer B.
8562306a36Sopenharmony_ci                   - Domain 2: Consumer A.
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci                   and a "supplies" relationship:
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci                   Domain-1 --> Domain-2
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci  - Constraints
9362306a36Sopenharmony_ci                 - Constraints are used to define power levels for performance
9462306a36Sopenharmony_ci                   and hardware protection. Constraints exist at three levels:
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci                   Regulator Level: This is defined by the regulator hardware
9762306a36Sopenharmony_ci                   operating parameters and is specified in the regulator
9862306a36Sopenharmony_ci                   datasheet. i.e.
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci                     - voltage output is in the range 800mV -> 3500mV.
10162306a36Sopenharmony_ci                     - regulator current output limit is 20mA @ 5V but is
10262306a36Sopenharmony_ci                       10mA @ 10V.
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci                   Power Domain Level: This is defined in software by kernel
10562306a36Sopenharmony_ci                   level board initialisation code. It is used to constrain a
10662306a36Sopenharmony_ci                   power domain to a particular power range. i.e.
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci                     - Domain-1 voltage is 3300mV
10962306a36Sopenharmony_ci                     - Domain-2 voltage is 1400mV -> 1600mV
11062306a36Sopenharmony_ci                     - Domain-3 current limit is 0mA -> 20mA.
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci                   Consumer Level: This is defined by consumer drivers
11362306a36Sopenharmony_ci                   dynamically setting voltage or current limit levels.
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci                   e.g. a consumer backlight driver asks for a current increase
11662306a36Sopenharmony_ci                   from 5mA to 10mA to increase LCD illumination. This passes
11762306a36Sopenharmony_ci                   to through the levels as follows :-
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci                   Consumer: need to increase LCD brightness. Lookup and
12062306a36Sopenharmony_ci                   request next current mA value in brightness table (the
12162306a36Sopenharmony_ci                   consumer driver could be used on several different
12262306a36Sopenharmony_ci                   personalities based upon the same reference device).
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci                   Power Domain: is the new current limit within the domain
12562306a36Sopenharmony_ci                   operating limits for this domain and system state (e.g.
12662306a36Sopenharmony_ci                   battery power, USB power)
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci                   Regulator Domains: is the new current limit within the
12962306a36Sopenharmony_ci                   regulator operating parameters for input/output voltage.
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci                   If the regulator request passes all the constraint tests
13262306a36Sopenharmony_ci                   then the new regulator value is applied.
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ciDesign
13662306a36Sopenharmony_ci======
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ciThe framework is designed and targeted at SoC based devices but may also be
13962306a36Sopenharmony_cirelevant to non SoC devices and is split into the following four interfaces:-
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci   1. Consumer driver interface.
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci      This uses a similar API to the kernel clock interface in that consumer
14562306a36Sopenharmony_ci      drivers can get and put a regulator (like they can with clocks atm) and
14662306a36Sopenharmony_ci      get/set voltage, current limit, mode, enable and disable. This should
14762306a36Sopenharmony_ci      allow consumers complete control over their supply voltage and current
14862306a36Sopenharmony_ci      limit. This also compiles out if not in use so drivers can be reused in
14962306a36Sopenharmony_ci      systems with no regulator based power control.
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci        See Documentation/power/regulator/consumer.rst
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci   2. Regulator driver interface.
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci      This allows regulator drivers to register their regulators and provide
15662306a36Sopenharmony_ci      operations to the core. It also has a notifier call chain for propagating
15762306a36Sopenharmony_ci      regulator events to clients.
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci        See Documentation/power/regulator/regulator.rst
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci   3. Machine interface.
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci      This interface is for machine specific code and allows the creation of
16462306a36Sopenharmony_ci      voltage/current domains (with constraints) for each regulator. It can
16562306a36Sopenharmony_ci      provide regulator constraints that will prevent device damage through
16662306a36Sopenharmony_ci      overvoltage or overcurrent caused by buggy client drivers. It also
16762306a36Sopenharmony_ci      allows the creation of a regulator tree whereby some regulators are
16862306a36Sopenharmony_ci      supplied by others (similar to a clock tree).
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci        See Documentation/power/regulator/machine.rst
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_ci   4. Userspace ABI.
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci      The framework also exports a lot of useful voltage/current/opmode data to
17562306a36Sopenharmony_ci      userspace via sysfs. This could be used to help monitor device power
17662306a36Sopenharmony_ci      consumption and status.
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci        See Documentation/ABI/testing/sysfs-class-regulator
179