qpnp-bms.txt 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. Qualcomm's QPNP PMIC Battery Management System driver
  2. QPNP PMIC BMS provides interface to clients to read properties related
  3. to the battery. It's main function is to calculate the State of Charge (SOC),
  4. a 0-100 percentage representing the amount of charge left in the battery.
  5. There are two required peripherals in the BMS driver, both implemented as
  6. subnodes in the example. These peripherals must not be disabled if the BMS
  7. device is to enabled:
  8. - qcom,bms-bms : The main BMS device. Supports battery monitoring controls and
  9. sensors.
  10. - qcom,bms-iadc : The BMS IADC peripheral in the IADC device. This is required
  11. to determine whether the BMS is using an internal or external
  12. rsense to accumulate the Coulomb Counter and read current.
  13. Additionally, optional subnodes may be included:
  14. - qcom,batt-pres-status : A subnode with a register address for the SMBB
  15. battery interface's BATT_PRES_STATUS register. If this node is
  16. added, then the BMS will try to detect offmode battery removal
  17. via the battery interface's offmode battery removal circuit.
  18. - qcom,soc-storage-reg : A subnode with a register address to a spare PMIC
  19. register. If this node is included, then the BMS will store its
  20. shutdown SOC in the specified register instead of the default
  21. BMS data register.
  22. - qcom,battery-data : A phandle to a node containing the available batterydata
  23. profiles. See the batterydata bindings documentation for more
  24. details.
  25. Parent node required properties:
  26. - compatible : should be "qcom,qpnp-bms" for the BM driver.
  27. - qcom,r-sense-uohm : sensor resistance in in micro-ohms.
  28. - qcom,v-cutoff-uv : cutoff voltage where the battery is considered dead in
  29. micro-volts.
  30. - qcom,max-voltage-uv : maximum voltage for the battery in micro-volts.
  31. - qcom,r-conn-mohm : connector resistance in milli-ohms.
  32. - qcom,shutdown-soc-valid-limit : If the ocv upon restart is within this
  33. distance of the shutdown ocv, the BMS will try to force
  34. the new SoC to the old one to provide charge continuity.
  35. That is to say,
  36. if (abs(shutdown-soc - current-soc) < limit)
  37. then use old SoC.
  38. - qcom,adjust-soc-low-threshold : The low threshold for when the BMS algorithm
  39. starts adjusting. If the estimated SoC is not below
  40. this percentage, do not adjust.
  41. - qcom,ocv-voltage-low-threshold-uv : The low voltage threshold for the
  42. "flat portion" of the discharge curve. The bms will not
  43. accept new ocvs between these thresholds.
  44. - qcom,ocv-voltage-high-threshold-uv : The high voltage threshold for
  45. the "flat portion" of the discharge curve.
  46. The bms will not accept new ocvs between these
  47. thresholds.
  48. - qcom,low-soc-calculate-soc-threshold : The SoC threshold for when
  49. the periodic calculate_soc work speeds up. This ensures
  50. SoC is updated in userspace constantly when we are near
  51. shutdown.
  52. - qcom,low-voltage-threshold : The battery voltage threshold in micro-volts for
  53. when the BMS tries to wake up and hold a wakelock to
  54. ensure a clean shutdown.
  55. - qcom,low-voltage-calculate-soc-ms : The time period between subsequent
  56. SoC recalculations when the current voltage is below
  57. qcom,low-voltage threshold. This takes precedence over
  58. qcom,low-soc-calculate-soc-ms.
  59. - qcom,low-soc-calculate-soc-ms : The time period between subsequent
  60. SoC recalculations when the current SoC is below
  61. qcom,low-soc-calculate-soc-threshold. This takes
  62. precedence over qcom,calculate-soc-ms.
  63. - qcom,calculate-soc-ms : The time period between subsequent SoC
  64. recalculations when the current SoC is above or equal
  65. qcom,low-soc-calculate-soc-threshold.
  66. - qcom,chg-term-ua : current in micro-amps when charging is considered done.
  67. As soon as current passes this point, charging is
  68. stopped.
  69. - qcom,batt-type: Type of battery used. This is an integer that corresponds
  70. to the enum defined in
  71. include/linux/mfd/pm8xxx/batterydata-lib.h
  72. - qcom,high-ocv-correction-limit-uv: how much the bms will correct OCV when
  73. voltage is above the flat portion of the discharge
  74. curve.
  75. - qcom,low-ocv-correction-limit-uv: how much the bms will correct OCV when
  76. voltage is below the flat portion of the discharge
  77. curve.
  78. - qcom,hold-soc-est: if the voltage-based estimated SoC is above this percent,
  79. the BMS will clamp SoC to be at least 1.
  80. - qcom,tm-temp-margin: if the pmic die temperature changes by more than this
  81. value, recalibrate the ADCs. The unit of this property
  82. is in millidegrees celsius.
  83. - qcom,min-fcc-learning-soc: An interger value which defines the minimum SOC
  84. to start FCC learning. This is applicable only if
  85. FCC learning is enabled.
  86. - qcom,min-fcc-ocv-pc: An interger value which defines the minimum PC-lookup
  87. (OCV) to start FCC learning. This is applicable only if
  88. FCC learning is enabled.
  89. - qcom,min-fcc-learning-samples: An interger value which defines the minimum
  90. number of the FCC measurement cycles required to
  91. generate an FCC update. This is applicable only
  92. if the FCC learning is enabled.
  93. - qcom,fcc-resolution: An integer which defines the fcc resolution used
  94. for storing the FCC(mAh) in the 8-bit BMS register.
  95. For example - A value of 10 indicates:
  96. FCC value (in mAh) = (8-bit register value) * 10.
  97. - qcom,bms-vadc: Corresponding VADC device's phandle.
  98. - qcom,bms-iadc: Corresponding IADC device's phandle.
  99. Parent node optional properties:
  100. - qcom,ignore-shutdown-soc: A boolean that controls whether BMS will
  101. try to force the startup SoC to be the same as the
  102. shutdown SoC. Defining it will make BMS ignore the
  103. shutdown SoC.
  104. - qcom,use-voltage-soc : A boolean that controls whether BMS will use
  105. voltage-based SoC instead of a coulomb counter based
  106. one. Voltage-based SoC will not guarantee linearity.
  107. - qcom,use-external-rsense : A boolean that controls whether BMS will use
  108. an external sensor resistor instead of the default
  109. RDS of the batfet.
  110. - qcom,use-ocv-thresholds : A boolean that controls whether BMS will take
  111. new OCVs only between the defined thresholds.
  112. - qcom,enable-fcc-learning: A boolean that defines if FCC learning is enabled.
  113. - qcom,bms-adc_tm: Corresponding ADC_TM device's phandle to set recurring
  114. measurements and receive notifications for
  115. die_temperature and vbatt.
  116. qcom,batt-pres-status node required properties:
  117. - reg : offset and length of the PMIC SMBB battery interface BATT_PRES_STATUS
  118. register.
  119. qcom,soc-storage-reg node required properties:
  120. - reg : address and length of the spare PMIC register that the BMS will store
  121. shutdown SoC in.
  122. qcom,bms-iadc node required properties:
  123. - reg : offset and length of the PMIC peripheral register map.
  124. qcom,bms-bms node required properties:
  125. - reg : offset and length of the PMIC peripheral register map.
  126. - interrupts : the interrupt mappings.
  127. The format should be
  128. <slave-id peripheral-id interrupt-number>.
  129. - interrupt-names : names for the mapped bms interrupt
  130. The following interrupts are required:
  131. 0 : vsense_for_r
  132. 1 : vsense_avg
  133. 2 : sw_cc_thr
  134. 3 : ocv_thr
  135. 4 : charge_begin
  136. 5 : good_ocv
  137. 6 : ocv_for_r
  138. 7 : cc_thr
  139. Example:
  140. pm8941_bms: qcom,bms {
  141. spmi-dev-container;
  142. compatible = "qcom,qpnp-bms";
  143. #address-cells = <1>;
  144. #size-cells = <1>;
  145. status = "disabled";
  146. qcom,r-sense-uohm = <10000>;
  147. qcom,v-cutoff-uv = <3400000>;
  148. qcom,max-voltage-uv = <4200000>;
  149. qcom,r-conn-mohm = <18>;
  150. qcom,shutdown-soc-valid-limit = <20>;
  151. qcom,ocv-voltage-low-threshold-uv = <3650000>;
  152. qcom,ocv-voltage-high-threshold-uv = <3750000>;
  153. qcom,adjust-soc-low-threshold = <15>;
  154. qcom,low-soc-calculate-soc-threshold = <15>;
  155. qcom,low-voltage-threshold = <3420000>;
  156. qcom,low-voltage-calculate-soc-ms = <1000>;
  157. qcom,low-soc-calculate-soc-ms = <5000>;
  158. qcom,calculate-soc-ms = <20000>;
  159. qcom,chg-term-ua = <100000>;
  160. qcom,batt-type = <0>;
  161. qcom,low-ocv-correction-limit-uv = <100>;
  162. qcom,high-ocv-correction-limit-uv = <50>;
  163. qcom,hold-soc-est = <3>;
  164. qcom,tm-temp-margin = <5000>;
  165. qcom,battery-data = <&mtp_batterydata>;
  166. qcom,bms-vadc = <&pm8941_vadc>;
  167. qcom,bms-iadc = <&pm8941_iadc>;
  168. qcom,bms-adc_tm = <&pm8941_adc_tm>;
  169. qcom,batt-pres-status@1208 {
  170. reg = <0x1208 0x1>;
  171. }
  172. qcom,bms-iadc@3800 {
  173. reg = <0x3800 0x100>;
  174. };
  175. qcom,bms-bms@4000 {
  176. reg = <0x4000 0x100>;
  177. interrupts = <0x0 0x40 0x0>,
  178. <0x0 0x40 0x1>,
  179. <0x0 0x40 0x2>,
  180. <0x0 0x40 0x3>,
  181. <0x0 0x40 0x4>,
  182. <0x0 0x40 0x5>,
  183. <0x0 0x40 0x6>,
  184. <0x0 0x40 0x7>;
  185. interrupt-names = "vsense_for_r",
  186. "vsense_avg",
  187. "sw_cc_thr",
  188. "ocv_thr",
  189. "charge_begin",
  190. "good_ocv",
  191. "ocv_for_r",
  192. "cc_thr";
  193. };
  194. };