stpmic1.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (c) 2016-2021, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef STPMIC1_H
  7. #define STPMIC1_H
  8. #include <drivers/st/stm32_i2c.h>
  9. #include <lib/utils_def.h>
  10. #define TURN_ON_REG 0x1U
  11. #define TURN_OFF_REG 0x2U
  12. #define ICC_LDO_TURN_OFF_REG 0x3U
  13. #define ICC_BUCK_TURN_OFF_REG 0x4U
  14. #define RESET_STATUS_REG 0x5U
  15. #define VERSION_STATUS_REG 0x6U
  16. #define MAIN_CONTROL_REG 0x10U
  17. #define PADS_PULL_REG 0x11U
  18. #define BUCK_PULL_DOWN_REG 0x12U
  19. #define LDO14_PULL_DOWN_REG 0x13U
  20. #define LDO56_PULL_DOWN_REG 0x14U
  21. #define VIN_CONTROL_REG 0x15U
  22. #define PONKEY_TIMER_REG 0x16U
  23. #define MASK_RANK_BUCK_REG 0x17U
  24. #define MASK_RESET_BUCK_REG 0x18U
  25. #define MASK_RANK_LDO_REG 0x19U
  26. #define MASK_RESET_LDO_REG 0x1AU
  27. #define WATCHDOG_CONTROL_REG 0x1BU
  28. #define WATCHDOG_TIMER_REG 0x1CU
  29. #define BUCK_ICC_TURNOFF_REG 0x1DU
  30. #define LDO_ICC_TURNOFF_REG 0x1EU
  31. #define BUCK_APM_CONTROL_REG 0x1FU
  32. #define BUCK1_CONTROL_REG 0x20U
  33. #define BUCK2_CONTROL_REG 0x21U
  34. #define BUCK3_CONTROL_REG 0x22U
  35. #define BUCK4_CONTROL_REG 0x23U
  36. #define VREF_DDR_CONTROL_REG 0x24U
  37. #define LDO1_CONTROL_REG 0x25U
  38. #define LDO2_CONTROL_REG 0x26U
  39. #define LDO3_CONTROL_REG 0x27U
  40. #define LDO4_CONTROL_REG 0x28U
  41. #define LDO5_CONTROL_REG 0x29U
  42. #define LDO6_CONTROL_REG 0x2AU
  43. #define BUCK1_PWRCTRL_REG 0x30U
  44. #define BUCK2_PWRCTRL_REG 0x31U
  45. #define BUCK3_PWRCTRL_REG 0x32U
  46. #define BUCK4_PWRCTRL_REG 0x33U
  47. #define VREF_DDR_PWRCTRL_REG 0x34U
  48. #define LDO1_PWRCTRL_REG 0x35U
  49. #define LDO2_PWRCTRL_REG 0x36U
  50. #define LDO3_PWRCTRL_REG 0x37U
  51. #define LDO4_PWRCTRL_REG 0x38U
  52. #define LDO5_PWRCTRL_REG 0x39U
  53. #define LDO6_PWRCTRL_REG 0x3AU
  54. #define FREQUENCY_SPREADING_REG 0x3BU
  55. #define USB_CONTROL_REG 0x40U
  56. #define ITLATCH1_REG 0x50U
  57. #define ITLATCH2_REG 0x51U
  58. #define ITLATCH3_REG 0x52U
  59. #define ITLATCH4_REG 0x53U
  60. #define ITSETLATCH1_REG 0x60U
  61. #define ITSETLATCH2_REG 0x61U
  62. #define ITSETLATCH3_REG 0x62U
  63. #define ITSETLATCH4_REG 0x63U
  64. #define ITCLEARLATCH1_REG 0x70U
  65. #define ITCLEARLATCH2_REG 0x71U
  66. #define ITCLEARLATCH3_REG 0x72U
  67. #define ITCLEARLATCH4_REG 0x73U
  68. #define ITMASK1_REG 0x80U
  69. #define ITMASK2_REG 0x81U
  70. #define ITMASK3_REG 0x82U
  71. #define ITMASK4_REG 0x83U
  72. #define ITSETMASK1_REG 0x90U
  73. #define ITSETMASK2_REG 0x91U
  74. #define ITSETMASK3_REG 0x92U
  75. #define ITSETMASK4_REG 0x93U
  76. #define ITCLEARMASK1_REG 0xA0U
  77. #define ITCLEARMASK2_REG 0xA1U
  78. #define ITCLEARMASK3_REG 0xA2U
  79. #define ITCLEARMASK4_REG 0xA3U
  80. #define ITSOURCE1_REG 0xB0U
  81. #define ITSOURCE2_REG 0xB1U
  82. #define ITSOURCE3_REG 0xB2U
  83. #define ITSOURCE4_REG 0xB3U
  84. /* Registers masks */
  85. #define LDO_VOLTAGE_MASK GENMASK(6, 2)
  86. #define BUCK_VOLTAGE_MASK GENMASK(7, 2)
  87. #define LDO_BUCK_VOLTAGE_SHIFT 2
  88. #define LDO_BUCK_ENABLE_MASK BIT(0)
  89. #define LDO_BUCK_HPLP_ENABLE_MASK BIT(1)
  90. #define LDO_BUCK_HPLP_SHIFT 1
  91. #define LDO_BUCK_RANK_MASK BIT(0)
  92. #define LDO_BUCK_RESET_MASK BIT(0)
  93. #define LDO_BUCK_PULL_DOWN_MASK GENMASK(1, 0)
  94. /* Pull down register */
  95. #define BUCK1_PULL_DOWN_SHIFT 0
  96. #define BUCK2_PULL_DOWN_SHIFT 2
  97. #define BUCK3_PULL_DOWN_SHIFT 4
  98. #define BUCK4_PULL_DOWN_SHIFT 6
  99. #define VREF_DDR_PULL_DOWN_SHIFT 4
  100. /* ICC register */
  101. #define BUCK1_ICC_SHIFT 0
  102. #define BUCK2_ICC_SHIFT 1
  103. #define BUCK3_ICC_SHIFT 2
  104. #define BUCK4_ICC_SHIFT 3
  105. #define PWR_SW1_ICC_SHIFT 4
  106. #define PWR_SW2_ICC_SHIFT 5
  107. #define BOOST_ICC_SHIFT 6
  108. #define LDO1_ICC_SHIFT 0
  109. #define LDO2_ICC_SHIFT 1
  110. #define LDO3_ICC_SHIFT 2
  111. #define LDO4_ICC_SHIFT 3
  112. #define LDO5_ICC_SHIFT 4
  113. #define LDO6_ICC_SHIFT 5
  114. /* Buck Mask reset register */
  115. #define BUCK1_MASK_RESET 0
  116. #define BUCK2_MASK_RESET 1
  117. #define BUCK3_MASK_RESET 2
  118. #define BUCK4_MASK_RESET 3
  119. /* LDO Mask reset register */
  120. #define LDO1_MASK_RESET 0
  121. #define LDO2_MASK_RESET 1
  122. #define LDO3_MASK_RESET 2
  123. #define LDO4_MASK_RESET 3
  124. #define LDO5_MASK_RESET 4
  125. #define LDO6_MASK_RESET 5
  126. #define VREF_DDR_MASK_RESET 6
  127. /* LDO3 Special modes */
  128. #define LDO3_BYPASS BIT(7)
  129. #define LDO3_DDR_SEL 31U
  130. /* Main PMIC Control Register (MAIN_CONTROL_REG) */
  131. #define ICC_EVENT_ENABLED BIT(4)
  132. #define PWRCTRL_POLARITY_HIGH BIT(3)
  133. #define PWRCTRL_PIN_VALID BIT(2)
  134. #define RESTART_REQUEST_ENABLED BIT(1)
  135. #define SOFTWARE_SWITCH_OFF_ENABLED BIT(0)
  136. /* Main PMIC PADS Control Register (PADS_PULL_REG) */
  137. #define WAKEUP_DETECTOR_DISABLED BIT(4)
  138. #define PWRCTRL_PD_ACTIVE BIT(3)
  139. #define PWRCTRL_PU_ACTIVE BIT(2)
  140. #define WAKEUP_PD_ACTIVE BIT(1)
  141. #define PONKEY_PU_ACTIVE BIT(0)
  142. /* Main PMIC VINLOW Control Register (VIN_CONTROL_REGC DMSC) */
  143. #define SWIN_DETECTOR_ENABLED BIT(7)
  144. #define SWOUT_DETECTOR_ENABLED BIT(6)
  145. #define VINLOW_HYST_MASK GENMASK(1, 0)
  146. #define VINLOW_HYST_SHIFT 4
  147. #define VINLOW_THRESHOLD_MASK GENMASK(2, 0)
  148. #define VINLOW_THRESHOLD_SHIFT 1
  149. #define VINLOW_ENABLED BIT(0)
  150. #define VINLOW_CTRL_REG_MASK GENMASK(7, 0)
  151. /* USB Control Register */
  152. #define BOOST_OVP_DISABLED BIT(7)
  153. #define VBUS_OTG_DETECTION_DISABLED BIT(6)
  154. #define SW_OUT_DISCHARGE BIT(5)
  155. #define VBUS_OTG_DISCHARGE BIT(4)
  156. #define OCP_LIMIT_HIGH BIT(3)
  157. #define SWIN_SWOUT_ENABLED BIT(2)
  158. #define USBSW_OTG_SWITCH_ENABLED BIT(1)
  159. #define BOOST_ENABLED BIT(0)
  160. int stpmic1_powerctrl_on(void);
  161. int stpmic1_switch_off(void);
  162. int stpmic1_register_read(uint8_t register_id, uint8_t *value);
  163. int stpmic1_register_write(uint8_t register_id, uint8_t value);
  164. int stpmic1_register_update(uint8_t register_id, uint8_t value, uint8_t mask);
  165. int stpmic1_regulator_enable(const char *name);
  166. int stpmic1_regulator_disable(const char *name);
  167. bool stpmic1_is_regulator_enabled(const char *name);
  168. int stpmic1_regulator_voltage_set(const char *name, uint16_t millivolts);
  169. int stpmic1_regulator_levels_mv(const char *name, const uint16_t **levels,
  170. size_t *levels_count);
  171. int stpmic1_regulator_voltage_get(const char *name);
  172. int stpmic1_regulator_pull_down_set(const char *name);
  173. int stpmic1_regulator_mask_reset_set(const char *name);
  174. int stpmic1_regulator_icc_set(const char *name);
  175. int stpmic1_regulator_sink_mode_set(const char *name);
  176. int stpmic1_regulator_bypass_mode_set(const char *name);
  177. int stpmic1_active_discharge_mode_set(const char *name);
  178. void stpmic1_bind_i2c(struct i2c_handle_s *i2c_handle, uint16_t i2c_addr);
  179. int stpmic1_get_version(unsigned long *version);
  180. void stpmic1_dump_regulators(void);
  181. #endif /* STPMIC1_H */