18c2ecf20Sopenharmony_ci============================================= 28c2ecf20Sopenharmony_ciLinux voltage and current regulator framework 38c2ecf20Sopenharmony_ci============================================= 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciAbout 68c2ecf20Sopenharmony_ci===== 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciThis framework is designed to provide a standard kernel interface to control 98c2ecf20Sopenharmony_civoltage and current regulators. 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ciThe intention is to allow systems to dynamically control regulator power output 128c2ecf20Sopenharmony_ciin order to save power and prolong battery life. This applies to both voltage 138c2ecf20Sopenharmony_ciregulators (where voltage output is controllable) and current sinks (where 148c2ecf20Sopenharmony_cicurrent limit is controllable). 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci(C) 2008 Wolfson Microelectronics PLC. 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ciAuthor: Liam Girdwood <lrg@slimlogic.co.uk> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ciNomenclature 228c2ecf20Sopenharmony_ci============ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ciSome terms used in this document: 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci - Regulator 278c2ecf20Sopenharmony_ci - Electronic device that supplies power to other devices. 288c2ecf20Sopenharmony_ci Most regulators can enable and disable their output while 298c2ecf20Sopenharmony_ci some can control their output voltage and or current. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci Input Voltage -> Regulator -> Output Voltage 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci - PMIC 358c2ecf20Sopenharmony_ci - Power Management IC. An IC that contains numerous 368c2ecf20Sopenharmony_ci regulators and often contains other subsystems. 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci - Consumer 408c2ecf20Sopenharmony_ci - Electronic device that is supplied power by a regulator. 418c2ecf20Sopenharmony_ci Consumers can be classified into two types:- 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci Static: consumer does not change its supply voltage or 448c2ecf20Sopenharmony_ci current limit. It only needs to enable or disable its 458c2ecf20Sopenharmony_ci power supply. Its supply voltage is set by the hardware, 468c2ecf20Sopenharmony_ci bootloader, firmware or kernel board initialisation code. 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci Dynamic: consumer needs to change its supply voltage or 498c2ecf20Sopenharmony_ci current limit to meet operation demands. 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci - Power Domain 538c2ecf20Sopenharmony_ci - Electronic circuit that is supplied its input power by the 548c2ecf20Sopenharmony_ci output power of a regulator, switch or by another power 558c2ecf20Sopenharmony_ci domain. 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci The supply regulator may be behind a switch(s). i.e.:: 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci Regulator -+-> Switch-1 -+-> Switch-2 --> [Consumer A] 608c2ecf20Sopenharmony_ci | | 618c2ecf20Sopenharmony_ci | +-> [Consumer B], [Consumer C] 628c2ecf20Sopenharmony_ci | 638c2ecf20Sopenharmony_ci +-> [Consumer D], [Consumer E] 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci That is one regulator and three power domains: 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci - Domain 1: Switch-1, Consumers D & E. 688c2ecf20Sopenharmony_ci - Domain 2: Switch-2, Consumers B & C. 698c2ecf20Sopenharmony_ci - Domain 3: Consumer A. 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci and this represents a "supplies" relationship: 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci Domain-1 --> Domain-2 --> Domain-3. 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci A power domain may have regulators that are supplied power 768c2ecf20Sopenharmony_ci by other regulators. i.e.:: 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci Regulator-1 -+-> Regulator-2 -+-> [Consumer A] 798c2ecf20Sopenharmony_ci | 808c2ecf20Sopenharmony_ci +-> [Consumer B] 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci This gives us two regulators and two power domains: 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci - Domain 1: Regulator-2, Consumer B. 858c2ecf20Sopenharmony_ci - Domain 2: Consumer A. 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci and a "supplies" relationship: 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci Domain-1 --> Domain-2 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci - Constraints 938c2ecf20Sopenharmony_ci - Constraints are used to define power levels for performance 948c2ecf20Sopenharmony_ci and hardware protection. Constraints exist at three levels: 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci Regulator Level: This is defined by the regulator hardware 978c2ecf20Sopenharmony_ci operating parameters and is specified in the regulator 988c2ecf20Sopenharmony_ci datasheet. i.e. 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci - voltage output is in the range 800mV -> 3500mV. 1018c2ecf20Sopenharmony_ci - regulator current output limit is 20mA @ 5V but is 1028c2ecf20Sopenharmony_ci 10mA @ 10V. 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci Power Domain Level: This is defined in software by kernel 1058c2ecf20Sopenharmony_ci level board initialisation code. It is used to constrain a 1068c2ecf20Sopenharmony_ci power domain to a particular power range. i.e. 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci - Domain-1 voltage is 3300mV 1098c2ecf20Sopenharmony_ci - Domain-2 voltage is 1400mV -> 1600mV 1108c2ecf20Sopenharmony_ci - Domain-3 current limit is 0mA -> 20mA. 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci Consumer Level: This is defined by consumer drivers 1138c2ecf20Sopenharmony_ci dynamically setting voltage or current limit levels. 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci e.g. a consumer backlight driver asks for a current increase 1168c2ecf20Sopenharmony_ci from 5mA to 10mA to increase LCD illumination. This passes 1178c2ecf20Sopenharmony_ci to through the levels as follows :- 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci Consumer: need to increase LCD brightness. Lookup and 1208c2ecf20Sopenharmony_ci request next current mA value in brightness table (the 1218c2ecf20Sopenharmony_ci consumer driver could be used on several different 1228c2ecf20Sopenharmony_ci personalities based upon the same reference device). 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci Power Domain: is the new current limit within the domain 1258c2ecf20Sopenharmony_ci operating limits for this domain and system state (e.g. 1268c2ecf20Sopenharmony_ci battery power, USB power) 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci Regulator Domains: is the new current limit within the 1298c2ecf20Sopenharmony_ci regulator operating parameters for input/output voltage. 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci If the regulator request passes all the constraint tests 1328c2ecf20Sopenharmony_ci then the new regulator value is applied. 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ciDesign 1368c2ecf20Sopenharmony_ci====== 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ciThe framework is designed and targeted at SoC based devices but may also be 1398c2ecf20Sopenharmony_cirelevant to non SoC devices and is split into the following four interfaces:- 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci 1. Consumer driver interface. 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci This uses a similar API to the kernel clock interface in that consumer 1458c2ecf20Sopenharmony_ci drivers can get and put a regulator (like they can with clocks atm) and 1468c2ecf20Sopenharmony_ci get/set voltage, current limit, mode, enable and disable. This should 1478c2ecf20Sopenharmony_ci allow consumers complete control over their supply voltage and current 1488c2ecf20Sopenharmony_ci limit. This also compiles out if not in use so drivers can be reused in 1498c2ecf20Sopenharmony_ci systems with no regulator based power control. 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci See Documentation/power/regulator/consumer.rst 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci 2. Regulator driver interface. 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci This allows regulator drivers to register their regulators and provide 1568c2ecf20Sopenharmony_ci operations to the core. It also has a notifier call chain for propagating 1578c2ecf20Sopenharmony_ci regulator events to clients. 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci See Documentation/power/regulator/regulator.rst 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci 3. Machine interface. 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci This interface is for machine specific code and allows the creation of 1648c2ecf20Sopenharmony_ci voltage/current domains (with constraints) for each regulator. It can 1658c2ecf20Sopenharmony_ci provide regulator constraints that will prevent device damage through 1668c2ecf20Sopenharmony_ci overvoltage or overcurrent caused by buggy client drivers. It also 1678c2ecf20Sopenharmony_ci allows the creation of a regulator tree whereby some regulators are 1688c2ecf20Sopenharmony_ci supplied by others (similar to a clock tree). 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci See Documentation/power/regulator/machine.rst 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci 4. Userspace ABI. 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci The framework also exports a lot of useful voltage/current/opmode data to 1758c2ecf20Sopenharmony_ci userspace via sysfs. This could be used to help monitor device power 1768c2ecf20Sopenharmony_ci consumption and status. 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci See Documentation/ABI/testing/sysfs-class-regulator 179