xref: /OK3568_Linux_fs/u-boot/doc/README.power-framework (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#
2*4882a593Smuzhiyun# (C) Copyright 2014 Samsung Electronics
3*4882a593Smuzhiyun# Lukasz Majewski <l.majewski@samsung.com>
4*4882a593Smuzhiyun#
5*4882a593Smuzhiyun# SPDX-License-Identifier:      GPL-2.0+
6*4882a593Smuzhiyun#
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunIntroduction
9*4882a593Smuzhiyun------------
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunThis document describes the second version of the u-boot's PMIC (Power
12*4882a593SmuzhiyunManagement IC) framework. As a reference boards please consider Samsungs' Trats
13*4882a593Smuzhiyunand Trats2.
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunBackground
16*4882a593Smuzhiyun----------
17*4882a593Smuzhiyun
18*4882a593SmuzhiyunBoards supported by u-boot are getting increasingly complex. Developers and
19*4882a593Smuzhiyundesigners strive to cut down power consumption. Hence several different types of
20*4882a593Smuzhiyundevices are now available on the board - namely power managers (PMIC), fuel
21*4882a593Smuzhiyungauges (FG), micro USB interface controllers (MUIC), batteries, multi-function
22*4882a593Smuzhiyundevices (MFD).
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunExplanation of key design decisions
25*4882a593Smuzhiyun-----------------------------------
26*4882a593Smuzhiyun
27*4882a593SmuzhiyunOne package can integrate PMIC and MUIC with different addresses on the I2C bus.
28*4882a593SmuzhiyunThe same device - e.g. MAX8997 uses two different I2C busses and addresses.
29*4882a593Smuzhiyun
30*4882a593SmuzhiyunPower devices use not only I2C for communication, but SPI as well. Additionally
31*4882a593Smuzhiyundifferent ICs use different endianess. For this reason struct pmic holds
32*4882a593Smuzhiyuninformation about I2C/SPI transmission, which is used with generic
33*4882a593Smuzhiyunpmic_req_write() function.
34*4882a593Smuzhiyun
35*4882a593SmuzhiyunThe "flat" hierarchy for power devices works well when each device performs only
36*4882a593Smuzhiyunone operation - e.g. PMIC enables LDO.
37*4882a593Smuzhiyun
38*4882a593SmuzhiyunThe problem emerges when we have a device (battery) which conceptually shall be
39*4882a593Smuzhiyunthe master and uses methods exported by other devices. We need to control MUIC
40*4882a593Smuzhiyunto start charging the battery, use PMIC to reduce board's overall power
41*4882a593Smuzhiyunconsumption (by disabling not needed LDOs, BUCKs) and get current state of
42*4882a593Smuzhiyunenergy on the battery from FG.
43*4882a593SmuzhiyunUp till now u-boot doesn't support device model, so a simple one had to be
44*4882a593Smuzhiyunadded.
45*4882a593Smuzhiyun
46*4882a593SmuzhiyunThe directory hierarchy has following structure:
47*4882a593Smuzhiyun./include/power/<device_name>_<device_function>.h
48*4882a593Smuzhiyune.g. ./include/power/max8997_pmic.h
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun./drivers/power/pmic/power_{core files}.c
51*4882a593Smuzhiyune.g. ./drivers/power/pmic/power_core.c
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun./drivers/power/pmic/<device_function>/<device_function>_<device_name>.c
54*4882a593Smuzhiyune.g. ./drivers/power/pmic/pmic_max8997.c
55*4882a593Smuzhiyune.g. ./drivers/power/battery/trats/bat_trats.c
56*4882a593Smuzhiyune.g. ./drivers/power/fuel_gauge/fg_max17042.c
57*4882a593Smuzhiyun
58*4882a593SmuzhiyunThe framework classifies devices by their function - separate directories should
59*4882a593Smuzhiyunbe maintained for different classes of devices.
60*4882a593Smuzhiyun
61*4882a593SmuzhiyunCurrent design
62*4882a593Smuzhiyun--------------
63*4882a593Smuzhiyun
64*4882a593SmuzhiyunEverything is a power device described by struct pmic. Even battery is
65*4882a593Smuzhiyunconsidered as a valid power device. This helps for better management of those
66*4882a593Smuzhiyundevices.
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun- Block diagram of the hierarchy:
69*4882a593Smuzhiyun			-----------------
70*4882a593Smuzhiyun		--------| BAT           |------------
71*4882a593Smuzhiyun		|       |               |           |
72*4882a593Smuzhiyun		|       -----------------           |
73*4882a593Smuzhiyun		|               |                   |
74*4882a593Smuzhiyun	       \|/             \|/                 \|/
75*4882a593Smuzhiyun	-----------     -----------------       ---------
76*4882a593Smuzhiyun	|FG       |     |MUIC           |       |CHRG   |
77*4882a593Smuzhiyun	|         |     |               |       |       |
78*4882a593Smuzhiyun	-----------     -----------------       ---------
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun1. When hierarchy is not needed (no complex battery charge):
82*4882a593Smuzhiyun
83*4882a593SmuzhiyunDefinition of the struct pmic is only required with proper name and parameters
84*4882a593Smuzhiyunfor communication. This is enough to use the "pmic" command in the u-boot
85*4882a593Smuzhiyunprompt to change values of device's register (enable/disable LDO, BUCK).
86*4882a593Smuzhiyun
87*4882a593SmuzhiyunThe PG, MUIC and CHRG above are regarded to be in the same level in the
88*4882a593Smuzhiyunhierarchy.
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun2. Complex battery charging.
91*4882a593Smuzhiyun
92*4882a593SmuzhiyunTo charge a battery, information from several "abstract" power devices is
93*4882a593Smuzhiyunneeded (defined at ./include/power/pmic.h):
94*4882a593Smuzhiyun- FG device (struct power_fg):
95*4882a593Smuzhiyun	     -- *fg_battery_check - check if battery is not above its limits
96*4882a593Smuzhiyun	     -- *fg_battery_update - update the pmic framework with current
97*4882a593Smuzhiyun				     battery state(voltage and current capacity)
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun- Charger device (struct power_chrq):
100*4882a593Smuzhiyun	     -- *chrg_type - type/capacity of the charger (including information
101*4882a593Smuzhiyun			     about USB cable disconnection)
102*4882a593Smuzhiyun	     -- *chrg_bat_present - detection if battery to be charged is
103*4882a593Smuzhiyun				    present
104*4882a593Smuzhiyun	     -- *chrg_state - status of the charger - if it is enabled or
105*4882a593Smuzhiyun			      disabled
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun- Battery device (struct power_battery):
108*4882a593Smuzhiyun	     -- *battery_init - assign proper callbacks to be used by top
109*4882a593Smuzhiyun				hierarchy battery device
110*4882a593Smuzhiyun	     -- *battery_charge - called from "pmic" command, responsible
111*4882a593Smuzhiyun				  for performing the charging
112*4882a593Smuzhiyun
113*4882a593SmuzhiyunNow two batteries are supported; trats and trats2 [*]. Those differ in the way
114*4882a593Smuzhiyunhow they handle the exact charging. Trats uses polling (MAX8997) and trats2
115*4882a593Smuzhiyunrelies on the PMIC/MUIC HW completely (MAX77693).
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun__Example for trats (this can be very different for other board):__
118*4882a593Smuzhiyun	     -- *fg_battery_check       -> FG device (fg_max17042.c)
119*4882a593Smuzhiyun	     -- *fg_battery_update      -> FG device (fg_max17042.c)
120*4882a593Smuzhiyun	     -- *chrg_type              -> MUIC device (muic_max8997.c)
121*4882a593Smuzhiyun	     -- *chrg_bat_present       -> PMIC device (pmic_max8997.c)
122*4882a593Smuzhiyun	     -- *chrg_state             -> PMIC device (pmic_max8997.c)
123*4882a593Smuzhiyun	     -- *battery_init           -> BAT device (bat_trats.c)
124*4882a593Smuzhiyun	     -- *battery_charge         -> BAT device (bat_trats.c)
125*4882a593Smuzhiyun
126*4882a593SmuzhiyunAlso the struct pmic holds method (*low_power_mode) for reducing board's
127*4882a593Smuzhiyunpower consumption when one calls "pmic BAT_TRATS bat charge" command.
128*4882a593Smuzhiyun
129*4882a593SmuzhiyunHow to add a new power device
130*4882a593Smuzhiyun-----------------------------
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun1. Simple device should be added with creation of file
133*4882a593Smuzhiyun<pmic_function>_<pmic_name>.c, <pmic_name>_<pmic_function>.h  according to the
134*4882a593Smuzhiyunproposed and described above scheme.
135*4882a593Smuzhiyun
136*4882a593SmuzhiyunThen "pmic" command supports reading/writing/dump of device's internal
137*4882a593Smuzhiyunregisters.
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun2. Charging battery with hierarchy
140*4882a593SmuzhiyunDefine devices as listed at 1.
141*4882a593Smuzhiyun
142*4882a593SmuzhiyunDefine battery file (bat_<board>.c). Please also note that one might need a
143*4882a593Smuzhiyuncorresponding battery model description for FG.
144*4882a593Smuzhiyun
145*4882a593SmuzhiyunFor points 1 and 2 use a generic function power_init_board() to initialise the
146*4882a593Smuzhiyunpower framework on your board.
147*4882a593Smuzhiyun
148*4882a593SmuzhiyunFor reference, please look into the trats/trats2 boards.
149*4882a593Smuzhiyun
150*4882a593SmuzhiyunTO DO list (for PMICv3) - up till v2014.04
151*4882a593Smuzhiyun------------------------------------------
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun1. Description of the devices related to power via device tree is not available.
154*4882a593SmuzhiyunThis is the main problem when a developer tries to build a multi-boot u-boot
155*4882a593Smuzhiyunbinary. The best would be to parse the DTS from Linux kernel.
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun2. To support many instances of the same IC, like two MAX8997, one needs to
158*4882a593Smuzhiyuncopy the corresponding pmic_max8997.c file with changed name to "MAX8997_PMICX",
159*4882a593Smuzhiyunwhere X is the device number. This problem will be addressed when extended
160*4882a593Smuzhiyunpmic_core.c will support storing available devices in a list.
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun3. Definition of batteries [*] (for trats/trats2) should be excluded from the
163*4882a593Smuzhiyuncode responsible for charging them and since it in fact describes the charging
164*4882a593Smuzhiyunprofile it should be put to a separate file.
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun4. Adjust the framework to work with the device model.
167