1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* 3 * Copyright (c) 2016-2018, STMicroelectronics - All Rights Reserved 4 */ 5 6 #ifndef __STPMIC1_H__ 7 #define __STPMIC1_H__ 8 9 #include <drivers/stm32_i2c.h> 10 #include <util.h> 11 12 #define TURN_ON_REG 0x1U 13 #define TURN_OFF_REG 0x2U 14 #define ICC_LDO_TURN_OFF_REG 0x3U 15 #define ICC_BUCK_TURN_OFF_REG 0x4U 16 #define RESET_STATUS_REG 0x5U 17 #define VERSION_STATUS_REG 0x6U 18 #define MAIN_CONTROL_REG 0x10U 19 #define PADS_PULL_REG 0x11U 20 #define BUCK_PULL_DOWN_REG 0x12U 21 #define LDO14_PULL_DOWN_REG 0x13U 22 #define LDO56_PULL_DOWN_REG 0x14U 23 #define VIN_CONTROL_REG 0x15U 24 #define PONKEY_TIMER_REG 0x16U 25 #define MASK_RANK_BUCK_REG 0x17U 26 #define MASK_RESET_BUCK_REG 0x18U 27 #define MASK_RANK_LDO_REG 0x19U 28 #define MASK_RESET_LDO_REG 0x1AU 29 #define WATCHDOG_CONTROL_REG 0x1BU 30 #define WATCHDOG_TIMER_REG 0x1CU 31 #define BUCK_ICC_TURNOFF_REG 0x1DU 32 #define LDO_ICC_TURNOFF_REG 0x1EU 33 #define BUCK_APM_CONTROL_REG 0x1FU 34 #define BUCK1_CONTROL_REG 0x20U 35 #define BUCK2_CONTROL_REG 0x21U 36 #define BUCK3_CONTROL_REG 0x22U 37 #define BUCK4_CONTROL_REG 0x23U 38 #define VREF_DDR_CONTROL_REG 0x24U 39 #define LDO1_CONTROL_REG 0x25U 40 #define LDO2_CONTROL_REG 0x26U 41 #define LDO3_CONTROL_REG 0x27U 42 #define LDO4_CONTROL_REG 0x28U 43 #define LDO5_CONTROL_REG 0x29U 44 #define LDO6_CONTROL_REG 0x2AU 45 #define BUCK1_PWRCTRL_REG 0x30U 46 #define BUCK2_PWRCTRL_REG 0x31U 47 #define BUCK3_PWRCTRL_REG 0x32U 48 #define BUCK4_PWRCTRL_REG 0x33U 49 #define VREF_DDR_PWRCTRL_REG 0x34U 50 #define LDO1_PWRCTRL_REG 0x35U 51 #define LDO2_PWRCTRL_REG 0x36U 52 #define LDO3_PWRCTRL_REG 0x37U 53 #define LDO4_PWRCTRL_REG 0x38U 54 #define LDO5_PWRCTRL_REG 0x39U 55 #define LDO6_PWRCTRL_REG 0x3AU 56 #define FREQUENCY_SPREADING_REG 0x3BU 57 #define USB_CONTROL_REG 0x40U 58 #define ITLATCH1_REG 0x50U 59 #define ITLATCH2_REG 0x51U 60 #define ITLATCH3_REG 0x52U 61 #define ITLATCH4_REG 0x53U 62 #define ITSETLATCH1_REG 0x60U 63 #define ITSETLATCH2_REG 0x61U 64 #define ITSETLATCH3_REG 0x62U 65 #define ITSETLATCH4_REG 0x63U 66 #define ITCLEARLATCH1_REG 0x70U 67 #define ITCLEARLATCH2_REG 0x71U 68 #define ITCLEARLATCH3_REG 0x72U 69 #define ITCLEARLATCH4_REG 0x73U 70 #define ITMASK1_REG 0x80U 71 #define ITMASK2_REG 0x81U 72 #define ITMASK3_REG 0x82U 73 #define ITMASK4_REG 0x83U 74 #define ITSETMASK1_REG 0x90U 75 #define ITSETMASK2_REG 0x91U 76 #define ITSETMASK3_REG 0x92U 77 #define ITSETMASK4_REG 0x93U 78 #define ITCLEARMASK1_REG 0xA0U 79 #define ITCLEARMASK2_REG 0xA1U 80 #define ITCLEARMASK3_REG 0xA2U 81 #define ITCLEARMASK4_REG 0xA3U 82 #define ITSOURCE1_REG 0xB0U 83 #define ITSOURCE2_REG 0xB1U 84 #define ITSOURCE3_REG 0xB2U 85 #define ITSOURCE4_REG 0xB3U 86 87 /* Registers masks */ 88 #define LDO_VOLTAGE_MASK 0x7CU 89 #define BUCK_VOLTAGE_MASK 0xFCU 90 #define LDO_BUCK_VOLTAGE_SHIFT 2 91 #define LDO_BUCK_ENABLE_MASK 0x01U 92 #define LDO_BUCK_HPLP_ENABLE_MASK 0x02U 93 #define LDO_BUCK_HPLP_SHIFT 1 94 #define LDO_BUCK_RANK_MASK 0x01U 95 #define LDO_BUCK_RESET_MASK 0x01U 96 #define LDO_BUCK_PULL_DOWN_MASK 0x03U 97 98 /* Pull down register */ 99 #define BUCK1_PULL_DOWN_SHIFT 0 100 #define BUCK2_PULL_DOWN_SHIFT 2 101 #define BUCK3_PULL_DOWN_SHIFT 4 102 #define BUCK4_PULL_DOWN_SHIFT 6 103 #define VREF_DDR_PULL_DOWN_SHIFT 4 104 105 /* Buck Mask reset register */ 106 #define BUCK1_MASK_RESET_SHIFT 0 107 #define BUCK2_MASK_RESET_SHIFT 1 108 #define BUCK3_MASK_RESET_SHIFT 2 109 #define BUCK4_MASK_RESET_SHIFT 3 110 111 /* LDO Mask reset register */ 112 #define LDO1_MASK_RESET_SHIFT 0 113 #define LDO2_MASK_RESET_SHIFT 1 114 #define LDO3_MASK_RESET_SHIFT 2 115 #define LDO4_MASK_RESET_SHIFT 3 116 #define LDO5_MASK_RESET_SHIFT 4 117 #define LDO6_MASK_RESET_SHIFT 5 118 #define VREF_DDR_MASK_RESET_SHIFT 6 119 120 /* Main PMIC Control Register (MAIN_CONTROL_REG) */ 121 #define ICC_EVENT_ENABLED BIT(4) 122 #define PWRCTRL_POLARITY_HIGH BIT(3) 123 #define PWRCTRL_PIN_VALID BIT(2) 124 #define RESTART_REQUEST_ENABLED BIT(1) 125 #define SOFTWARE_SWITCH_OFF_ENABLED BIT(0) 126 127 /* Main PMIC PADS Control Register (PADS_PULL_REG) */ 128 #define WAKEUP_DETECTOR_DISABLED BIT(4) 129 #define PWRCTRL_PD_ACTIVE BIT(3) 130 #define PWRCTRL_PU_ACTIVE BIT(2) 131 #define WAKEUP_PD_ACTIVE BIT(1) 132 #define PONKEY_PU_ACTIVE BIT(0) 133 134 /* Main PMIC VINLOW Control Register (VIN_CONTROL_REGC DMSC) */ 135 #define SWIN_DETECTOR_ENABLED BIT(7) 136 #define SWOUT_DETECTOR_ENABLED BIT(6) 137 #define VINLOW_HYST_MASK GENMASK_32(5, 4) 138 #define VINLOW_HYST_SHIFT 4 139 #define VINLOW_THRESHOLD_MASK GENMASK_32(3, 1) 140 #define VINLOW_THRESHOLD_SHIFT 1 141 #define VINLOW_ENABLED 1 142 143 /* USB Control Register */ 144 #define BOOST_OVP_DISABLED BIT(7) 145 #define VBUS_OTG_DETECTION_DISABLED BIT(6) 146 #define OCP_LIMIT_HIGH BIT(3) 147 #define SWIN_SWOUT_ENABLED BIT(2) 148 #define USBSW_OTG_SWITCH_ENABLED BIT(1) 149 150 /* 151 * Bind SPMIC1 device driver with a specific I2C bus instance 152 * @i2c_handle: target I2C instance to use 153 * @i2c_addr: I2C address of the STPMIC1 device 154 */ 155 void stpmic1_bind_i2c(struct i2c_handle_s *i2c_handle, uint16_t i2c_addr); 156 157 /* Read STPMIC1 device version information */ 158 int stpmic1_get_version(unsigned long *version); 159 160 /* Read STPMIC1 device internal registers content */ 161 void stpmic1_dump_regulators(void); 162 163 /* Enable power control in STPMIC1 device */ 164 int stpmic1_powerctrl_on(void); 165 166 /* Disable STPMIC1 device */ 167 int stpmic1_switch_off(void); 168 169 /* Read/write/update STPMIC1 device internal register */ 170 int stpmic1_register_read(uint8_t register_id, uint8_t *value); 171 int stpmic1_register_write(uint8_t register_id, uint8_t value); 172 int stpmic1_register_update(uint8_t register_id, uint8_t value, uint8_t mask); 173 174 /* API for gating of regulators driven from STPMIC1 device */ 175 int stpmic1_regulator_enable(const char *name); 176 int stpmic1_regulator_disable(const char *name); 177 uint8_t stpmic1_is_regulator_enabled(const char *name); 178 179 /* API for voltage cnotrol of regulators driven from STPMIC1 device */ 180 int stpmic1_regulator_voltage_set(const char *name, uint16_t millivolts); 181 int stpmic1_regulator_voltage_get(const char *name); 182 int stpmic1_regulator_mask_reset_set(const char *name); 183 184 /* API for low power configuration of regulators driven from STPMIC1 device */ 185 int stpmic1_lp_copy_reg(const char *name); 186 int stpmic1_lp_reg_on_off(const char *name, uint8_t enable); 187 int stpmic1_lp_set_mode(const char *name, uint8_t hplp); 188 int stpmic1_lp_set_voltage(const char *name, uint16_t millivolts); 189 190 /* 191 * Specific API for controlling regulators driven from STPMIC1 device 192 * from unpaged execution context of the STPMIC1 driver. 193 */ 194 195 /* 196 * The STPMIC1 is accessed during low power sequence in unpaged 197 * execution context. To prevent adding an unpaged constraint on 198 * STPMIC1 regulator definitions, conversion tables and device tree 199 * content, the regulators configurations are read from device tree 200 * at boot time and saved in memory for being applied at runtime 201 * without needing pager support. 202 * 203 * There are 2 types of regulator configuration loaded during such 204 * low power and unpaged sequences: boot-on (bo) configuration and 205 * low power (lp) configuration. 206 */ 207 struct stpmic1_bo_cfg { 208 uint8_t ctrl_reg; 209 uint8_t value; 210 uint8_t mask; 211 uint8_t pd_reg; 212 uint8_t pd_value; 213 uint8_t pd_mask; 214 uint8_t mrst_reg; 215 uint8_t mrst_value; 216 uint8_t mrst_mask; 217 }; 218 219 struct stpmic1_lp_cfg { 220 uint8_t ctrl_reg; 221 uint8_t lp_reg; 222 uint8_t value; 223 uint8_t mask; 224 }; 225 226 int stpmic1_bo_enable_unpg(struct stpmic1_bo_cfg *cfg); 227 int stpmic1_bo_voltage_cfg(const char *name, uint16_t millivolts, 228 struct stpmic1_bo_cfg *cfg); 229 int stpmic1_bo_voltage_unpg(struct stpmic1_bo_cfg *cfg); 230 231 int stpmic1_bo_pull_down_cfg(const char *name, 232 struct stpmic1_bo_cfg *cfg); 233 int stpmic1_bo_pull_down_unpg(struct stpmic1_bo_cfg *cfg); 234 235 int stpmic1_bo_mask_reset_cfg(const char *name, struct stpmic1_bo_cfg *cfg); 236 int stpmic1_bo_mask_reset_unpg(struct stpmic1_bo_cfg *cfg); 237 238 int stpmic1_lp_cfg(const char *name, struct stpmic1_lp_cfg *cfg); 239 int stpmic1_lp_load_unpg(struct stpmic1_lp_cfg *cfg); 240 int stpmic1_lp_on_off_unpg(struct stpmic1_lp_cfg *cfg, int enable); 241 int stpmic1_lp_mode_unpg(struct stpmic1_lp_cfg *cfg, 242 unsigned int mode); 243 int stpmic1_lp_voltage_cfg(const char *name, uint16_t millivolts, 244 struct stpmic1_lp_cfg *cfg); 245 int stpmic1_lp_voltage_unpg(struct stpmic1_lp_cfg *cfg); 246 247 #endif /*__STPMIC1_H__*/ 248