1 /*
2 * Copyright 2016 Freescale Semiconductor, Inc.
3 * Copyright 2016 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #include "fsl_common.h"
10 #include "fsl_pf3000.h"
11
12 /*******************************************************************************
13 * Definitions
14 ******************************************************************************/
15 /* CONCTL bit-field. */
16 #define PF3000_COIN_CTRL_ENABLE_MASK (0x08U)
17 #define PF3000_COIN_CTRL_VOLT_MASK (0x07U)
18 #define PF3000_COIN_CTRL_VOLT_SHIFT (0U)
19 #define PF3000_COIN_CTRL_VOLT(x) (((uint8_t)((uint8_t)(x) << PF3000_COIN_CTRL_VOLT_SHIFT)) & PF3000_COIN_CTRL_VOLT_MASK)
20 /* PWRCTL bit-field. */
21 #define PF3000_PWR_CTRL_REGSCCP_ENABLE_MASK (0x80U)
22 #define PF3000_PWR_CTRL_STANDBYINV_MASK (0x40U)
23 #define PF3000_PWR_CTRL_STBYDLY_MASK (0x30U)
24 #define PF3000_PWR_CTRL_STBYDLY_SHIFT (4U)
25 #define PF3000_PWR_CTRL_STBYDLY(x) \
26 (((uint8_t)((uint8_t)(x) << PF3000_PWR_CTRL_STBYDLY_SHIFT)) & PF3000_PWR_CTRL_STBYDLY_MASK)
27 #define PF3000_PWR_CTRL_PWRONDBNC_MASK (0x0CU)
28 #define PF3000_PWR_CTRL_PWRONDBNC_SHIFT (2U)
29 #define PF3000_PWR_CTRL_PWRONDBNC(x) \
30 (((uint8_t)((uint8_t)(x) << PF3000_PWR_CTRL_PWRONDBNC_SHIFT)) & PF3000_PWR_CTRL_PWRONDBNC_MASK)
31 #define PF3000_PWR_CTRL_PWRONRSTEN_MASK (0x02U)
32 #define PF3000_PWR_CTRL_RESTARTEN_MASK (0x01U)
33 /* SW1XVOLT, SW1XSTBY, SW1XOFF bit-field. */
34 #define PF3000_SW1X_VOLT_CTRL_MASK (0x1FU)
35 #define PF3000_SW1X_VOLT_CTRL_SHIFT (0U)
36 #define PF3000_SW1X_VOLT_CTRL(x) (((uint8_t)((uint8_t)(x) << PF3000_SW1X_VOLT_CTRL_SHIFT)) & PF3000_SW1X_VOLT_CTRL_MASK)
37 /* SW2VOLT, SW2STBY, SW2OFF bit-field. */
38 #define PF3000_SW2_VOLT_CTRL_MASK (0x07U)
39 #define PF3000_SW2_VOLT_CTRL_SHIFT (0U)
40 #define PF3000_SW2_VOLT_CTRL(x) (((uint8_t)((uint8_t)(x) << PF3000_SW2_VOLT_CTRL_SHIFT)) & PF3000_SW2_VOLT_CTRL_MASK)
41 /* SW3VOLT, SW3STBY, SW3OFF bit-field. */
42 #define PF3000_SW3_VOLT_CTRL_MASK (0x0FU)
43 #define PF3000_SW3_VOLT_CTRL_SHIFT (0U)
44 #define PF3000_SW3_VOLT_CTRL(x) (((uint8_t)((uint8_t)(x) << PF3000_SW3_VOLT_CTRL_SHIFT)) & PF3000_SW3_VOLT_CTRL_MASK)
45 /* SW MODE bit-field. */
46 #define PF3000_SW_MODE_OFF_MASK (0x20U)
47 #define PF3000_SW_MODE_SELECTOR_MASK (0x0FU)
48 #define PF3000_SW_MODE_SELECTOR_SHIFT (0U)
49 #define PF3000_SW_MODE_SELECTOR(x) \
50 (((uint8_t)((uint8_t)(x) << PF3000_SW_MODE_SELECTOR_SHIFT)) & PF3000_SW_MODE_SELECTOR_MASK)
51 /* SW CONFIG bit-field. */
52 #define PF3000_SW_CTRL_DVSSPEED_MASK (0x40U)
53 #define PF3000_SW_CTRL_PHASE_MASK (0x30U)
54 #define PF3000_SW_CTRL_PHASE_SHIFT (4U)
55 #define PF3000_SW_CTRL_PHASE(x) (((uint8_t)((uint8_t)(x) << PF3000_SW_CTRL_PHASE_SHIFT)) & PF3000_SW_CTRL_PHASE_MASK)
56 #define PF3000_SW_CTRL_FREQUENCY_MASK (0x0CU)
57 #define PF3000_SW_CTRL_FREQUENCY_SHIFT (2U)
58 #define PF3000_SW_CTRL_FREQUENCY(x) \
59 (((uint8_t)((uint8_t)(x) << PF3000_SW_CTRL_FREQUENCY_SHIFT)) & PF3000_SW_CTRL_FREQUENCY_MASK)
60 #define PF3000_SW_CTRL_CURRENT_LIMIT_MASK (0x01U)
61 /* SW_BOOST_CTRL bit-field. */
62 #define PF3000_SW_BST_CTRL_STANDBY_MODE_MASK (0x60U)
63 #define PF3000_SW_BST_CTRL_STANDBY_MODE_SHIFT (5U)
64 #define PF3000_SW_BST_CTRL_STANDBY_MODE(x) \
65 (((uint8_t)((uint8_t)(x) << PF3000_SW_BST_CTRL_STANDBY_MODE_SHIFT)) & PF3000_SW_BST_CTRL_STANDBY_MODE_MASK)
66 #define PF3000_SW_BST_CTRL_NORMAL_MODE_MASK (0x0CU)
67 #define PF3000_SW_BST_CTRL_NORMAL_MODE_SHIFT (2U)
68 #define PF3000_SW_BST_CTRL_NORMAL_MODE(x) \
69 (((uint8_t)((uint8_t)(x) << PF3000_SW_BST_CTRL_NORMAL_MODE_SHIFT)) & PF3000_SW_BST_CTRL_NORMAL_MODE_MASK)
70 #define PF3000_SW_BST_CTRL_VOLT_MASK (0x03U)
71 #define PF3000_SW_BST_CTRL_VOLT_SHIFT (0U)
72 #define PF3000_SW_BST_CTRL_VOLT(x) \
73 (((uint8_t)((uint8_t)(x) << PF3000_SW_BST_CTRL_VOLT_SHIFT)) & PF3000_SW_BST_CTRL_VOLT_MASK)
74 /* VREFDDRCTL bit-field. */
75 #define PF3000_VREFDDR_SUPPLY_ENABLE_MASK (0x01U)
76 /* VSNVSCTL bit-field. */
77 #define PF3000_VSNVS_VOLT_CTRL_MASK (0x07U)
78 #define PF3000_VSNVS_VOLT_CTRL_SHIFT (0U)
79 #define PF3000_VSNVS_VOLT_CTRL(x) \
80 (((uint8_t)((uint8_t)(x) << PF3000_VSNVS_VOLT_CTRL_SHIFT)) & PF3000_VSNVS_VOLT_CTRL_MASK)
81 #define PF3000_VSNVS_VOLT_CTRL_VALUE (0x06U)
82 /* VLDO CTL bit-field. */
83 #define PF3000_LDO_OFF_MODE_MASK (0x80U)
84 #define PF3000_LDO_LOW_POWER_MODE_MASK (0x40U)
85 #define PF3000_LDO_STANDBY_ON_OFF_MASK (0x20U)
86 #define PF3000_LDO_ENABLE_MASK (0x10U)
87 #define PF3000_LDO_VOLT_CTRL_MASK (0x0FU)
88 #define PF3000_LDO_VOLT_CTRL_SHIFT (0U)
89 #define PF3000_LDO_VOLT_CTRL(x) (((uint8_t)((uint8_t)(x) << PF3000_LDO_VOLT_CTRL_SHIFT)) & PF3000_LDO_VOLT_CTRL_MASK)
90 /* VCC_SDCTL bit-field. */
91 #define PF3000_VCC_SD_VOLT_CTRL_MASK (0x03U)
92 #define PF3000_VCC_SD_VOLT_CTRL_SHIFT (0U)
93 #define PF3000_VCC_SD_VOLT_CTRL(x) \
94 (((uint8_t)((uint8_t)(x) << PF3000_VCC_SD_VOLT_CTRL_SHIFT)) & PF3000_VCC_SD_VOLT_CTRL_MASK)
95 /* V33 bit-field. */
96 #define PF3000_V33_VOLT_CTRL_MASK (0x03U)
97 #define PF3000_V33_VOLT_CTRL_SHIFT (0U)
98 #define PF3000_V33_VOLT_CTRL(x) (((uint8_t)((uint8_t)(x) << PF3000_V33_VOLT_CTRL_SHIFT)) & PF3000_V33_VOLT_CTRL_MASK)
99 /* Page Selection bit-field. */
100 #define PF3000_PAGE_SELECTION_MASK (0x0FU)
101 #define PF3000_PAGE_SELECTION_SHIFT (0U)
102 #define PF3000_PAGE_SELECTION(x) (((uint8_t)((uint8_t)(x) << PF3000_PAGE_SELECTION_SHIFT)) & PF3000_PAGE_SELECTION_MASK)
103
104 /* Regulator Voltage Control Helper Macros. */
105 #define PF3000_SW1A_SET_POINT_MAX_NUM (31U)
106 #define PF3000_SW1A_OUTPUT_LIMIT_LOW_DVS (700000U)
107 #define PF3000_SW1A_OUTPUT_STEP_DVS (25000U)
108 #define PF3000_SW1B_SET_POINT_MAX_NUM (31U)
109 #define PF3000_SW1B_OUTPUT_LIMIT_LOW_DVS (700000U)
110 #define PF3000_SW1B_OUTPUT_STEP_DVS (25000U)
111 #define PF3000_SW2_SET_POINT_MAX_NUM (7U)
112 #define PF3000_SW2_OUTPUT_LIMIT_LOW_DVS (1500000U)
113 #define PF3000_SW2_OUTPUT_STEP_DVS (50000U)
114 #define PF3000_SW3_SET_POINT_MAX_NUM (15U)
115 #define PF3000_SW3_OUTPUT_LIMIT_LOW_DVS (900000U)
116 #define PF3000_SW3_OUTPUT_STEP_DVS (50000U)
117 #define PF3000_SW_BST_SET_POINT_MAX_NUM (3U)
118 #define PF3000_SW_BST_OUTPUT_LIMIT_LOW_DVS (5000000U)
119 #define PF3000_SW_BST_OUTPUT_STEP_DVS (50000U)
120 #define PF3000_LDOX_SET_POINT_MAX_NUM (15U)
121 #define PF3000_LDOX_OUTPUT_LIMIT_LOW_DVS (1800000U)
122 #define PF3000_LDOX_OUTPUT_STEP_DVS (100000U)
123 #define PF3000_LDOY_SET_POINT_MAX_NUM (15U)
124 #define PF3000_LDOY_OUTPUT_LIMIT_LOW_DVS (800000U)
125 #define PF3000_LDOY_OUTPUT_STEP_DVS (50000U)
126 #define PF3000_VCC_SD_SET_POINT_MAX_NUM (3U)
127 #define PF3000_VCC_SD_OUTPUT_LIMIT_LOW_DVS (2850000U)
128 #define PF3000_VCC_SD_OUTPUT_STEP_DVS (150000U)
129 #define PF3000_V33_SET_POINT_MAX_NUM (3U)
130 #define PF3000_V33_OUTPUT_LIMIT_LOW_DVS (2850000U)
131 #define PF3000_V33_OUTPUT_STEP_DVS (150000U)
132 #define PF3000_VSNVS_OUTPUT_VOLTAGE (3000000U)
133
134 /*******************************************************************************
135 * Prototypes
136 ******************************************************************************/
137
138 /*******************************************************************************
139 * Variables
140 ******************************************************************************/
141 static const uint8_t regulatorCtrlRegTab[] = {
142 PF3000_SW1A_CONF, PF3000_SW1B_CONF, PF3000_SW2_CONF, PF3000_SW3_CONF, PF3000_SWBST_CTRL,
143 PF3000_VLDO1_CTRL, PF3000_VLDO2_CTRL, PF3000_VLDO3_CTRL, PF3000_VLDO4_CTRL, PF3000_VCC_SD_CTRL,
144 PF3000_V33_CTRL, PF3000_VSNVS_CTRL, PF3000_VREFDDR_CTRL};
145
146 static const uint8_t switchVoltRegTab[][3] = {
147 {PF3000_SW1A_VOLT, PF3000_SW1A_STBY, PF3000_SW1A_OFF},
148 {PF3000_SW1B_VOLT, PF3000_SW1B_STBY, PF3000_SW1B_OFF},
149 {PF3000_SW2_VOLT, PF3000_SW2_STBY, PF3000_SW2_OFF},
150 {PF3000_SW3_VOLT, PF3000_SW3_STBY, PF3000_SW3_OFF},
151 };
152
153 /*******************************************************************************
154 * Code
155 ******************************************************************************/
PF3000_ReadOtp(pf3000_handle_t * handle,uint8_t page,uint8_t reg,uint8_t * val)156 static bool PF3000_ReadOtp(pf3000_handle_t *handle, uint8_t page, uint8_t reg, uint8_t *val)
157 {
158 bool result = false;
159
160 assert(handle);
161 assert(val);
162 assert((page == 0x01U) || (page == 0x02U));
163
164 result = PF3000_WriteReg(handle, PF3000_PAGE_REGISTER, PF3000_PAGE_SELECTION(page));
165 if (true == result)
166 {
167 result = PF3000_ReadReg(handle, reg, val);
168 }
169
170 return result;
171 }
172
PF3000_GetRegulatorSetPoint(pf3000_handle_t * handle,pf3000_module_t module,uint32_t voltage)173 static uint8_t PF3000_GetRegulatorSetPoint(pf3000_handle_t *handle, pf3000_module_t module, uint32_t voltage)
174 {
175 uint8_t regulatorSetPoint = 0U;
176 uint32_t index;
177
178 assert(handle);
179 assert((kPF3000_ModuleSwitch1A == module) || (kPF3000_ModuleSwitch1B == module) ||
180 (kPF3000_ModuleSwitch2 == module) || (kPF3000_ModuleSwitch3 == module) ||
181 (kPF3000_ModuleSwitchBoost == module) || (kPF3000_ModuleLdo1 == module) || (kPF3000_ModuleLdo2 == module) ||
182 (kPF3000_ModuleLdo3 == module) || (kPF3000_ModuleLdo4 == module) || (kPF3000_ModuleVcc_sd == module) ||
183 (kPF3000_ModuleV33 == module));
184
185 switch (module)
186 {
187 /* Process Switch 1A. */
188 case kPF3000_ModuleSwitch1A:
189 /* Process Switch 1B. */
190 case kPF3000_ModuleSwitch1B:
191 if ((handle->switch1Mode == kPF3000_SW1SinglePhase) ||
192 ((handle->switch1Mode == kPF3000_SW1IndependentMode) && (module == kPF3000_ModuleSwitch1A)))
193 {
194 /* Find the first Vset_point <= voltage */
195 if (3300000U <= voltage)
196 {
197 index = PF3000_SW1A_SET_POINT_MAX_NUM;
198 }
199 else if (1800000U <= voltage)
200 {
201 index = PF3000_SW1A_SET_POINT_MAX_NUM - 1U;
202 }
203 else
204 {
205 for (index = PF3000_SW1A_SET_POINT_MAX_NUM - 2U; index > 0U; index--)
206 {
207 if ((PF3000_SW1A_OUTPUT_LIMIT_LOW_DVS + (PF3000_SW1A_OUTPUT_STEP_DVS * index)) <= voltage)
208 {
209 break;
210 }
211 }
212 }
213 }
214 else if ((handle->switch1Mode == kPF3000_SW1IndependentMode) && (module == kPF3000_ModuleSwitch1B))
215 {
216 /* Find the first Vset_point >= voltage */
217 for (index = PF3000_SW1B_SET_POINT_MAX_NUM; index > 0U; index--)
218 {
219 if ((PF3000_SW1B_OUTPUT_LIMIT_LOW_DVS + (PF3000_SW1B_OUTPUT_STEP_DVS * index)) <= voltage)
220 {
221 break;
222 }
223 }
224 }
225 else
226 {
227 ;
228 }
229 break;
230
231 /* Process Switch 2. */
232 case kPF3000_ModuleSwitch2:
233 /* OTP_SW2_HI= 0, SW2 is in low output voltage range */
234 if (handle->switch2Range == kPF3000_SW2LowVoltRange)
235 {
236 for (index = PF3000_SW2_SET_POINT_MAX_NUM; index > 0U; index--)
237 {
238 if ((PF3000_SW2_OUTPUT_LIMIT_LOW_DVS + (PF3000_SW2_OUTPUT_STEP_DVS * index)) <= voltage)
239 {
240 break;
241 }
242 }
243 }
244 /* OTP_SW2_HI= 1, SW2 is in high output voltage range */
245 else
246 {
247 if (3300000 <= voltage)
248 {
249 index = 0x7U;
250 }
251 else if (3200000 <= voltage)
252 {
253 index = 0x6U;
254 }
255 else if (3150000 <= voltage)
256 {
257 index = 0x5U;
258 }
259 else if (3100000 <= voltage)
260 {
261 index = 0x4U;
262 }
263 else if (3000000 <= voltage)
264 {
265 index = 0x3U;
266 }
267 else if (2850000 <= voltage)
268 {
269 index = 0x2U;
270 }
271 else if (2800000 <= voltage)
272 {
273 index = 0x1U;
274 }
275 else
276 {
277 index = 0x0U;
278 }
279 }
280 break;
281
282 /* Process Switch 3. */
283 case kPF3000_ModuleSwitch3:
284 for (index = PF3000_SW3_SET_POINT_MAX_NUM; index > 0U; index--)
285 {
286 if ((PF3000_SW3_OUTPUT_LIMIT_LOW_DVS + (PF3000_SW3_OUTPUT_STEP_DVS * index)) <= voltage)
287 {
288 break;
289 }
290 }
291 break;
292
293 /* Process Switch Boost. */
294 case kPF3000_ModuleSwitchBoost:
295 for (index = PF3000_SW_BST_SET_POINT_MAX_NUM; index > 0U; index--)
296 {
297 if ((PF3000_SW_BST_OUTPUT_LIMIT_LOW_DVS + (PF3000_SW_BST_OUTPUT_STEP_DVS * index)) <= voltage)
298 {
299 break;
300 }
301 }
302 break;
303
304 /* Process LDO X, including LDO1, LDO3, LDO4. */
305 case kPF3000_ModuleLdo1:
306 case kPF3000_ModuleLdo3:
307 case kPF3000_ModuleLdo4:
308 for (index = PF3000_LDOX_SET_POINT_MAX_NUM; index > 0U; index--)
309 {
310 if ((PF3000_LDOX_OUTPUT_LIMIT_LOW_DVS + (PF3000_LDOX_OUTPUT_STEP_DVS * index)) <= voltage)
311 {
312 break;
313 }
314 }
315 break;
316
317 /* Process LDO Y, including LDO2. */
318 case kPF3000_ModuleLdo2:
319 for (index = PF3000_LDOY_SET_POINT_MAX_NUM; index > 0U; index--)
320 {
321 if ((PF3000_LDOY_OUTPUT_LIMIT_LOW_DVS + (PF3000_LDOY_OUTPUT_STEP_DVS * index)) <= voltage)
322 {
323 break;
324 }
325 }
326 break;
327
328 /* Process Vcc_sd. */
329 case kPF3000_ModuleVcc_sd:
330 /* VSD_VSEL= 0. */
331 if (handle->vccsdVsel == 0U)
332 {
333 for (index = PF3000_VCC_SD_SET_POINT_MAX_NUM; index > 0U; index--)
334 {
335 if ((PF3000_VCC_SD_OUTPUT_LIMIT_LOW_DVS + (PF3000_VCC_SD_OUTPUT_STEP_DVS * index)) <= voltage)
336 {
337 break;
338 }
339 }
340 }
341 /* VSD_VSEL= 1. */
342 else
343 {
344 if (1850000U <= voltage)
345 {
346 index = 0x3U;
347 }
348 else
349 {
350 index = 0x0U;
351 }
352 }
353 break;
354
355 /* Process Vcc_sd. */
356 case kPF3000_ModuleV33:
357 for (index = PF3000_V33_SET_POINT_MAX_NUM; index > 0U; index--)
358 {
359 if ((PF3000_V33_OUTPUT_LIMIT_LOW_DVS + (PF3000_V33_OUTPUT_STEP_DVS * index)) <= voltage)
360 {
361 break;
362 }
363 }
364 break;
365
366 default:
367 index = 0U;
368 break;
369 }
370
371 /* Assin index to regulatorSetPoint*/
372 regulatorSetPoint = index;
373
374 return regulatorSetPoint;
375 }
376
PF3000_GetRegulatorOutputVolt(pf3000_handle_t * handle,pf3000_module_t module,uint8_t voltRegContent)377 static uint32_t PF3000_GetRegulatorOutputVolt(pf3000_handle_t *handle, pf3000_module_t module, uint8_t voltRegContent)
378 {
379 uint32_t voltage = 0U;
380
381 assert(handle);
382 assert((kPF3000_ModuleSwitch1A == module) || (kPF3000_ModuleSwitch1B == module) ||
383 (kPF3000_ModuleSwitch2 == module) || (kPF3000_ModuleSwitch3 == module) ||
384 (kPF3000_ModuleSwitchBoost == module) || (kPF3000_ModuleLdo1 == module) || (kPF3000_ModuleLdo2 == module) ||
385 (kPF3000_ModuleLdo3 == module) || (kPF3000_ModuleLdo4 == module) || (kPF3000_ModuleVcc_sd == module) ||
386 (kPF3000_ModuleV33 == module) || (kPF3000_ModuleVsnvs == module));
387
388 switch (module)
389 {
390 /* Process Switch 1A. */
391 case kPF3000_ModuleSwitch1A:
392 /* Process Switch 1B. */
393 case kPF3000_ModuleSwitch1B:
394 if ((handle->switch1Mode == kPF3000_SW1SinglePhase) ||
395 ((handle->switch1Mode == kPF3000_SW1IndependentMode) && (module == kPF3000_ModuleSwitch1A)))
396 {
397 if (voltRegContent <= (PF3000_SW1A_SET_POINT_MAX_NUM - 2))
398 {
399 voltage = PF3000_SW1A_OUTPUT_LIMIT_LOW_DVS + PF3000_SW1A_OUTPUT_STEP_DVS * voltRegContent;
400 }
401 else if (voltRegContent == (PF3000_SW1A_SET_POINT_MAX_NUM - 1))
402 {
403 voltage = 1800000U;
404 }
405 else if (voltRegContent == (PF3000_SW1A_SET_POINT_MAX_NUM))
406 {
407 voltage = 3300000U;
408 }
409 else
410 {
411 ;
412 }
413 }
414 else if ((handle->switch1Mode == kPF3000_SW1IndependentMode) && (module == kPF3000_ModuleSwitch1B))
415 {
416 voltage = PF3000_SW1B_OUTPUT_LIMIT_LOW_DVS + PF3000_SW1B_OUTPUT_STEP_DVS * voltRegContent;
417 }
418 else
419 {
420 ;
421 }
422 break;
423
424 /* Process Switch 2. */
425 case kPF3000_ModuleSwitch2:
426 /* OTP_SW2_HI= 0, SW2 is in low output voltage range */
427 if (handle->switch2Range == kPF3000_SW2LowVoltRange)
428 {
429 voltage = PF3000_SW3_OUTPUT_LIMIT_LOW_DVS + PF3000_SW3_OUTPUT_STEP_DVS * voltRegContent;
430 }
431 /* OTP_SW2_HI= 1, SW2 is in high output voltage range */
432 else
433 {
434 switch (voltRegContent)
435 {
436 case 0x0U:
437 voltage = 2500000U;
438 break;
439 case 0x1U:
440 voltage = 2800000U;
441 break;
442 case 0x2U:
443 voltage = 2850000U;
444 break;
445 case 0x3U:
446 voltage = 3000000U;
447 break;
448 case 0x4U:
449 voltage = 3100000U;
450 break;
451 case 0x5U:
452 voltage = 3150000U;
453 break;
454 case 0x6U:
455 voltage = 3200000U;
456 break;
457 case 0x7U:
458 voltage = 3300000U;
459 break;
460 default:
461 voltage = 0U;
462 break;
463 }
464 }
465 break;
466
467 /* Process Switch 3. */
468 case kPF3000_ModuleSwitch3:
469 voltage = PF3000_SW3_OUTPUT_LIMIT_LOW_DVS + PF3000_SW3_OUTPUT_STEP_DVS * voltRegContent;
470 break;
471
472 /* Process Switch Boost. */
473 case kPF3000_ModuleSwitchBoost:
474 voltage = PF3000_SW_BST_OUTPUT_LIMIT_LOW_DVS + PF3000_SW_BST_OUTPUT_STEP_DVS * voltRegContent;
475 break;
476
477 /* Process LDO X, including LDO1, LDO3, LDO4. */
478 case kPF3000_ModuleLdo1:
479 case kPF3000_ModuleLdo3:
480 case kPF3000_ModuleLdo4:
481 voltage = PF3000_LDOX_OUTPUT_LIMIT_LOW_DVS + PF3000_LDOX_OUTPUT_STEP_DVS * voltRegContent;
482 break;
483
484 /* Process LDO Y, including LDO2. */
485 case kPF3000_ModuleLdo2:
486 voltage = PF3000_LDOY_OUTPUT_LIMIT_LOW_DVS + PF3000_LDOY_OUTPUT_STEP_DVS * voltRegContent;
487 break;
488
489 /* Process Vcc_sd. */
490 case kPF3000_ModuleVcc_sd:
491 /* VSD_VSEL= 0. */
492 if (handle->vccsdVsel == 0U)
493 {
494 voltage = PF3000_VCC_SD_OUTPUT_LIMIT_LOW_DVS + PF3000_VCC_SD_OUTPUT_STEP_DVS * voltRegContent;
495 }
496 /* VSD_VSEL= 1. */
497 else
498 {
499 if (voltRegContent == 3U)
500 {
501 voltage = 1850000U;
502 }
503 else
504 {
505 voltage = 1800000U;
506 }
507 }
508 break;
509
510 /* Process Vcc_sd. */
511 case kPF3000_ModuleV33:
512 voltage = PF3000_V33_OUTPUT_LIMIT_LOW_DVS + PF3000_V33_OUTPUT_STEP_DVS * voltRegContent;
513 break;
514
515 /* Process Vsnvs. It's fixed in 3.0V, can't be changed. */
516 case kPF3000_ModuleVsnvs:
517 assert(voltRegContent == PF3000_VSNVS_VOLT_CTRL_VALUE);
518 voltage = PF3000_VSNVS_OUTPUT_VOLTAGE;
519 break;
520
521 default:
522 break;
523 }
524
525 return voltage;
526 }
527
PF3000_GetDefaultConfig(pf3000_config_t * config)528 void PF3000_GetDefaultConfig(pf3000_config_t *config)
529 {
530 assert(config);
531
532 /* Set callback function to NULL Pointer. */
533 config->I2C_SendFunc = NULL;
534 config->I2C_ReceiveFunc = NULL;
535
536 /* Set Default Slave Address. */
537 config->slaveAddress = PF3000_DEFAULT_I2C_ADDR;
538 /* Short-circuit protection enabled. */
539 config->enableRegSCP = true;
540 /* VSD_VSEL. */
541 config->vccsdVsel = 0U;
542 }
543
PF3000_Init(pf3000_handle_t * handle,const pf3000_config_t * config)544 void PF3000_Init(pf3000_handle_t *handle, const pf3000_config_t *config)
545 {
546 uint8_t temp;
547 uint8_t regValue;
548
549 assert(handle);
550 assert(config);
551
552 /* Initialize Callback functions. */
553 handle->I2C_SendFunc = config->I2C_SendFunc;
554 handle->I2C_ReceiveFunc = config->I2C_ReceiveFunc;
555 /* Set Slave Address. */
556 handle->slaveAddress = config->slaveAddress;
557
558 /* Modify Switch Mode Register Value. */
559 temp = (config->enableRegSCP ? PF3000_PWR_CTRL_REGSCCP_ENABLE_MASK : 0U);
560
561 PF3000_ModifyReg(handle, PF3000_PWR_CTRL, PF3000_PWR_CTRL_REGSCCP_ENABLE_MASK, temp);
562
563 /* VSD_VSEL. */
564 handle->vccsdVsel = config->vccsdVsel;
565
566 /* Read the register value of OTP SW1x CONFIG */
567 PF3000_ReadOtp(handle, 0x01U, PF3000_OTP_SW1x_CONFIG, ®Value);
568 /* SW1A SW1B mode selection. */
569 handle->switch1Mode = (pf3000_switch1_mode_t)((regValue & 0x0CU) >> 2U);
570
571 assert((handle->switch1Mode == kPF3000_SW1SinglePhase) || (handle->switch1Mode == kPF3000_SW1IndependentMode));
572
573 /* Read the register value of OTP SW2 VOLT */
574 PF3000_ReadOtp(handle, 0x01U, PF3000_OTP_SW2_VOLT, ®Value);
575 /* SW2 voltage range. */
576 handle->switch2Range = (regValue & 0x08U) ? (kPF3000_SW2HighVoltRange) : (kPF3000_SW2LowVoltRange);
577 }
578
PF3000_WriteReg(pf3000_handle_t * handle,uint8_t reg,uint8_t val)579 bool PF3000_WriteReg(pf3000_handle_t *handle, uint8_t reg, uint8_t val)
580 {
581 assert(handle);
582 assert(handle->I2C_SendFunc);
583
584 return handle->I2C_SendFunc(handle->slaveAddress, reg, 1U, &val, 1U);
585 }
586
PF3000_ReadReg(pf3000_handle_t * handle,uint8_t reg,uint8_t * val)587 bool PF3000_ReadReg(pf3000_handle_t *handle, uint8_t reg, uint8_t *val)
588 {
589 assert(handle);
590 assert(handle->I2C_ReceiveFunc);
591 assert(val);
592
593 return handle->I2C_ReceiveFunc(handle->slaveAddress, reg, 1U, val, 1U);
594 }
595
PF3000_ModifyReg(pf3000_handle_t * handle,uint8_t reg,uint8_t mask,uint8_t val)596 bool PF3000_ModifyReg(pf3000_handle_t *handle, uint8_t reg, uint8_t mask, uint8_t val)
597 {
598 bool result = false;
599 uint8_t regValue;
600
601 assert(handle);
602
603 /* Read back the register content. */
604 result = PF3000_ReadReg(handle, reg, ®Value);
605 if (true == result)
606 {
607 /* Modify the bit-fields you want to change. */
608 regValue &= (uint8_t)~mask;
609 regValue |= val;
610
611 /* Write back the content to the registers. */
612 result = PF3000_WriteReg(handle, reg, regValue);
613 }
614
615 return result;
616 }
617
PF3000_DumpReg(pf3000_handle_t * handle,uint8_t page,uint8_t reg,uint8_t * buffer,uint8_t size)618 bool PF3000_DumpReg(pf3000_handle_t *handle, uint8_t page, uint8_t reg, uint8_t *buffer, uint8_t size)
619 {
620 bool result = true;
621 uint8_t i;
622
623 assert(handle);
624 assert(buffer);
625 assert((page == 0x00U) || (page == 0x01U) || (page == 0x02U));
626
627 PF3000_WriteReg(handle, PF3000_PAGE_REGISTER, PF3000_PAGE_SELECTION(page));
628
629 /* It seems that PF3000 only supports single-byte I2C transactions
630 for read and write. */
631 for (i = 0; i < size; i++)
632 {
633 if (false == PF3000_ReadReg(handle, reg++, buffer++))
634 {
635 result = false;
636 }
637 }
638
639 return result;
640 }
641
PF3000_EnableInterrupts(pf3000_handle_t * handle,uint32_t source)642 void PF3000_EnableInterrupts(pf3000_handle_t *handle, uint32_t source)
643 {
644 assert(handle);
645
646 /* Enable INTSTAT0 interrupts. */
647 PF3000_ModifyReg(handle, PF3000_SW_INT_MASK0, (source & 0xFFU), 0x0U);
648 /* Enable INTSTAT1 interrupts. */
649 PF3000_ModifyReg(handle, PF3000_SW_INT_MASK1, ((source & 0xFF00U) >> 8U), 0x0U);
650 /* Enable INTSTAT3 interrupts. */
651 PF3000_ModifyReg(handle, PF3000_SW_INT_MASK3, ((source & 0xFF0000U) >> 16U), 0x0U);
652 /* Enable INTSTAT4 interrupts. */
653 PF3000_ModifyReg(handle, PF3000_SW_INT_MASK4, ((source & 0xFF000000U) >> 24), 0x0U);
654 }
655
PF3000_DisableInterrupts(pf3000_handle_t * handle,uint32_t source)656 void PF3000_DisableInterrupts(pf3000_handle_t *handle, uint32_t source)
657 {
658 assert(handle);
659
660 /* Enable INTSTAT0 interrupts. */
661 PF3000_ModifyReg(handle, PF3000_SW_INT_MASK0, 0x0U, (source & 0xFFU));
662 /* Enable INTSTAT1 interrupts. */
663 PF3000_ModifyReg(handle, PF3000_SW_INT_MASK1, 0x0U, ((source & 0xFF00U) >> 8U));
664 /* Enable INTSTAT3 interrupts. */
665 PF3000_ModifyReg(handle, PF3000_SW_INT_MASK3, 0x0U, ((source & 0xFF0000U) >> 16U));
666 /* Enable INTSTAT4 interrupts. */
667 PF3000_ModifyReg(handle, PF3000_SW_INT_MASK4, 0x0U, ((source & 0xFF000000U) >> 24));
668 }
669
PF3000_GetInterruptStatus(pf3000_handle_t * handle)670 uint32_t PF3000_GetInterruptStatus(pf3000_handle_t *handle)
671 {
672 uint32_t status = 0x0U;
673 uint8_t temp;
674
675 assert(handle);
676
677 /* Get INTSTAT0 interrupts flag. */
678 PF3000_ReadReg(handle, PF3000_SW_INT_STAT0, &temp);
679 status = temp;
680
681 /* Get INTSTAT1 interrupts flag. */
682 PF3000_ReadReg(handle, PF3000_SW_INT_STAT1, &temp);
683 status |= (uint32_t)((uint32_t)temp << 8U);
684
685 /* Get INTSTAT3 interrupts flag. */
686 PF3000_ReadReg(handle, PF3000_SW_INT_STAT3, &temp);
687 status |= (uint32_t)((uint32_t)temp << 16U);
688
689 /* Get INTSTAT4 interrupts flag. */
690 PF3000_ReadReg(handle, PF3000_SW_INT_STAT4, &temp);
691 status |= (uint32_t)((uint32_t)temp << 24U);
692
693 return status;
694 }
695
PF3000_ClearInterruptStatus(pf3000_handle_t * handle,uint32_t source)696 void PF3000_ClearInterruptStatus(pf3000_handle_t *handle, uint32_t source)
697 {
698 assert(handle);
699
700 /* Clear INTSTAT0 interrupts flag. */
701 PF3000_WriteReg(handle, PF3000_SW_INT_STAT0, (source & 0xFFU));
702 /* Clear INTSTAT1 interrupts flag. */
703 PF3000_WriteReg(handle, PF3000_SW_INT_STAT1, ((source & 0xFF00U) >> 8U));
704 /* Clear INTSTAT3 interrupts flag. */
705 PF3000_WriteReg(handle, PF3000_SW_INT_STAT3, ((source & 0xFF0000U) >> 16U));
706 /* Clear INTSTAT4 interrupts flag. */
707 PF3000_WriteReg(handle, PF3000_SW_INT_STAT4, ((source & 0xFF000000U) >> 24U));
708 }
709
PF3000_SetRegulatorOutputVoltage(pf3000_handle_t * handle,pf3000_module_t module,pf3000_operating_status_t status,uint32_t voltage)710 void PF3000_SetRegulatorOutputVoltage(pf3000_handle_t *handle,
711 pf3000_module_t module,
712 pf3000_operating_status_t status,
713 uint32_t voltage)
714 {
715 uint8_t regulatorVoltRegAddr;
716 uint8_t regulatorVoltRegContent;
717 uint8_t regulatorVoltRegMask;
718
719 assert(handle);
720 assert((kPF3000_ModuleSwitch1A == module) || (kPF3000_ModuleSwitch1B == module) ||
721 (kPF3000_ModuleSwitch2 == module) || (kPF3000_ModuleSwitch3 == module) ||
722 (kPF3000_ModuleSwitchBoost == module) || (kPF3000_ModuleLdo1 == module) || (kPF3000_ModuleLdo2 == module) ||
723 (kPF3000_ModuleLdo3 == module) || (kPF3000_ModuleLdo4 == module) || (kPF3000_ModuleVcc_sd == module) ||
724 (kPF3000_ModuleV33 == module));
725
726 assert((kPF3000_OperatingStatusSystemOn == status) || (kPF3000_OperatingStatusStandby == status) ||
727 (kPF3000_OperatingStatusOff == status));
728
729 /* Get Register Value. */
730 regulatorVoltRegContent = PF3000_GetRegulatorSetPoint(handle, module, voltage);
731
732 switch (module)
733 {
734 /* Process SW1A, SW1B. */
735 case kPF3000_ModuleSwitch1A:
736 case kPF3000_ModuleSwitch1B:
737 regulatorVoltRegAddr = switchVoltRegTab[module][status];
738 regulatorVoltRegContent = PF3000_SW1X_VOLT_CTRL(regulatorVoltRegContent);
739 regulatorVoltRegMask = PF3000_SW1X_VOLT_CTRL_MASK;
740 break;
741
742 /* Process SW2. */
743 case kPF3000_ModuleSwitch2:
744 regulatorVoltRegAddr = switchVoltRegTab[module][status];
745 regulatorVoltRegContent = PF3000_SW2_VOLT_CTRL(regulatorVoltRegContent);
746 regulatorVoltRegMask = PF3000_SW2_VOLT_CTRL_MASK;
747 break;
748
749 /* Process SW3. */
750 case kPF3000_ModuleSwitch3:
751 regulatorVoltRegAddr = switchVoltRegTab[module][status];
752 regulatorVoltRegContent = PF3000_SW3_VOLT_CTRL(regulatorVoltRegContent);
753 regulatorVoltRegMask = PF3000_SW3_VOLT_CTRL_MASK;
754 break;
755
756 /* Process Switch Boost. */
757 case kPF3000_ModuleSwitchBoost:
758 regulatorVoltRegAddr = PF3000_SWBST_CTRL;
759 regulatorVoltRegContent = PF3000_SW_BST_CTRL_VOLT(regulatorVoltRegContent);
760 regulatorVoltRegMask = PF3000_SW_BST_CTRL_VOLT_MASK;
761 break;
762
763 /* Process LDO1, LDO2, LDO3, LDO4. */
764 case kPF3000_ModuleLdo1:
765 case kPF3000_ModuleLdo2:
766 case kPF3000_ModuleLdo3:
767 case kPF3000_ModuleLdo4:
768 regulatorVoltRegAddr = regulatorCtrlRegTab[module];
769 regulatorVoltRegContent = PF3000_LDO_VOLT_CTRL(regulatorVoltRegContent);
770 regulatorVoltRegMask = PF3000_LDO_VOLT_CTRL_MASK;
771 break;
772
773 /* Process Vcc_sd. */
774 case kPF3000_ModuleVcc_sd:
775 regulatorVoltRegAddr = regulatorCtrlRegTab[module];
776 regulatorVoltRegContent = PF3000_VCC_SD_VOLT_CTRL(regulatorVoltRegContent);
777 regulatorVoltRegMask = PF3000_VCC_SD_VOLT_CTRL_MASK;
778 break;
779
780 /* Process V33. */
781 case kPF3000_ModuleV33:
782 regulatorVoltRegAddr = regulatorCtrlRegTab[module];
783 regulatorVoltRegContent = PF3000_V33_VOLT_CTRL(regulatorVoltRegContent);
784 regulatorVoltRegMask = PF3000_V33_VOLT_CTRL_MASK;
785 break;
786
787 default:
788 regulatorVoltRegAddr = 0x00U;
789 regulatorVoltRegMask = 0x00U;
790 break;
791 }
792
793 /* Modify corresponding registers. */
794 PF3000_ModifyReg(handle, regulatorVoltRegAddr, regulatorVoltRegMask, regulatorVoltRegContent);
795 }
796
PF3000_GetRegulatorOutputVoltage(pf3000_handle_t * handle,pf3000_module_t module,pf3000_operating_status_t status)797 uint32_t PF3000_GetRegulatorOutputVoltage(pf3000_handle_t *handle,
798 pf3000_module_t module,
799 pf3000_operating_status_t status)
800 {
801 uint8_t regulatorVoltRegAddr;
802 uint8_t regulatorVoltRegContent;
803 uint8_t regulatorVoltRegMask;
804 uint32_t voltage = 0U;
805
806 assert(handle);
807 assert((kPF3000_ModuleSwitch1A == module) || (kPF3000_ModuleSwitch1B == module) ||
808 (kPF3000_ModuleSwitch2 == module) || (kPF3000_ModuleSwitch3 == module) ||
809 (kPF3000_ModuleSwitchBoost == module) || (kPF3000_ModuleLdo1 == module) || (kPF3000_ModuleLdo2 == module) ||
810 (kPF3000_ModuleLdo3 == module) || (kPF3000_ModuleLdo4 == module) || (kPF3000_ModuleVcc_sd == module) ||
811 (kPF3000_ModuleV33 == module) || (kPF3000_ModuleVsnvs == module));
812
813 assert((kPF3000_OperatingStatusSystemOn == status) || (kPF3000_OperatingStatusStandby == status) ||
814 (kPF3000_OperatingStatusOff == status));
815
816 switch (module)
817 {
818 /* Process SW1A, SW1B. */
819 case kPF3000_ModuleSwitch1A:
820 case kPF3000_ModuleSwitch1B:
821 regulatorVoltRegAddr = switchVoltRegTab[module][status];
822 regulatorVoltRegMask = PF3000_SW1X_VOLT_CTRL_MASK;
823 break;
824
825 /* Process SW2. */
826 case kPF3000_ModuleSwitch2:
827 regulatorVoltRegAddr = switchVoltRegTab[module][status];
828 regulatorVoltRegMask = PF3000_SW2_VOLT_CTRL_MASK;
829 break;
830
831 /* Process SW3. */
832 case kPF3000_ModuleSwitch3:
833 regulatorVoltRegAddr = switchVoltRegTab[module][status];
834 regulatorVoltRegMask = PF3000_SW3_VOLT_CTRL_MASK;
835 break;
836
837 /* Process Switch Boost. */
838 case kPF3000_ModuleSwitchBoost:
839 regulatorVoltRegAddr = regulatorCtrlRegTab[module];
840 regulatorVoltRegMask = PF3000_SW_BST_CTRL_VOLT_MASK;
841 break;
842
843 /* Process LDO1, LDO2, LDO3, LDO4. */
844 case kPF3000_ModuleLdo1:
845 case kPF3000_ModuleLdo2:
846 case kPF3000_ModuleLdo3:
847 case kPF3000_ModuleLdo4:
848 regulatorVoltRegAddr = regulatorCtrlRegTab[module];
849 regulatorVoltRegMask = PF3000_LDO_VOLT_CTRL_MASK;
850 break;
851
852 /* Process Vcc_sd. */
853 case kPF3000_ModuleVcc_sd:
854 regulatorVoltRegAddr = regulatorCtrlRegTab[module];
855 regulatorVoltRegMask = PF3000_VCC_SD_VOLT_CTRL_MASK;
856 break;
857
858 /* Process V33. */
859 case kPF3000_ModuleV33:
860 regulatorVoltRegAddr = regulatorCtrlRegTab[module];
861 regulatorVoltRegMask = PF3000_V33_VOLT_CTRL_MASK;
862 break;
863
864 /* Process Vsnvs. */
865 case kPF3000_ModuleVsnvs:
866 regulatorVoltRegAddr = regulatorCtrlRegTab[module];
867 regulatorVoltRegMask = PF3000_VSNVS_VOLT_CTRL_MASK;
868 break;
869
870 default:
871 regulatorVoltRegAddr = 0x00U;
872 regulatorVoltRegMask = 0x00U;
873 break;
874 }
875
876 /* Get Register Value. */
877 PF3000_ReadReg(handle, regulatorVoltRegAddr, ®ulatorVoltRegContent);
878 /* Modify Register Value. */
879 regulatorVoltRegContent = regulatorVoltRegContent & regulatorVoltRegMask;
880 /* Get LDO Voltage Control Value. */
881 voltage = PF3000_GetRegulatorOutputVolt(handle, module, regulatorVoltRegContent);
882
883 return voltage;
884 }
885
PF3000_EnableRegulator(pf3000_handle_t * handle,pf3000_module_t module,bool enable)886 void PF3000_EnableRegulator(pf3000_handle_t *handle, pf3000_module_t module, bool enable)
887 {
888 uint8_t regulatorCtrlRegAddr;
889
890 assert(handle);
891 assert((kPF3000_ModuleSwitch1A == module) || (kPF3000_ModuleSwitch1B == module) ||
892 (kPF3000_ModuleSwitch2 == module) || (kPF3000_ModuleSwitch3 == module) ||
893 (kPF3000_ModuleSwitchBoost == module) || (kPF3000_ModuleLdo1 == module) || (kPF3000_ModuleLdo2 == module) ||
894 (kPF3000_ModuleLdo3 == module) || (kPF3000_ModuleLdo4 == module) || (kPF3000_ModuleVcc_sd == module) ||
895 (kPF3000_ModuleV33 == module) || (kPF3000_ModuleVsnvs == module) || (kPF3000_ModuleVrefDdr == module));
896
897 switch (module)
898 {
899 case kPF3000_ModuleLdo1:
900 case kPF3000_ModuleLdo2:
901 case kPF3000_ModuleLdo3:
902 case kPF3000_ModuleLdo4:
903 case kPF3000_ModuleVcc_sd:
904 case kPF3000_ModuleV33:
905 /* Get LDO Control Register Address. */
906 regulatorCtrlRegAddr = regulatorCtrlRegTab[module];
907 /* Modify LDO Control Register Value. */
908 PF3000_ModifyReg(handle, regulatorCtrlRegAddr, PF3000_LDO_ENABLE_MASK,
909 (enable ? PF3000_LDO_ENABLE_MASK : 0x0U));
910 break;
911
912 case kPF3000_ModuleVrefDdr:
913 /* Modify Vrefddr Control Register Value. */
914 PF3000_ModifyReg(handle, PF3000_VREFDDR_CTRL, PF3000_VREFDDR_SUPPLY_ENABLE_MASK,
915 (enable ? PF3000_VREFDDR_SUPPLY_ENABLE_MASK : 0x0U));
916 break;
917
918 case kPF3000_ModuleSwitch1A:
919 case kPF3000_ModuleSwitch1B:
920 case kPF3000_ModuleSwitch2:
921 case kPF3000_ModuleSwitch3:
922 case kPF3000_ModuleSwitchBoost:
923 case kPF3000_ModuleVsnvs:
924 default:
925 break;
926 }
927 }
928
PF3000_IsRegulatorEnabled(pf3000_handle_t * handle,pf3000_module_t module)929 bool PF3000_IsRegulatorEnabled(pf3000_handle_t *handle, pf3000_module_t module)
930 {
931 bool result;
932 uint8_t regulatorCtrlRegAddr;
933 uint8_t regulatorCtrlRegContent;
934
935 assert(handle);
936 assert((kPF3000_ModuleSwitch1A == module) || (kPF3000_ModuleSwitch1B == module) ||
937 (kPF3000_ModuleSwitch2 == module) || (kPF3000_ModuleSwitch3 == module) ||
938 (kPF3000_ModuleSwitchBoost == module) || (kPF3000_ModuleLdo1 == module) || (kPF3000_ModuleLdo2 == module) ||
939 (kPF3000_ModuleLdo3 == module) || (kPF3000_ModuleLdo4 == module) || (kPF3000_ModuleVcc_sd == module) ||
940 (kPF3000_ModuleV33 == module) || (kPF3000_ModuleVsnvs == module) || (kPF3000_ModuleVrefDdr == module));
941
942 switch (module)
943 {
944 case kPF3000_ModuleLdo1:
945 case kPF3000_ModuleLdo2:
946 case kPF3000_ModuleLdo3:
947 case kPF3000_ModuleLdo4:
948 case kPF3000_ModuleVcc_sd:
949 case kPF3000_ModuleV33:
950 /* Get LDO Control Register Content. */
951 regulatorCtrlRegAddr = regulatorCtrlRegTab[module];
952 /* Read LDO Control Register Value. */
953 PF3000_ReadReg(handle, regulatorCtrlRegAddr, ®ulatorCtrlRegContent);
954 /* LDO enable judge */
955 result = (regulatorCtrlRegContent & PF3000_LDO_ENABLE_MASK) ? true : false;
956 break;
957
958 case kPF3000_ModuleVrefDdr:
959 /* Get Vrefddr Control Register Content. */
960 regulatorCtrlRegAddr = regulatorCtrlRegTab[module];
961 /* Read Vrefddr Control Register Value. */
962 PF3000_ReadReg(handle, regulatorCtrlRegAddr, ®ulatorCtrlRegContent);
963 /* Vrefddr enable judge */
964 result = (regulatorCtrlRegContent & PF3000_VREFDDR_SUPPLY_ENABLE_MASK) ? true : false;
965 break;
966
967 case kPF3000_ModuleSwitch1A:
968 case kPF3000_ModuleSwitch1B:
969 case kPF3000_ModuleSwitch2:
970 case kPF3000_ModuleSwitch3:
971 case kPF3000_ModuleSwitchBoost:
972 case kPF3000_ModuleVsnvs:
973 /* They are enabled by default */
974 result = true;
975 break;
976
977 default:
978 result = false;
979 break;
980 }
981
982 return result;
983 }
984
PF3000_SetSwitchAttribute(pf3000_handle_t * handle,pf3000_module_t module,const pf3000_switch_attribute_t * attribute)985 void PF3000_SetSwitchAttribute(pf3000_handle_t *handle,
986 pf3000_module_t module,
987 const pf3000_switch_attribute_t *attribute)
988 {
989 uint8_t switchModeRegAddr;
990 uint8_t switchCtrlRegAddr;
991 uint8_t temp;
992
993 assert(handle);
994 assert(attribute);
995 assert((kPF3000_ModuleSwitch1A == module) || (kPF3000_ModuleSwitch1B == module) ||
996 (kPF3000_ModuleSwitch2 == module) || (kPF3000_ModuleSwitch3 == module));
997
998 /* Set Switch Mode Register. */
999 switch (module)
1000 {
1001 case kPF3000_ModuleSwitch1A:
1002 switchModeRegAddr = PF3000_SW1A_MODE;
1003 break;
1004
1005 case kPF3000_ModuleSwitch1B:
1006 switchModeRegAddr = PF3000_SW1B_MODE;
1007 break;
1008
1009 case kPF3000_ModuleSwitch2:
1010 switchModeRegAddr = PF3000_SW2_MODE;
1011 break;
1012
1013 case kPF3000_ModuleSwitch3:
1014 switchModeRegAddr = PF3000_SW3_MODE;
1015 break;
1016
1017 default:
1018 switchModeRegAddr = 0x00U;
1019 break;
1020 }
1021
1022 /* Modify Switch Mode Register Value. */
1023 temp = ((attribute->offMode ? PF3000_SW_MODE_OFF_MASK : 0U) | (PF3000_SW_MODE_SELECTOR(attribute->mode)));
1024
1025 PF3000_ModifyReg(handle, switchModeRegAddr, PF3000_SW_MODE_OFF_MASK | PF3000_SW_MODE_SELECTOR_MASK, temp);
1026
1027 /* Set Switch Control Register. */
1028 switchCtrlRegAddr = regulatorCtrlRegTab[module];
1029
1030 /* Modify Switch Control Register Value. */
1031 temp = ((attribute->dvsSpeed ? PF3000_SW_CTRL_DVSSPEED_MASK : 0U) | (PF3000_SW_CTRL_PHASE(attribute->phaseClock)) |
1032 (PF3000_SW_CTRL_FREQUENCY(attribute->frequency)) |
1033 (attribute->currentLimit ? PF3000_SW_CTRL_CURRENT_LIMIT_MASK : 0U));
1034
1035 PF3000_ModifyReg(handle, switchCtrlRegAddr,
1036 PF3000_SW_CTRL_DVSSPEED_MASK | PF3000_SW_CTRL_PHASE_MASK | PF3000_SW_CTRL_FREQUENCY_MASK |
1037 PF3000_SW_CTRL_CURRENT_LIMIT_MASK,
1038 temp);
1039 }
1040
PF3000_SetSwitchBoostAttribute(pf3000_handle_t * handle,const pf3000_switch_boost_attribute_t * attribute)1041 void PF3000_SetSwitchBoostAttribute(pf3000_handle_t *handle, const pf3000_switch_boost_attribute_t *attribute)
1042 {
1043 uint8_t switchBoostCtrlRegAddr;
1044 uint8_t temp;
1045
1046 assert(handle);
1047 assert(attribute);
1048
1049 switchBoostCtrlRegAddr = regulatorCtrlRegTab[kPF3000_ModuleSwitchBoost];
1050
1051 temp = (PF3000_SW_BST_CTRL_STANDBY_MODE(attribute->standbyMode) |
1052 PF3000_SW_BST_CTRL_NORMAL_MODE(attribute->normalMode));
1053
1054 PF3000_ModifyReg(handle, switchBoostCtrlRegAddr,
1055 PF3000_SW_BST_CTRL_STANDBY_MODE_MASK | PF3000_SW_BST_CTRL_NORMAL_MODE_MASK, temp);
1056 }
1057
PF3000_SetLdoAttribute(pf3000_handle_t * handle,pf3000_module_t module,const pf3000_ldo_attribute_t * attribute)1058 void PF3000_SetLdoAttribute(pf3000_handle_t *handle, pf3000_module_t module, const pf3000_ldo_attribute_t *attribute)
1059 {
1060 uint8_t ldoCtrlRegAddr;
1061 uint8_t temp;
1062
1063 assert(handle);
1064 assert(attribute);
1065 assert((kPF3000_ModuleLdo1 == module) || (kPF3000_ModuleLdo2 == module) || (kPF3000_ModuleLdo3 == module) ||
1066 (kPF3000_ModuleLdo4 == module) || (kPF3000_ModuleVcc_sd == module) || (kPF3000_ModuleV33 == module));
1067
1068 /* Set LDO to load switch mode. */
1069 ldoCtrlRegAddr = regulatorCtrlRegTab[module];
1070
1071 temp = ((attribute->offMode ? PF3000_LDO_OFF_MODE_MASK : 0) |
1072 (attribute->enableLowPower ? PF3000_LDO_LOW_POWER_MODE_MASK : 0) |
1073 ((attribute->standbyOnOff == kPF3000_LdoOffDuringStandby) ? PF3000_LDO_STANDBY_ON_OFF_MASK : 0));
1074
1075 PF3000_ModifyReg(handle, ldoCtrlRegAddr,
1076 PF3000_LDO_OFF_MODE_MASK | PF3000_LDO_LOW_POWER_MODE_MASK | PF3000_LDO_STANDBY_ON_OFF_MASK, temp);
1077 }
1078
PF3000_SetCoinCellAttribute(pf3000_handle_t * handle,const pf3000_coin_cell_attribute_t * attribute)1079 void PF3000_SetCoinCellAttribute(pf3000_handle_t *handle, const pf3000_coin_cell_attribute_t *attribute)
1080 {
1081 uint8_t temp;
1082
1083 assert(handle);
1084 assert(attribute);
1085
1086 temp = ((attribute->enableCoinCellCharger ? PF3000_COIN_CTRL_ENABLE_MASK : 0) |
1087 PF3000_COIN_CTRL_VOLT(attribute->coinCellChargingVoltage));
1088
1089 /* Set Coin Cell Control Register. */
1090 PF3000_ModifyReg(handle, PF3000_COIN_CTRL, PF3000_COIN_CTRL_ENABLE_MASK | PF3000_COIN_CTRL_VOLT_MASK, temp);
1091 }
1092
PF3000_SetStandbyPadAttribute(pf3000_handle_t * handle,const pf3000_standby_attribute_t * attribute)1093 void PF3000_SetStandbyPadAttribute(pf3000_handle_t *handle, const pf3000_standby_attribute_t *attribute)
1094 {
1095 uint8_t temp;
1096
1097 assert(handle);
1098 assert(attribute);
1099
1100 temp = ((attribute->standbyPolarity ? PF3000_PWR_CTRL_STANDBYINV_MASK : 0U) |
1101 PF3000_PWR_CTRL_STBYDLY(attribute->standbyDelay));
1102
1103 /* Set Coin Cell Control Register. */
1104 PF3000_ModifyReg(handle, PF3000_PWR_CTRL, PF3000_PWR_CTRL_STANDBYINV_MASK | PF3000_PWR_CTRL_STBYDLY_MASK, temp);
1105 }
1106
PF3000_SetPwrOnPadAttibute(pf3000_handle_t * handle,const pf3000_power_on_attribute_t * attribute)1107 void PF3000_SetPwrOnPadAttibute(pf3000_handle_t *handle, const pf3000_power_on_attribute_t *attribute)
1108 {
1109 uint8_t temp;
1110
1111 assert(handle);
1112 assert(attribute);
1113
1114 temp = (PF3000_PWR_CTRL_PWRONDBNC(attribute->debounce) |
1115 (attribute->longPressAllowOffMode ? PF3000_PWR_CTRL_PWRONRSTEN_MASK : 0U) |
1116 (attribute->longPressRestart ? PF3000_PWR_CTRL_RESTARTEN_MASK : 0U));
1117
1118 /* Set Coin Cell Control Register. */
1119 PF3000_ModifyReg(handle, PF3000_PWR_CTRL,
1120 PF3000_PWR_CTRL_PWRONDBNC_MASK | PF3000_PWR_CTRL_PWRONRSTEN_MASK | PF3000_PWR_CTRL_RESTARTEN_MASK,
1121 temp);
1122 }
1123 /*******************************************************************************
1124 * EOF
1125 ******************************************************************************/
1126