README.power-framework 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #
  2. # (C) Copyright 2014 Samsung Electronics
  3. # Lukasz Majewski <l.majewski@samsung.com>
  4. #
  5. # SPDX-License-Identifier: GPL-2.0+
  6. #
  7. Introduction
  8. ------------
  9. This document describes the second version of the u-boot's PMIC (Power
  10. Management IC) framework. As a reference boards please consider Samsungs' Trats
  11. and Trats2.
  12. Background
  13. ----------
  14. Boards supported by u-boot are getting increasingly complex. Developers and
  15. designers strive to cut down power consumption. Hence several different types of
  16. devices are now available on the board - namely power managers (PMIC), fuel
  17. gauges (FG), micro USB interface controllers (MUIC), batteries, multi-function
  18. devices (MFD).
  19. Explanation of key design decisions
  20. -----------------------------------
  21. One package can integrate PMIC and MUIC with different addresses on the I2C bus.
  22. The same device - e.g. MAX8997 uses two different I2C busses and addresses.
  23. Power devices use not only I2C for communication, but SPI as well. Additionally
  24. different ICs use different endianess. For this reason struct pmic holds
  25. information about I2C/SPI transmission, which is used with generic
  26. pmic_req_write() function.
  27. The "flat" hierarchy for power devices works well when each device performs only
  28. one operation - e.g. PMIC enables LDO.
  29. The problem emerges when we have a device (battery) which conceptually shall be
  30. the master and uses methods exported by other devices. We need to control MUIC
  31. to start charging the battery, use PMIC to reduce board's overall power
  32. consumption (by disabling not needed LDOs, BUCKs) and get current state of
  33. energy on the battery from FG.
  34. Up till now u-boot doesn't support device model, so a simple one had to be
  35. added.
  36. The directory hierarchy has following structure:
  37. ./include/power/<device_name>_<device_function>.h
  38. e.g. ./include/power/max8997_pmic.h
  39. ./drivers/power/pmic/power_{core files}.c
  40. e.g. ./drivers/power/pmic/power_core.c
  41. ./drivers/power/pmic/<device_function>/<device_function>_<device_name>.c
  42. e.g. ./drivers/power/pmic/pmic_max8997.c
  43. e.g. ./drivers/power/battery/trats/bat_trats.c
  44. e.g. ./drivers/power/fuel_gauge/fg_max17042.c
  45. The framework classifies devices by their function - separate directories should
  46. be maintained for different classes of devices.
  47. Current design
  48. --------------
  49. Everything is a power device described by struct pmic. Even battery is
  50. considered as a valid power device. This helps for better management of those
  51. devices.
  52. - Block diagram of the hierarchy:
  53. -----------------
  54. --------| BAT |------------
  55. | | | |
  56. | ----------------- |
  57. | | |
  58. \|/ \|/ \|/
  59. ----------- ----------------- ---------
  60. |FG | |MUIC | |CHRG |
  61. | | | | | |
  62. ----------- ----------------- ---------
  63. 1. When hierarchy is not needed (no complex battery charge):
  64. Definition of the struct pmic is only required with proper name and parameters
  65. for communication. This is enough to use the "pmic" command in the u-boot
  66. prompt to change values of device's register (enable/disable LDO, BUCK).
  67. The PG, MUIC and CHRG above are regarded to be in the same level in the
  68. hierarchy.
  69. 2. Complex battery charging.
  70. To charge a battery, information from several "abstract" power devices is
  71. needed (defined at ./include/power/pmic.h):
  72. - FG device (struct power_fg):
  73. -- *fg_battery_check - check if battery is not above its limits
  74. -- *fg_battery_update - update the pmic framework with current
  75. battery state(voltage and current capacity)
  76. - Charger device (struct power_chrq):
  77. -- *chrg_type - type/capacity of the charger (including information
  78. about USB cable disconnection)
  79. -- *chrg_bat_present - detection if battery to be charged is
  80. present
  81. -- *chrg_state - status of the charger - if it is enabled or
  82. disabled
  83. - Battery device (struct power_battery):
  84. -- *battery_init - assign proper callbacks to be used by top
  85. hierarchy battery device
  86. -- *battery_charge - called from "pmic" command, responsible
  87. for performing the charging
  88. Now two batteries are supported; trats and trats2 [*]. Those differ in the way
  89. how they handle the exact charging. Trats uses polling (MAX8997) and trats2
  90. relies on the PMIC/MUIC HW completely (MAX77693).
  91. __Example for trats (this can be very different for other board):__
  92. -- *fg_battery_check -> FG device (fg_max17042.c)
  93. -- *fg_battery_update -> FG device (fg_max17042.c)
  94. -- *chrg_type -> MUIC device (muic_max8997.c)
  95. -- *chrg_bat_present -> PMIC device (pmic_max8997.c)
  96. -- *chrg_state -> PMIC device (pmic_max8997.c)
  97. -- *battery_init -> BAT device (bat_trats.c)
  98. -- *battery_charge -> BAT device (bat_trats.c)
  99. Also the struct pmic holds method (*low_power_mode) for reducing board's
  100. power consumption when one calls "pmic BAT_TRATS bat charge" command.
  101. How to add a new power device
  102. -----------------------------
  103. 1. Simple device should be added with creation of file
  104. <pmic_function>_<pmic_name>.c, <pmic_name>_<pmic_function>.h according to the
  105. proposed and described above scheme.
  106. Then "pmic" command supports reading/writing/dump of device's internal
  107. registers.
  108. 2. Charging battery with hierarchy
  109. Define devices as listed at 1.
  110. Define battery file (bat_<board>.c). Please also note that one might need a
  111. corresponding battery model description for FG.
  112. For points 1 and 2 use a generic function power_init_board() to initialise the
  113. power framework on your board.
  114. For reference, please look into the trats/trats2 boards.
  115. TO DO list (for PMICv3) - up till v2014.04
  116. ------------------------------------------
  117. 1. Description of the devices related to power via device tree is not available.
  118. This is the main problem when a developer tries to build a multi-boot u-boot
  119. binary. The best would be to parse the DTS from Linux kernel.
  120. 2. To support many instances of the same IC, like two MAX8997, one needs to
  121. copy the corresponding pmic_max8997.c file with changed name to "MAX8997_PMICX",
  122. where X is the device number. This problem will be addressed when extended
  123. pmic_core.c will support storing available devices in a list.
  124. 3. Definition of batteries [*] (for trats/trats2) should be excluded from the
  125. code responsible for charging them and since it in fact describes the charging
  126. profile it should be put to a separate file.
  127. 4. Adjust the framework to work with the device model.