blob: b2aadfb2c9e27747eb62812d460f602a22498add [file] [log] [blame]
Pascal Paillet3263aea2022-12-16 14:59:34 +01001/*
2 * Copyright (C) 2024, STMicroelectronics - All Rights Reserved
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef STPMIC2_H
8#define STPMIC2_H
9
10#include <drivers/st/stm32_i2c.h>
11#include <lib/utils_def.h>
12
13enum {
14 STPMIC2_BUCK1 = 0,
15 STPMIC2_BUCK2,
16 STPMIC2_BUCK3,
17 STPMIC2_BUCK4,
18 STPMIC2_BUCK5,
19 STPMIC2_BUCK6,
20 STPMIC2_BUCK7,
21 STPMIC2_REFDDR,
22 STPMIC2_LDO1,
23 STPMIC2_LDO2,
24 STPMIC2_LDO3,
25 STPMIC2_LDO4,
26 STPMIC2_LDO5,
27 STPMIC2_LDO6,
28 STPMIC2_LDO7,
29 STPMIC2_LDO8,
30 STPMIC2_NB_REG
31};
32
33/* Status Registers */
34#define PRODUCT_ID 0x00
35#define VERSION_SR 0x01
36#define TURN_ON_SR 0x02
37#define TURN_OFF_SR 0x03
38#define RESTART_SR 0x04
39#define OCP_SR1 0x05
40#define OCP_SR2 0x06
41#define EN_SR1 0x07
42#define EN_SR2 0x08
43#define FS_CNT_SR1 0x09
44#define FS_CNT_SR2 0x0A
45#define FS_CNT_SR3 0x0B
46#define MODE_SR 0x0C
47/* Control Registers */
48#define MAIN_CR 0x10
49#define VINLOW_CR 0x11
50#define PKEY_LKP_CR 0x12
51#define WDG_CR 0x13
52#define WDG_TMR_CR 0x14
53#define WDG_TMR_SR 0x15
54#define FS_OCP_CR1 0x16
55#define FS_OCP_CR2 0x17
56#define PADS_PULL_CR 0x18
57#define BUCKS_PD_CR1 0x19
58#define BUCKS_PD_CR2 0x1A
59#define LDOS_PD_CR1 0x1B
60#define LDOS_PD_CR2 0x1C
61#define BUCKS_MRST_CR 0x1D
62#define LDOS_MRST_CR 0x1E
63/* Buck CR */
64#define BUCK1_MAIN_CR1 0x20
65#define BUCK1_MAIN_CR2 0x21
66#define BUCK1_ALT_CR1 0x22
67#define BUCK1_ALT_CR2 0x23
68#define BUCK1_PWRCTRL_CR 0x24
69#define BUCK2_MAIN_CR1 0x25
70#define BUCK2_MAIN_CR2 0x26
71#define BUCK2_ALT_CR1 0x27
72#define BUCK2_ALT_CR2 0x28
73#define BUCK2_PWRCTRL_CR 0x29
74#define BUCK3_MAIN_CR1 0x2A
75#define BUCK3_MAIN_CR2 0x2B
76#define BUCK3_ALT_CR1 0x2C
77#define BUCK3_ALT_CR2 0x2D
78#define BUCK3_PWRCTRL_CR 0x2E
79#define BUCK4_MAIN_CR1 0x2F
80#define BUCK4_MAIN_CR2 0x30
81#define BUCK4_ALT_CR1 0x31
82#define BUCK4_ALT_CR2 0x32
83#define BUCK4_PWRCTRL_CR 0x33
84#define BUCK5_MAIN_CR1 0x34
85#define BUCK5_MAIN_CR2 0x35
86#define BUCK5_ALT_CR1 0x36
87#define BUCK5_ALT_CR2 0x37
88#define BUCK5_PWRCTRL_CR 0x38
89#define BUCK6_MAIN_CR1 0x39
90#define BUCK6_MAIN_CR2 0x3A
91#define BUCK6_ALT_CR1 0x3B
92#define BUCK6_ALT_CR2 0x3C
93#define BUCK6_PWRCTRL_CR 0x3D
94#define BUCK7_MAIN_CR1 0x3E
95#define BUCK7_MAIN_CR2 0x3F
96#define BUCK7_ALT_CR1 0x40
97#define BUCK7_ALT_CR2 0x41
98#define BUCK7_PWRCTRL_CR 0x42
99/* LDO CR */
100#define LDO1_MAIN_CR 0x4C
101#define LDO1_ALT_CR 0x4D
102#define LDO1_PWRCTRL_CR 0x4E
103#define LDO2_MAIN_CR 0x4F
104#define LDO2_ALT_CR 0x50
105#define LDO2_PWRCTRL_CR 0x51
106#define LDO3_MAIN_CR 0x52
107#define LDO3_ALT_CR 0x53
108#define LDO3_PWRCTRL_CR 0x54
109#define LDO4_MAIN_CR 0x55
110#define LDO4_ALT_CR 0x56
111#define LDO4_PWRCTRL_CR 0x57
112#define LDO5_MAIN_CR 0x58
113#define LDO5_ALT_CR 0x59
114#define LDO5_PWRCTRL_CR 0x5A
115#define LDO6_MAIN_CR 0x5B
116#define LDO6_ALT_CR 0x5C
117#define LDO6_PWRCTRL_CR 0x5D
118#define LDO7_MAIN_CR 0x5E
119#define LDO7_ALT_CR 0x5F
120#define LDO7_PWRCTRL_CR 0x60
121#define LDO8_MAIN_CR 0x61
122#define LDO8_ALT_CR 0x62
123#define LDO8_PWRCTRL_CR 0x63
124#define REFDDR_MAIN_CR 0x64
125#define REFDDR_ALT_CR 0x65
126#define REFDDR_PWRCTRL_CR 0x66
127/* INTERRUPT CR */
128#define INT_PENDING_R1 0x70
129#define INT_PENDING_R2 0x71
130#define INT_PENDING_R3 0x72
131#define INT_PENDING_R4 0x73
132#define INT_CLEAR_R1 0x74
133#define INT_CLEAR_R2 0x75
134#define INT_CLEAR_R3 0x76
135#define INT_CLEAR_R4 0x77
136#define INT_MASK_R1 0x78
137#define INT_MASK_R2 0x79
138#define INT_MASK_R3 0x7A
139#define INT_MASK_R4 0x7B
140#define INT_SRC_R1 0x7C
141#define INT_SRC_R2 0x7D
142#define INT_SRC_R3 0x7E
143#define INT_SRC_R4 0x7F
144#define INT_DBG_LATCH_R1 0x80
145#define INT_DBG_LATCH_R2 0x81
146#define INT_DBG_LATCH_R3 0x82
147#define INT_DBG_LATCH_R4 0x83
148
Boerge Struempfel907e5472025-04-01 10:23:31 +0200149/* NVM user control registers */
150#define NVM_SR 0x8E
151#define NVM_CR 0x8F
152
153/* NVM user shadow registers */
154#define NVM_MAIN_CTRL_SHR1 0x90
155#define NVM_MAIN_CTRL_SHR2 0x91
156#define NVM_RANK_SHR1 0x92
157#define NVM_RANK_SHR2 0x93
158#define NVM_RANK_SHR3 0x94
159#define NVM_RANK_SHR4 0x95
160#define NVM_RANK_SHR5 0x96
161#define NVM_RANK_SHR6 0x97
162#define NVM_RANK_SHR7 0x98
163#define NVM_RANK_SHR8 0x99
164#define NVM_BUCK_MODE_SHR1 0x9A
165#define NVM_BUCK_MODE_SHR2 0x9B
166#define NVM_BUCK1_VOUT_SHR 0x9C
167#define NVM_BUCK2_VOUT_SHR 0x9D
168#define NVM_BUCK3_VOUT_SHR 0x9E
169#define NVM_BUCK4_VOUT_SHR 0x9F
170#define NVM_BUCK5_VOUT_SHR 0xA0
171#define NVM_BUCK6_VOUT_SHR 0xA1
172#define NVM_BUCK7_VOUT_SHR 0xA2
173#define NVM_LDO2_SHR 0xA3
174#define NVM_LDO3_SHR 0xA4
175#define NVM_LDO5_SHR 0xA5
176#define NVM_LDO6_SHR 0xA6
177#define NVM_LDO7_SHR 0xA7
178#define NVM_LDO8_SHR 0xA8
179#define NVM_PD_SHR1 0xA9
180#define NVM_PD_SHR2 0xAA
181#define NVM_PD_SHR3 0xAB
182#define NVM_BUCKS_IOUT_SHR1 0xAC
183#define NVM_BUCKS_IOUT_SHR2 0xAD
184#define NVM_LDOS_IOUT_SHR 0xAE
185#define NVM_FS_OCP_SHR1 0xAF
186#define NVM_FS_OCP_SHR2 0xB0
187#define NVM_FS_SHR1 0xB1
188#define NVM_FS_SHR2 0xB2
189#define NVM_FS_SHR3 0xB3
190#define NVM_I2C_ADDR_SHR 0xB5
191#define NVM_USER_SHR1 0xB6
192#define NVM_USER_SHR2 0xB7
193
Pascal Paillet3263aea2022-12-16 14:59:34 +0100194/* BUCKS_MRST_CR bits definition */
195#define BUCK1_MRST BIT(0)
196#define BUCK2_MRST BIT(1)
197#define BUCK3_MRST BIT(2)
198#define BUCK4_MRST BIT(3)
199#define BUCK5_MRST BIT(4)
200#define BUCK6_MRST BIT(5)
201#define BUCK7_MRST BIT(6)
202#define REFDDR_MRST BIT(7)
203
204/* LDOS_MRST_CR bits definition */
205#define LDO1_MRST BIT(0)
206#define LDO2_MRST BIT(1)
207#define LDO3_MRST BIT(2)
208#define LDO4_MRST BIT(3)
209#define LDO5_MRST BIT(4)
210#define LDO6_MRST BIT(5)
211#define LDO7_MRST BIT(6)
212#define LDO8_MRST BIT(7)
213
214/* LDOx_MAIN_CR */
215#define LDO_VOLT_SHIFT 1
216#define LDO_BYPASS BIT(6)
217#define LDO1_INPUT_SRC BIT(7)
218#define LDO3_SNK_SRC BIT(7)
219#define LDO4_INPUT_SRC_SHIFT 6
220#define LDO4_INPUT_SRC_MASK GENMASK_32(7, 6)
221
222/* PWRCTRL register bit definition */
223#define PWRCTRL_EN BIT(0)
224#define PWRCTRL_RS BIT(1)
225#define PWRCTRL_SEL_SHIFT 2
226#define PWRCTRL_SEL_MASK GENMASK_32(3, 2)
227
228/* BUCKx_MAIN_CR2 */
229#define PREG_MODE_SHIFT 1
230#define PREG_MODE_MASK GENMASK_32(2, 1)
231
232/* BUCKS_PD_CR1 */
233#define BUCK1_PD_MASK GENMASK_32(1, 0)
234#define BUCK2_PD_MASK GENMASK_32(3, 2)
235#define BUCK3_PD_MASK GENMASK_32(5, 4)
236#define BUCK4_PD_MASK GENMASK_32(7, 6)
237
238#define BUCK1_PD_FAST BIT(1)
239#define BUCK2_PD_FAST BIT(3)
240#define BUCK3_PD_FAST BIT(5)
241#define BUCK4_PD_FAST BIT(7)
242
243/* BUCKS_PD_CR2 */
244#define BUCK5_PD_MASK GENMASK_32(1, 0)
245#define BUCK6_PD_MASK GENMASK_32(3, 2)
246#define BUCK7_PD_MASK GENMASK_32(5, 4)
247
248#define BUCK5_PD_FAST BIT(1)
249#define BUCK6_PD_FAST BIT(3)
250#define BUCK7_PD_FAST BIT(5)
251
252/* LDOS_PD_CR1 */
253#define LDO1_PD BIT(0)
254#define LDO2_PD BIT(1)
255#define LDO3_PD BIT(2)
256#define LDO4_PD BIT(3)
257#define LDO5_PD BIT(4)
258#define LDO6_PD BIT(5)
259#define LDO7_PD BIT(6)
260#define LDO8_PD BIT(7)
261
262/* LDOS_PD_CR2 */
263#define REFDDR_PD BIT(0)
264
265/* FS_OCP_CR1 */
266#define FS_OCP_BUCK1 BIT(0)
267#define FS_OCP_BUCK2 BIT(1)
268#define FS_OCP_BUCK3 BIT(2)
269#define FS_OCP_BUCK4 BIT(3)
270#define FS_OCP_BUCK5 BIT(4)
271#define FS_OCP_BUCK6 BIT(5)
272#define FS_OCP_BUCK7 BIT(6)
273#define FS_OCP_REFDDR BIT(7)
274
275/* FS_OCP_CR2 */
276#define FS_OCP_LDO1 BIT(0)
277#define FS_OCP_LDO2 BIT(1)
278#define FS_OCP_LDO3 BIT(2)
279#define FS_OCP_LDO4 BIT(3)
280#define FS_OCP_LDO5 BIT(4)
281#define FS_OCP_LDO6 BIT(5)
282#define FS_OCP_LDO7 BIT(6)
283#define FS_OCP_LDO8 BIT(7)
284
Boerge Struempfel907e5472025-04-01 10:23:31 +0200285/* NVM_CR */
286#define NVM_CMD_MASK GENMASK_32(1, 0)
287
288#define NVM_CMD_PROGRAM 1
289#define NVM_CMD_READ 2
290
291/* NVM_SR */
292#define NVM_BUSY BIT(0)
293#define NVM_WRITE_FAIL BIT(1)
294
Pascal Paillet3263aea2022-12-16 14:59:34 +0100295/* IRQ definitions */
296#define IT_PONKEY_F 0
297#define IT_PONKEY_R 1
298#define IT_BUCK1_OCP 16
299#define IT_BUCK2_OCP 17
300#define IT_BUCK3_OCP 18
301#define IT_BUCK4_OCP 19
302#define IT_BUCK5_OCP 20
303#define IT_BUCK6_OCP 21
304#define IT_BUCK7_OCP 22
305#define IT_REFDDR_OCP 23
306#define IT_LDO1_OCP 24
307#define IT_LDO2_OCP 25
308#define IT_LDO3_OCP 26
309#define IT_LDO4_OCP 27
310#define IT_LDO5_OCP 28
311#define IT_LDO6_OCP 29
312#define IT_LDO7_OCP 30
313#define IT_LDO8_OCP 31
314
315enum stpmic2_prop_id {
316 STPMIC2_MASK_RESET = 0,
317 STPMIC2_PULL_DOWN,
318 STPMIC2_BYPASS, /* arg: 1=set 0=reset */
319 STPMIC2_SINK_SOURCE,
320 STPMIC2_OCP,
321};
322
323struct pmic_handle_s {
324 struct i2c_handle_s *i2c_handle;
325 uint32_t i2c_addr;
326 unsigned int pmic_status;
327};
328
329int stpmic2_register_read(struct pmic_handle_s *pmic,
330 uint8_t register_id, uint8_t *value);
331int stpmic2_register_write(struct pmic_handle_s *pmic,
332 uint8_t register_id, uint8_t value);
333int stpmic2_register_update(struct pmic_handle_s *pmic,
334 uint8_t register_id, uint8_t value, uint8_t mask);
335
336int stpmic2_regulator_set_state(struct pmic_handle_s *pmic,
337 uint8_t id, bool enable);
338int stpmic2_regulator_get_state(struct pmic_handle_s *pmic,
339 uint8_t id, bool *enabled);
340
341int stpmic2_regulator_levels_mv(struct pmic_handle_s *pmic,
342 uint8_t id, const uint16_t **levels,
343 size_t *levels_count);
344int stpmic2_regulator_get_voltage(struct pmic_handle_s *pmic,
345 uint8_t id, uint16_t *val);
346int stpmic2_regulator_set_voltage(struct pmic_handle_s *pmic,
347 uint8_t id, uint16_t millivolts);
348
Pascal Paillet3263aea2022-12-16 14:59:34 +0100349void stpmic2_dump_regulators(struct pmic_handle_s *pmic);
Pascal Paillet3263aea2022-12-16 14:59:34 +0100350
351int stpmic2_get_version(struct pmic_handle_s *pmic, uint8_t *val);
352int stpmic2_get_product_id(struct pmic_handle_s *pmic, uint8_t *val);
353
354int stpmic2_regulator_get_prop(struct pmic_handle_s *pmic, uint8_t id,
355 enum stpmic2_prop_id prop);
356
357int stpmic2_regulator_set_prop(struct pmic_handle_s *pmic, uint8_t id,
358 enum stpmic2_prop_id prop, uint32_t arg);
359
360#endif /*STPMIC2_H*/