1*4882a593Smuzhiyun============================================= 2*4882a593SmuzhiyunLinux voltage and current regulator framework 3*4882a593Smuzhiyun============================================= 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunAbout 6*4882a593Smuzhiyun===== 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunThis framework is designed to provide a standard kernel interface to control 9*4882a593Smuzhiyunvoltage and current regulators. 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunThe intention is to allow systems to dynamically control regulator power output 12*4882a593Smuzhiyunin order to save power and prolong battery life. This applies to both voltage 13*4882a593Smuzhiyunregulators (where voltage output is controllable) and current sinks (where 14*4882a593Smuzhiyuncurrent limit is controllable). 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun(C) 2008 Wolfson Microelectronics PLC. 17*4882a593Smuzhiyun 18*4882a593SmuzhiyunAuthor: Liam Girdwood <lrg@slimlogic.co.uk> 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun 21*4882a593SmuzhiyunNomenclature 22*4882a593Smuzhiyun============ 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunSome terms used in this document: 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun - Regulator 27*4882a593Smuzhiyun - Electronic device that supplies power to other devices. 28*4882a593Smuzhiyun Most regulators can enable and disable their output while 29*4882a593Smuzhiyun some can control their output voltage and or current. 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun Input Voltage -> Regulator -> Output Voltage 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun - PMIC 35*4882a593Smuzhiyun - Power Management IC. An IC that contains numerous 36*4882a593Smuzhiyun regulators and often contains other subsystems. 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun - Consumer 40*4882a593Smuzhiyun - Electronic device that is supplied power by a regulator. 41*4882a593Smuzhiyun Consumers can be classified into two types:- 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun Static: consumer does not change its supply voltage or 44*4882a593Smuzhiyun current limit. It only needs to enable or disable its 45*4882a593Smuzhiyun power supply. Its supply voltage is set by the hardware, 46*4882a593Smuzhiyun bootloader, firmware or kernel board initialisation code. 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun Dynamic: consumer needs to change its supply voltage or 49*4882a593Smuzhiyun current limit to meet operation demands. 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun - Power Domain 53*4882a593Smuzhiyun - Electronic circuit that is supplied its input power by the 54*4882a593Smuzhiyun output power of a regulator, switch or by another power 55*4882a593Smuzhiyun domain. 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun The supply regulator may be behind a switch(s). i.e.:: 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun Regulator -+-> Switch-1 -+-> Switch-2 --> [Consumer A] 60*4882a593Smuzhiyun | | 61*4882a593Smuzhiyun | +-> [Consumer B], [Consumer C] 62*4882a593Smuzhiyun | 63*4882a593Smuzhiyun +-> [Consumer D], [Consumer E] 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun That is one regulator and three power domains: 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun - Domain 1: Switch-1, Consumers D & E. 68*4882a593Smuzhiyun - Domain 2: Switch-2, Consumers B & C. 69*4882a593Smuzhiyun - Domain 3: Consumer A. 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun and this represents a "supplies" relationship: 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun Domain-1 --> Domain-2 --> Domain-3. 74*4882a593Smuzhiyun 75*4882a593Smuzhiyun A power domain may have regulators that are supplied power 76*4882a593Smuzhiyun by other regulators. i.e.:: 77*4882a593Smuzhiyun 78*4882a593Smuzhiyun Regulator-1 -+-> Regulator-2 -+-> [Consumer A] 79*4882a593Smuzhiyun | 80*4882a593Smuzhiyun +-> [Consumer B] 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun This gives us two regulators and two power domains: 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun - Domain 1: Regulator-2, Consumer B. 85*4882a593Smuzhiyun - Domain 2: Consumer A. 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun and a "supplies" relationship: 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun Domain-1 --> Domain-2 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun - Constraints 93*4882a593Smuzhiyun - Constraints are used to define power levels for performance 94*4882a593Smuzhiyun and hardware protection. Constraints exist at three levels: 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun Regulator Level: This is defined by the regulator hardware 97*4882a593Smuzhiyun operating parameters and is specified in the regulator 98*4882a593Smuzhiyun datasheet. i.e. 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun - voltage output is in the range 800mV -> 3500mV. 101*4882a593Smuzhiyun - regulator current output limit is 20mA @ 5V but is 102*4882a593Smuzhiyun 10mA @ 10V. 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun Power Domain Level: This is defined in software by kernel 105*4882a593Smuzhiyun level board initialisation code. It is used to constrain a 106*4882a593Smuzhiyun power domain to a particular power range. i.e. 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun - Domain-1 voltage is 3300mV 109*4882a593Smuzhiyun - Domain-2 voltage is 1400mV -> 1600mV 110*4882a593Smuzhiyun - Domain-3 current limit is 0mA -> 20mA. 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun Consumer Level: This is defined by consumer drivers 113*4882a593Smuzhiyun dynamically setting voltage or current limit levels. 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun e.g. a consumer backlight driver asks for a current increase 116*4882a593Smuzhiyun from 5mA to 10mA to increase LCD illumination. This passes 117*4882a593Smuzhiyun to through the levels as follows :- 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun Consumer: need to increase LCD brightness. Lookup and 120*4882a593Smuzhiyun request next current mA value in brightness table (the 121*4882a593Smuzhiyun consumer driver could be used on several different 122*4882a593Smuzhiyun personalities based upon the same reference device). 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun Power Domain: is the new current limit within the domain 125*4882a593Smuzhiyun operating limits for this domain and system state (e.g. 126*4882a593Smuzhiyun battery power, USB power) 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun Regulator Domains: is the new current limit within the 129*4882a593Smuzhiyun regulator operating parameters for input/output voltage. 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun If the regulator request passes all the constraint tests 132*4882a593Smuzhiyun then the new regulator value is applied. 133*4882a593Smuzhiyun 134*4882a593Smuzhiyun 135*4882a593SmuzhiyunDesign 136*4882a593Smuzhiyun====== 137*4882a593Smuzhiyun 138*4882a593SmuzhiyunThe framework is designed and targeted at SoC based devices but may also be 139*4882a593Smuzhiyunrelevant to non SoC devices and is split into the following four interfaces:- 140*4882a593Smuzhiyun 141*4882a593Smuzhiyun 142*4882a593Smuzhiyun 1. Consumer driver interface. 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun This uses a similar API to the kernel clock interface in that consumer 145*4882a593Smuzhiyun drivers can get and put a regulator (like they can with clocks atm) and 146*4882a593Smuzhiyun get/set voltage, current limit, mode, enable and disable. This should 147*4882a593Smuzhiyun allow consumers complete control over their supply voltage and current 148*4882a593Smuzhiyun limit. This also compiles out if not in use so drivers can be reused in 149*4882a593Smuzhiyun systems with no regulator based power control. 150*4882a593Smuzhiyun 151*4882a593Smuzhiyun See Documentation/power/regulator/consumer.rst 152*4882a593Smuzhiyun 153*4882a593Smuzhiyun 2. Regulator driver interface. 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun This allows regulator drivers to register their regulators and provide 156*4882a593Smuzhiyun operations to the core. It also has a notifier call chain for propagating 157*4882a593Smuzhiyun regulator events to clients. 158*4882a593Smuzhiyun 159*4882a593Smuzhiyun See Documentation/power/regulator/regulator.rst 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun 3. Machine interface. 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun This interface is for machine specific code and allows the creation of 164*4882a593Smuzhiyun voltage/current domains (with constraints) for each regulator. It can 165*4882a593Smuzhiyun provide regulator constraints that will prevent device damage through 166*4882a593Smuzhiyun overvoltage or overcurrent caused by buggy client drivers. It also 167*4882a593Smuzhiyun allows the creation of a regulator tree whereby some regulators are 168*4882a593Smuzhiyun supplied by others (similar to a clock tree). 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun See Documentation/power/regulator/machine.rst 171*4882a593Smuzhiyun 172*4882a593Smuzhiyun 4. Userspace ABI. 173*4882a593Smuzhiyun 174*4882a593Smuzhiyun The framework also exports a lot of useful voltage/current/opmode data to 175*4882a593Smuzhiyun userspace via sysfs. This could be used to help monitor device power 176*4882a593Smuzhiyun consumption and status. 177*4882a593Smuzhiyun 178*4882a593Smuzhiyun See Documentation/ABI/testing/sysfs-class-regulator 179