1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "fsl_common.h"
10 #include "fsl_pf1550.h"
11 
12 /*******************************************************************************
13  * Definitions
14  ******************************************************************************/
15 /* INT_CATEGORY bit-field. */
16 #define PF1550_INT_CATEGORY_CHG_INT_MASK   (0x01U)
17 #define PF1550_INT_CATEGORY_SW1_INT_MASK   (0x02U)
18 #define PF1550_INT_CATEGORY_SW2_INT_MASK   (0x04U)
19 #define PF1550_INT_CATEGORY_SW3_INT_MASK   (0x08U)
20 #define PF1550_INT_CATEGORY_LDO_INT_MASK   (0x10U)
21 #define PF1550_INT_CATEGORY_ONKEY_INT_MASK (0x20U)
22 #define PF1550_INT_CATEGORY_TEMP_INT_MASK  (0x40U)
23 #define PF1550_INT_CATEGORY_MISC_INT_MASK  (0x80U)
24 /* REGULATOR_CTRL bit-field. */
25 #define PF1550_REGULATOR_CTRL_EN_MASK       (0x01U)
26 #define PF1550_REGULATOR_CTRL_STBY_EN_MASK  (0x02U)
27 #define PF1550_REGULATOR_CTRL_OMODE_MASK    (0x04U)
28 #define PF1550_REGULATOR_CTRL_SYSON_EN_MASK (0x07U)
29 /* SW_CTRL bit-field. */
30 #define PF1550_SW_CTRL_LPWR_MASK      (0x08U)
31 #define PF1550_SW_CTRL_DVSSPEED_MASK  (0x10U)
32 #define PF1550_SW_CTRL_DVSSPEED_SHIFT (4U)
33 #define PF1550_SW_CTRL_DVSSPEED(x) \
34     (((uint8_t)((uint8_t)(x) << PF1550_SW_CTRL_DVSSPEED_SHIFT)) & PF1550_SW_CTRL_DVSSPEED_MASK)
35 #define PF1550_SW_CTRL_FPWM_IN_DVS_MASK (0x20U)
36 #define PF1550_SW_CTRL_FPWM_MASK        (0x40U)
37 #define PF1550_SW_CTRL_RDIS_EN_MASK     (0x80U)
38 /* LDO_CTRL bit-field. */
39 #define PF1550_LDO_CTRL_LPWR_MASK  (0x08U)
40 #define PF1550_LDO_CTRL_LS_EN_MASK (0x10U)
41 /* COINCELL bit-field. */
42 #define PF1550_COINCELL_CONTROL_COINCHEN_MASK (0x10U)
43 /* VSNVS_CTRL bit-field. */
44 #define PF1550_VSNVS_CTRL_LIBGDIS_MASK (0x20U)
45 /* PWRCTRL0 bit-field. */
46 #define PF1550_PWRCTRL0_STANDBYDLY_MASK  (0x03U)
47 #define PF1550_PWRCTRL0_STANDBYINV_MASK  (0x04U)
48 #define PF1550_PWRCTRL0_STANDBYINV_SHIFT (2U)
49 #define PF1550_PWRCTRL0_STANDBYINV(x) \
50     (((uint8_t)((uint8_t)(x) << PF1550_PWRCTRL0_STANDBYINV_SHIFT)) & PF1550_PWRCTRL0_STANDBYINV_MASK)
51 #define PF1550_PWRCTRL0_POR_DLY_MASK  (0x38U)
52 #define PF1550_PWRCTRL0_POR_DLY_SHIFT (3U)
53 #define PF1550_PWRCTRL0_POR_DLY(x) \
54     (((uint8_t)((uint8_t)(x) << PF1550_PWRCTRL0_POR_DLY_SHIFT)) & PF1550_PWRCTRL0_POR_DLY_MASK)
55 #define PF1550_PWRCTRL0_TGRESET_MASK  (0xC0U)
56 #define PF1550_PWRCTRL0_TGRESET_SHIFT (6U)
57 #define PF1550_PWRCTRL0_TGRESET(x) \
58     (((uint8_t)((uint8_t)(x) << PF1550_PWRCTRL0_TGRESET_SHIFT)) & PF1550_PWRCTRL0_TGRESET_MASK)
59 /* PWRCTRL1 bit-field. */
60 #define PF1550_PWRCTRL1_PWRONDBNC_MASK  (0x03U)
61 #define PF1550_PWRCTRL1_PWRONRSTEN_MASK (0x10U)
62 #define PF1550_PWRCTRL1_RESTARTEN_MASK  (0x20U)
63 #define PF1550_PWRCTRL1_ONKEYDBNC_MASK  (0x0CU)
64 #define PF1550_PWRCTRL1_ONKEYDBNC_SHIFT (2U)
65 #define PF1550_PWRCTRL1_ONKEYDBNC(x) \
66     (((uint8_t)((uint8_t)(x) << PF1550_PWRCTRL1_ONKEYDBNC_SHIFT)) & PF1550_PWRCTRL1_ONKEYDBNC_MASK)
67 #define PF1550_PWRCTRL1_REGSCPEN_MASK     (0x40U)
68 #define PF1550_PWRCTRL1_ONKEY_RST_EN_MASK (0x80U)
69 /* PWRCTRL2 bit-field. */
70 #define PF1550_PWRCTRL2_UVDET_MASK (0x03U)
71 /* OTP_SW1_SW2 bit-field. */
72 #define PF1550_OTP_SW1_SW2_OTP_SW1_DVS_ENB_MASK (0x02U)
73 /* OTP_SW2_SW3 bit-field. */
74 #define PF1550_OTP_SW2_SW3_OTP_SW2_DVS_ENB_MASK (0x08U)
75 
76 /* Regulator Control Helper Macros. */
77 #define PF1550_SWX_SET_POINT_NUM        (64U)
78 #define PF1550_SWX_OUTPUT_LIMIT_LOW_DVS (600000U)
79 #define PF1550_SWX_OUTPUT_STEP_DVS      (12500U)
80 #define PF1550_SWY_SET_POINT_NUM        (16U)
81 #define PF1550_SWY_OUTPUT_LIMIT_LOW     (1800000U)
82 #define PF1550_SWY_OUTPUT_STEP          (100000U)
83 #define PF1550_LDOX_SET_POINT_NUM       (16U)
84 #define PF1550_LDOX_OUTPUT_LIMIT_LOW    (1800000U)
85 #define PF1550_LDOX_OUTPUT_STEP         (100000U)
86 #define PF1550_LDOY_SET_POINT_NUM       (32U)
87 #define PF1550_LDOY_SET_POINT_LOW_NUM   (16U)
88 #define PF1550_LDOY_OUTPUT_LIMIT_LOW    (750000U)
89 #define PF1550_LDOY_OUTPUT_STEP_LOW     (50000U)
90 #define PF1550_LDOY_OUTPUT_LIMIT_MID    (1800000U)
91 #define PF1550_LDOY_OUTPUT_STEP_HIGH    (100000U)
92 #define PF1550_VSNVS_OUTPUT_VOLTAGE     (3300000U)
93 
94 /*******************************************************************************
95  * Prototypes
96  ******************************************************************************/
97 
98 /*******************************************************************************
99  * Variables
100  ******************************************************************************/
101 static const uint8_t powerDownRegTab[] = {
102     PF1550_SW1_PWRDN_SEQ,
103     PF1550_SW2_PWRDN_SEQ,
104     PF1550_SW3_PWRDN_SEQ,
105     PF1550_LDO1_PWRDN_SEQ,
106     PF1550_LDO2_PWRDN_SEQ,
107     PF1550_LDO3_PWRDN_SEQ,
108     0x0,
109     PF1550_VREFDDR_PWRDN_SEQ,
110 };
111 static const uint8_t regulatorCtrlRegTab[] = {
112     PF1550_SW1_CTRL,  PF1550_SW2_CTRL,  PF1550_SW3_CTRL,   PF1550_LDO1_CTRL,
113     PF1550_LDO2_CTRL, PF1550_LDO3_CTRL, PF1550_VSNVS_CTRL, PF1550_VREFDDR_CTRL,
114 };
115 static const uint8_t regulatorVoltRegTab[] = {
116     PF1550_SW1_VOLT, PF1550_SW2_VOLT, PF1550_SW3_VOLT, PF1550_LDO1_VOLT, PF1550_LDO2_VOLT, PF1550_LDO3_VOLT, 0x0, 0x0,
117 };
118 static const uint32_t regulatorSwVoltSetPonitTab[] = {
119     1100000U, 1200000U, 1350000U, 1500000U, 1800000U, 2500000U, 3000000U, 3300000U,
120 };
121 
122 /*******************************************************************************
123  * Code
124  ******************************************************************************/
125 
PF1550_ReadOtp(pf1550_handle_t * handle,uint8_t reg,uint8_t * val)126 static bool PF1550_ReadOtp(pf1550_handle_t *handle, uint8_t reg, uint8_t *val)
127 {
128     bool result = false;
129 
130     assert(handle);
131     assert(val);
132 
133     result = PF1550_WriteReg(handle, PF1550_KEY1, 0x15);
134     if (true == result)
135     {
136         result = PF1550_WriteReg(handle, PF1550_CHGR_KEY2, 0x50);
137         if (true == result)
138         {
139             result = PF1550_WriteReg(handle, PF1550_KEY3, 0xAB);
140             if (true == result)
141             {
142                 result = PF1550_WriteReg(handle, PF1550_FMRADDR, reg);
143                 if (true == result)
144                 {
145                     result = PF1550_ReadReg(handle, PF1550_FMRDATA, val);
146                 }
147             }
148         }
149     }
150 
151     return result;
152 }
153 
PF1550_GetRegulatorSetPoint(pf1550_handle_t * handle,pf1550_module_t module,uint32_t voltage)154 static uint8_t PF1550_GetRegulatorSetPoint(pf1550_handle_t *handle, pf1550_module_t module, uint32_t voltage)
155 {
156     uint8_t regulatorSetPoint = 0U;
157     uint32_t index;
158 
159     assert(handle);
160     assert((kPF1550_ModuleSwitch1 == module) || (kPF1550_ModuleSwitch2 == module) ||
161            (kPF1550_ModuleSwitch3 == module) || (kPF1550_ModuleLdo1 == module) || (kPF1550_ModuleLdo2 == module) ||
162            (kPF1550_ModuleLdo3 == module));
163 
164     switch (module)
165     {
166         /* Process Switch X. */
167         case kPF1550_ModuleSwitch1:
168         case kPF1550_ModuleSwitch2:
169             /* Find the first Vset_point >= voltage */
170             for (index = 0U; index < PF1550_SWX_SET_POINT_NUM; index++)
171             {
172                 if ((PF1550_SWX_OUTPUT_LIMIT_LOW_DVS + (PF1550_SWX_OUTPUT_STEP_DVS * index)) >= voltage)
173                 {
174                     regulatorSetPoint = (uint8_t)index;
175                     break;
176                 }
177             }
178             /* Not found, Desired voltage is beyond upper limit. */
179             if (PF1550_SWX_SET_POINT_NUM == index)
180             {
181                 /* Use Vset_point_max as actual Voutput. */
182                 regulatorSetPoint = PF1550_SWX_SET_POINT_NUM - 1U;
183             }
184             break;
185 
186         /* Process Switch Y. */
187         case kPF1550_ModuleSwitch3:
188             for (index = 0U; index < PF1550_SWY_SET_POINT_NUM; index++)
189             {
190                 if ((PF1550_SWY_OUTPUT_LIMIT_LOW + (PF1550_SWY_OUTPUT_STEP * index)) >= voltage)
191                 {
192                     regulatorSetPoint = (uint8_t)index;
193                     break;
194                 }
195             }
196             /* Desired voltage is beyond upper limit. */
197             if (PF1550_SWY_SET_POINT_NUM == index)
198             {
199                 regulatorSetPoint = PF1550_SWY_SET_POINT_NUM - 1U;
200             }
201             break;
202 
203         /* Process LDO X. */
204         case kPF1550_ModuleLdo2:
205             for (index = 0U; index < PF1550_LDOX_SET_POINT_NUM; index++)
206             {
207                 if ((PF1550_LDOX_OUTPUT_LIMIT_LOW + (PF1550_LDOX_OUTPUT_STEP * index)) >= voltage)
208                 {
209                     regulatorSetPoint = (uint8_t)index;
210                     break;
211                 }
212             }
213             /* Desired voltage is beyond upper limit. */
214             if (PF1550_LDOX_SET_POINT_NUM == index)
215             {
216                 regulatorSetPoint = PF1550_LDOX_SET_POINT_NUM - 1U;
217             }
218             break;
219 
220         /* Process LDO Y. */
221         case kPF1550_ModuleLdo1:
222         case kPF1550_ModuleLdo3:
223             for (index = 0U; index < PF1550_LDOY_SET_POINT_NUM; index++)
224             {
225                 if (((index < PF1550_LDOY_SET_POINT_LOW_NUM) &&
226                      ((PF1550_LDOY_OUTPUT_LIMIT_LOW + (PF1550_LDOY_OUTPUT_STEP_LOW * index)) >= voltage)) ||
227                     ((index >= PF1550_LDOY_SET_POINT_LOW_NUM) &&
228                      ((PF1550_LDOY_OUTPUT_LIMIT_MID +
229                        (PF1550_LDOY_OUTPUT_STEP_HIGH * (index - PF1550_LDOY_SET_POINT_LOW_NUM))) >= voltage)))
230                 {
231                     regulatorSetPoint = (uint8_t)index;
232                     break;
233                 }
234             }
235             /* Desired voltage is byond upper limit. */
236             if (PF1550_LDOY_SET_POINT_NUM == index)
237             {
238                 regulatorSetPoint = PF1550_LDOY_SET_POINT_NUM - 1U;
239             }
240             break;
241 
242         default:
243             assert(false);
244             break;
245     }
246 
247     return regulatorSetPoint;
248 }
249 
PF1550_GetRegulatorOutputVolt(pf1550_handle_t * handle,pf1550_module_t module,uint8_t voltRegContent)250 static uint32_t PF1550_GetRegulatorOutputVolt(pf1550_handle_t *handle, pf1550_module_t module, uint8_t voltRegContent)
251 {
252     uint32_t voltage;
253 
254     assert(handle);
255     assert((kPF1550_ModuleSwitch1 == module) || (kPF1550_ModuleSwitch2 == module) ||
256            (kPF1550_ModuleSwitch3 == module) || (kPF1550_ModuleLdo1 == module) || (kPF1550_ModuleLdo2 == module) ||
257            (kPF1550_ModuleLdo3 == module));
258 
259     switch (module)
260     {
261         /* Process Switch X. */
262         case kPF1550_ModuleSwitch1:
263         case kPF1550_ModuleSwitch2:
264             /* Get Set Point when Switch DVS feature is enabled. */
265             if (true == PF1550_IsRegulatorSupportDvs(handle, module))
266             {
267                 voltage = PF1550_SWX_OUTPUT_LIMIT_LOW_DVS + (uint32_t)PF1550_SWX_OUTPUT_STEP_DVS * voltRegContent;
268             }
269             /* Get Set Point when Switch DVS feature is disable. */
270             else
271             {
272                 if (sizeof(regulatorSwVoltSetPonitTab) / sizeof(regulatorSwVoltSetPonitTab[0]) <= voltRegContent)
273                 {
274                     voltage = regulatorSwVoltSetPonitTab[(sizeof(regulatorSwVoltSetPonitTab) /
275                                                           sizeof(regulatorSwVoltSetPonitTab[0])) -
276                                                          1U];
277                 }
278                 else
279                 {
280                     voltage = regulatorSwVoltSetPonitTab[voltRegContent];
281                 }
282             }
283             break;
284 
285         /* Process Switch Y. */
286         case kPF1550_ModuleSwitch3:
287             voltage = PF1550_SWY_OUTPUT_LIMIT_LOW + (PF1550_SWY_OUTPUT_STEP * voltRegContent);
288             break;
289 
290         /* Process LDO X. */
291         case kPF1550_ModuleLdo2:
292             voltage = PF1550_LDOX_OUTPUT_LIMIT_LOW + (PF1550_LDOX_OUTPUT_STEP * voltRegContent);
293             break;
294 
295         /* Process LDO Y. */
296         case kPF1550_ModuleLdo1:
297         case kPF1550_ModuleLdo3:
298             if (PF1550_LDOY_SET_POINT_LOW_NUM <= voltRegContent)
299             {
300                 voltage = PF1550_LDOY_OUTPUT_LIMIT_MID +
301                           (PF1550_LDOY_OUTPUT_STEP_HIGH * ((uint32_t)voltRegContent - PF1550_LDOY_SET_POINT_LOW_NUM));
302             }
303             else
304             {
305                 voltage = PF1550_LDOY_OUTPUT_LIMIT_LOW + (PF1550_LDOY_OUTPUT_STEP_LOW * (uint32_t)voltRegContent);
306             }
307             break;
308 
309         default:
310             voltage = 0U;
311             break;
312     }
313 
314     return voltage;
315 }
316 
PF1550_GetDefaultConfig(pf1550_config_t * config)317 void PF1550_GetDefaultConfig(pf1550_config_t *config)
318 {
319     assert(config);
320 
321     /* Set callback function to NULL Pointer. */
322     config->I2C_SendFunc    = NULL;
323     config->I2C_ReceiveFunc = NULL;
324 
325     /* Under-Voltage interrupt will assert when Vsys rising voltage cross 3.0V
326      * or Vsys rising voltage cross 2.9V. */
327     config->threshold = kPF1550_UnderVoltDetThres_Rising3V0Falling2V9;
328     /* PF1550 reset MCU 2ms later after last regulator power up. */
329     config->delay = kPF1550_PowerUpDelay_2ms;
330     /* PF1550 will not disable LDO when Current Limit Fault occur. */
331     config->shutDownLdoInCurrentFault = false;
332     /* Set Default Slave Address. */
333     config->slaveAddress = PF1550_DEFAULT_I2C_ADDR;
334 }
335 
PF1550_Init(pf1550_handle_t * handle,const pf1550_config_t * config)336 void PF1550_Init(pf1550_handle_t *handle, const pf1550_config_t *config)
337 {
338     assert(handle);
339     assert(config);
340 
341     /* Initialize Callback functions. */
342     handle->I2C_SendFunc    = config->I2C_SendFunc;
343     handle->I2C_ReceiveFunc = config->I2C_ReceiveFunc;
344     /* Set Slave Address. */
345     handle->slaveAddress = config->slaveAddress;
346 
347     /* Set Vsys Under-Voltage Detection Threshold. */
348     (void)PF1550_ModifyReg(handle, PF1550_PWRCTRL2, PF1550_PWRCTRL2_UVDET_MASK, (uint8_t)(config->threshold));
349     /* Set Power Up Delay Time. */
350     (void)PF1550_ModifyReg(handle, PF1550_PWRCTRL0, PF1550_PWRCTRL0_POR_DLY_MASK,
351                            PF1550_PWRCTRL0_POR_DLY(config->delay));
352     /* Shuts down LDO if it enters a current limit fault. */
353     (void)PF1550_ModifyReg(handle, PF1550_PWRCTRL1, PF1550_PWRCTRL1_REGSCPEN_MASK,
354                            config->shutDownLdoInCurrentFault ? PF1550_PWRCTRL1_REGSCPEN_MASK : 0x0U);
355 }
356 
PF1550_WriteReg(pf1550_handle_t * handle,uint8_t reg,uint8_t val)357 bool PF1550_WriteReg(pf1550_handle_t *handle, uint8_t reg, uint8_t val)
358 {
359     assert(handle);
360     assert(handle->I2C_SendFunc);
361 
362     return (kStatus_Success == handle->I2C_SendFunc(handle->slaveAddress, reg, 1U, &val, 1U)) ? true : false;
363 }
364 
PF1550_ReadReg(pf1550_handle_t * handle,uint8_t reg,uint8_t * val)365 bool PF1550_ReadReg(pf1550_handle_t *handle, uint8_t reg, uint8_t *val)
366 {
367     assert(handle);
368     assert(handle->I2C_ReceiveFunc);
369     assert(val);
370 
371     return (kStatus_Success == handle->I2C_ReceiveFunc(handle->slaveAddress, reg, 1U, val, 1U)) ? true : false;
372 }
373 
PF1550_ModifyReg(pf1550_handle_t * handle,uint8_t reg,uint8_t mask,uint8_t val)374 bool PF1550_ModifyReg(pf1550_handle_t *handle, uint8_t reg, uint8_t mask, uint8_t val)
375 {
376     bool result      = false;
377     uint8_t regValue = 0U;
378 
379     assert(handle);
380 
381     /* Read back the register content. */
382     result = PF1550_ReadReg(handle, reg, &regValue);
383     if (true == result)
384     {
385         /* Modify the bit-fields you want to change. */
386         regValue &= (uint8_t)~mask;
387         regValue |= val;
388 
389         /* Write back the content to the registers. */
390         result = PF1550_WriteReg(handle, reg, regValue);
391     }
392 
393     return result;
394 }
395 
PF1550_DumpReg(pf1550_handle_t * handle,uint8_t reg,uint8_t * buffer,uint8_t size)396 bool PF1550_DumpReg(pf1550_handle_t *handle, uint8_t reg, uint8_t *buffer, uint8_t size)
397 {
398     bool result = true;
399     uint8_t i;
400 
401     assert(handle);
402     assert(buffer);
403 
404     /* It seems that PF1550 only supports single-byte I2C transactions
405        for read and write. */
406     for (i = 0; i < size; i++)
407     {
408         if (false == PF1550_ReadReg(handle, reg++, buffer++))
409         {
410             result = false;
411         }
412     }
413 
414     return result;
415 }
416 
PF1550_GetInterruptCategory(pf1550_handle_t * handle)417 uint32_t PF1550_GetInterruptCategory(pf1550_handle_t *handle)
418 {
419     uint8_t category = 0U;
420 
421     assert(handle);
422 
423     /* It seems that PF1550 only support  */
424     (void)PF1550_ReadReg(handle, PF1550_INT_CATEGORY, &category);
425 
426     return category;
427 }
428 
PF1550_EnableInterrupts(pf1550_handle_t * handle,pf1550_interrupt_category_t category,uint32_t source)429 void PF1550_EnableInterrupts(pf1550_handle_t *handle, pf1550_interrupt_category_t category, uint32_t source)
430 {
431     assert(handle);
432 
433     switch (category)
434     {
435         case kPF1550_IntCategoryCharger:
436             /* Enable Charger interrupts. */
437             (void)PF1550_ModifyReg(handle, PF1550_CHG_INT_MASK, (uint8_t)(source & 0xFFU), 0x0U);
438             break;
439 
440         case kPF1550_IntCategorySwitch:
441             /* Enable Switch low side current limit interrupts. */
442             (void)PF1550_ModifyReg(handle, PF1550_SW_INT_MASK0, (uint8_t)(source & 0xFFU), 0x0U);
443             /* Enable Switch high side current limit interrupts. */
444             (void)PF1550_ModifyReg(handle, PF1550_SW_INT_MASK1, (uint8_t)((source & 0xFF00U) >> 8U), 0x0U);
445             /* Enable Switch DVS complete interrupts. */
446             (void)PF1550_ModifyReg(handle, PF1550_SW_INT_MASK2, (uint8_t)((source & 0xFF0000U) >> 16U), 0x0U);
447             break;
448 
449         case kPF1550_IntCategoryLdo:
450             /* Enable LDO current limit fault interrupts. */
451             (void)PF1550_ModifyReg(handle, PF1550_LDO_INT_MASK0, (uint8_t)(source & 0xFFU), 0x0U);
452             break;
453 
454         case kPF1550_IntCategoryOnkey:
455             /* Enable ONKEY Press interrupts. */
456             (void)PF1550_ModifyReg(handle, PF1550_ONKEY_INT_MASK0, (uint8_t)(source & 0xFFU), 0x0U);
457             break;
458 
459         case kPF1550_IntCategoryTemp:
460             /* Enable Die Temperature Cross interrupts. */
461             (void)PF1550_ModifyReg(handle, PF1550_TEMP_INT_MASK0, (uint8_t)(source & 0xFFU), 0x0U);
462             break;
463 
464         case kPF1550_IntCategoryMisc:
465             /* Enable Misc. interrupts. */
466             (void)PF1550_ModifyReg(handle, PF1550_MISC_INT_MASK0, (uint8_t)(source & 0xFFU), 0x0U);
467             break;
468 
469         default:
470             assert(false);
471             break;
472     }
473 }
474 
PF1550_DisableInterrupts(pf1550_handle_t * handle,pf1550_interrupt_category_t category,uint32_t source)475 void PF1550_DisableInterrupts(pf1550_handle_t *handle, pf1550_interrupt_category_t category, uint32_t source)
476 {
477     assert(handle);
478 
479     switch (category)
480     {
481         case kPF1550_IntCategoryCharger:
482             /* TODO: Add charger Interrupt Enable Logic here. */
483             break;
484 
485         case kPF1550_IntCategorySwitch:
486             /* Disable Switch low side current limit interrupts. */
487             (void)PF1550_ModifyReg(handle, PF1550_SW_INT_MASK0, 0x0U, (uint8_t)(source & 0xFFU));
488             /* Disable Switch high side current limit interrupts. */
489             (void)PF1550_ModifyReg(handle, PF1550_SW_INT_MASK1, 0x0U, (uint8_t)((source & 0xFF00U) >> 8U));
490             /* Disable Switch DVS complete interrupts. */
491             (void)PF1550_ModifyReg(handle, PF1550_SW_INT_MASK2, 0x0U, (uint8_t)((source & 0xFF0000U) >> 16U));
492             break;
493 
494         case kPF1550_IntCategoryLdo:
495             /* Disable LDO current limit fault interrupts. */
496             (void)PF1550_ModifyReg(handle, PF1550_LDO_INT_MASK0, 0x0U, (uint8_t)(source & 0xFFU));
497             break;
498 
499         case kPF1550_IntCategoryOnkey:
500             /* Disable ONKEY Press interrupts. */
501             (void)PF1550_ModifyReg(handle, PF1550_ONKEY_INT_MASK0, 0x0U, (uint8_t)(source & 0xFFU));
502             break;
503 
504         case kPF1550_IntCategoryTemp:
505             /* Disable Die Temperature Cross interrupts. */
506             (void)PF1550_ModifyReg(handle, PF1550_TEMP_INT_MASK0, 0x0U, (uint8_t)(source & 0xFFU));
507             break;
508 
509         case kPF1550_IntCategoryMisc:
510             /* Disable Misc. interrupts. */
511             (void)PF1550_ModifyReg(handle, PF1550_MISC_INT_MASK0, 0x0U, (uint8_t)(source & 0xFFU));
512             break;
513 
514         default:
515             assert(false);
516             break;
517     }
518 }
519 
PF1550_GetInterruptStatus(pf1550_handle_t * handle,pf1550_interrupt_category_t category)520 uint32_t PF1550_GetInterruptStatus(pf1550_handle_t *handle, pf1550_interrupt_category_t category)
521 {
522     uint32_t status = 0x0U;
523     uint8_t temp    = 0U;
524 
525     assert(handle);
526 
527     switch (category)
528     {
529         case kPF1550_IntCategoryCharger:
530             /* Get Charger interrupt flags. */
531             (void)PF1550_ReadReg(handle, PF1550_CHG_INT, &temp);
532             status = temp;
533             break;
534 
535         case kPF1550_IntCategorySwitch:
536             /* Get Switch low side current limit interrupt flags. */
537             (void)PF1550_ReadReg(handle, PF1550_SW_INT_STAT0, &temp);
538             status = temp;
539 
540             /* Get Switch high side current limit interrupt flags. */
541             (void)PF1550_ReadReg(handle, PF1550_SW_INT_STAT1, &temp);
542             status |= (uint32_t)((uint32_t)temp << 8U);
543 
544             /* Get Switch DVS complete interrupt flags. */
545             (void)PF1550_ReadReg(handle, PF1550_SW_INT_STAT2, &temp);
546             status |= (uint32_t)((uint32_t)temp << 16U);
547             break;
548 
549         case kPF1550_IntCategoryLdo:
550             /* Get LDO current limit fault interrupt flags. */
551             (void)PF1550_ReadReg(handle, PF1550_LDO_INT_STAT0, &temp);
552             status = temp;
553             break;
554 
555         case kPF1550_IntCategoryOnkey:
556             /* Get ONKEY Press interrupt flags. */
557             (void)PF1550_ReadReg(handle, PF1550_ONKEY_INT_STAT0, &temp);
558             status = temp;
559             break;
560 
561         case kPF1550_IntCategoryTemp:
562             /* Get Die Temperature Cross interrupt flags. */
563             (void)PF1550_ReadReg(handle, PF1550_TEMP_INT_STAT0, &temp);
564             status = temp;
565             break;
566 
567         case kPF1550_IntCategoryMisc:
568             /* Get Misc. interrupt flags. */
569             (void)PF1550_ReadReg(handle, PF1550_MISC_INT_STAT0, &temp);
570             status = temp;
571             break;
572 
573         default:
574             assert(false);
575             break;
576     }
577 
578     return status;
579 }
580 
PF1550_ClearInterruptStatus(pf1550_handle_t * handle,pf1550_interrupt_category_t category,uint32_t source)581 void PF1550_ClearInterruptStatus(pf1550_handle_t *handle, pf1550_interrupt_category_t category, uint32_t source)
582 {
583     assert(handle);
584 
585     /* interrupt status bits are w1c. */
586     switch (category)
587     {
588         case kPF1550_IntCategoryCharger:
589             /* Clear Charger interrupts. */
590             (void)PF1550_WriteReg(handle, PF1550_CHG_INT, (uint8_t)(source & 0xFFU));
591             break;
592 
593         case kPF1550_IntCategorySwitch:
594             /* Clear Switch low side current limit interrupts. */
595             (void)PF1550_WriteReg(handle, PF1550_SW_INT_STAT0, (uint8_t)(source & 0xFFU));
596             /* Clear Switch high side current limit interrupts. */
597             (void)PF1550_WriteReg(handle, PF1550_SW_INT_STAT1, (uint8_t)((source & 0xFF00U) >> 8U));
598             /* Clear Switch DVS complete interrupts. */
599             (void)PF1550_WriteReg(handle, PF1550_SW_INT_STAT2, (uint8_t)((source & 0xFF0000U) >> 16U));
600             break;
601 
602         case kPF1550_IntCategoryLdo:
603             /* Clear LDO current limit fault interrupts. */
604             (void)PF1550_WriteReg(handle, PF1550_LDO_INT_STAT0, (uint8_t)(source & 0xFFU));
605             break;
606 
607         case kPF1550_IntCategoryOnkey:
608             /* Clear ONKEY Press interrupts. */
609             (void)PF1550_WriteReg(handle, PF1550_ONKEY_INT_STAT0, (uint8_t)(source & 0xFFU));
610             break;
611 
612         case kPF1550_IntCategoryTemp:
613             /* Clear Die Temperature Cross interrupts. */
614             (void)PF1550_WriteReg(handle, PF1550_TEMP_INT_STAT0, (uint8_t)(source & 0xFFU));
615             break;
616 
617         case kPF1550_IntCategoryMisc:
618             /* Clear Misc. interrupts. */
619             (void)PF1550_WriteReg(handle, PF1550_MISC_INT_STAT0, (uint8_t)(source & 0xFFU));
620             break;
621 
622         default:
623             assert(false);
624             break;
625     }
626 }
627 
PF1550_EnableRegulator(pf1550_handle_t * handle,pf1550_module_t module,pf1550_operating_status_t status,bool enable)628 void PF1550_EnableRegulator(pf1550_handle_t *handle,
629                             pf1550_module_t module,
630                             pf1550_operating_status_t status,
631                             bool enable)
632 {
633     uint8_t regulatorCtrlRegAddr;
634 
635     assert(handle);
636     /* Regulators are only enabled in any of the System On Statues. */
637     assert((kPF1550_OperatingStatusRun == status) || (kPF1550_OperatingStatusStandby == status) ||
638            (kPF1550_OperatingStatusSleep == status) || (kPF1550_OperatingStatusSystemOn == status));
639 
640     /* There is no enable/disable switch for Vsnvs. */
641     if (kPF1550_ModuleVsnvs == module)
642     {
643         return;
644     }
645 
646     /* Get Regulator Control Register Address. */
647     regulatorCtrlRegAddr = regulatorCtrlRegTab[module];
648 
649     switch (status)
650     {
651         case kPF1550_OperatingStatusRun:
652             (void)PF1550_ModifyReg(handle, regulatorCtrlRegAddr, PF1550_REGULATOR_CTRL_EN_MASK,
653                                    (enable ? PF1550_REGULATOR_CTRL_EN_MASK : 0x0U));
654             break;
655 
656         case kPF1550_OperatingStatusStandby:
657             (void)PF1550_ModifyReg(handle, regulatorCtrlRegAddr, PF1550_REGULATOR_CTRL_STBY_EN_MASK,
658                                    (enable ? PF1550_REGULATOR_CTRL_STBY_EN_MASK : 0x0U));
659             break;
660 
661         case kPF1550_OperatingStatusSleep:
662             (void)PF1550_ModifyReg(handle, regulatorCtrlRegAddr, PF1550_REGULATOR_CTRL_OMODE_MASK,
663                                    (enable ? PF1550_REGULATOR_CTRL_OMODE_MASK : 0x0U));
664             break;
665 
666         case kPF1550_OperatingStatusSystemOn:
667             (void)PF1550_ModifyReg(handle, regulatorCtrlRegAddr, PF1550_REGULATOR_CTRL_SYSON_EN_MASK,
668                                    (enable ? PF1550_REGULATOR_CTRL_SYSON_EN_MASK : 0x0U));
669             break;
670 
671         default:
672             assert(false);
673             break;
674     }
675 }
676 
PF1550_IsRegulatorEnabled(pf1550_handle_t * handle,pf1550_module_t module,pf1550_operating_status_t status)677 bool PF1550_IsRegulatorEnabled(pf1550_handle_t *handle, pf1550_module_t module, pf1550_operating_status_t status)
678 {
679     bool result;
680     uint8_t regulatorCtrlRegAddr;
681     uint8_t regulatorCtrlRegContent = 0U;
682 
683     assert(handle);
684     /* Regulators are only enabled in any of the System On Statues. */
685     assert((kPF1550_OperatingStatusRun == status) || (kPF1550_OperatingStatusStandby == status) ||
686            (kPF1550_OperatingStatusSleep == status) || (kPF1550_OperatingStatusSystemOn == status));
687 
688     /* There is no enable/disable switch for Vsnvs. */
689     if (kPF1550_ModuleVsnvs == module)
690     {
691         result = true;
692     }
693     else
694     {
695         /* Get Regulator Control Register Content. */
696         regulatorCtrlRegAddr = regulatorCtrlRegTab[module];
697         (void)PF1550_ReadReg(handle, regulatorCtrlRegAddr, &regulatorCtrlRegContent);
698 
699         switch (status)
700         {
701             case kPF1550_OperatingStatusRun:
702                 result = ((regulatorCtrlRegContent & PF1550_REGULATOR_CTRL_EN_MASK) != 0U) ? true : false;
703                 break;
704 
705             case kPF1550_OperatingStatusStandby:
706                 result = ((regulatorCtrlRegContent & PF1550_REGULATOR_CTRL_STBY_EN_MASK) != 0U) ? true : false;
707                 break;
708 
709             case kPF1550_OperatingStatusSleep:
710                 result = ((regulatorCtrlRegContent & PF1550_REGULATOR_CTRL_OMODE_MASK) != 0U) ? true : false;
711                 break;
712 
713             case kPF1550_OperatingStatusSystemOn:
714                 result = ((regulatorCtrlRegContent & PF1550_REGULATOR_CTRL_SYSON_EN_MASK) ==
715                           PF1550_REGULATOR_CTRL_SYSON_EN_MASK) ?
716                              true :
717                              false;
718                 break;
719 
720             default:
721                 result = false;
722                 break;
723         }
724     }
725 
726     return result;
727 }
728 
PF1550_SetRegulatorOutputVoltage(pf1550_handle_t * handle,pf1550_module_t module,pf1550_operating_status_t status,uint32_t voltage)729 void PF1550_SetRegulatorOutputVoltage(pf1550_handle_t *handle,
730                                       pf1550_module_t module,
731                                       pf1550_operating_status_t status,
732                                       uint32_t voltage)
733 {
734     uint8_t regulatorVoltRegAddr;
735     uint8_t regulatorVoltRegContent;
736 
737     assert(handle);
738     /* Regulators are only enabled in any of the System On Statues. */
739     assert((kPF1550_OperatingStatusRun == status) || (kPF1550_OperatingStatusStandby == status) ||
740            (kPF1550_OperatingStatusSleep == status) || (kPF1550_OperatingStatusSystemOn == status));
741 
742     /* Return directly if regulator does not support DVS feature. */
743     if (PF1550_IsRegulatorSupportDvs(handle, module))
744     {
745         /* Get Regulator Output Set Point. */
746         regulatorVoltRegAddr    = regulatorVoltRegTab[module];
747         regulatorVoltRegContent = PF1550_GetRegulatorSetPoint(handle, module, voltage);
748 
749         /* There is only one regulator output voltage control register for LDO.
750            So regulator output set for any operating status to LDO will affect
751            all operating status. */
752         if ((kPF1550_ModuleLdo1 == module) || (kPF1550_ModuleLdo2 == module) || (kPF1550_ModuleLdo3 == module))
753         {
754             (void)PF1550_WriteReg(handle, regulatorVoltRegAddr, regulatorVoltRegContent);
755         }
756         else
757         {
758             switch (status)
759             {
760                 case kPF1550_OperatingStatusRun:
761                     (void)PF1550_WriteReg(handle, regulatorVoltRegAddr, regulatorVoltRegContent);
762                     break;
763 
764                 case kPF1550_OperatingStatusStandby:
765                     (void)PF1550_WriteReg(handle, regulatorVoltRegAddr + (PF1550_SW1_STBY_VOLT - PF1550_SW1_VOLT),
766                                           regulatorVoltRegContent);
767                     break;
768 
769                 case kPF1550_OperatingStatusSleep:
770                     (void)PF1550_WriteReg(handle, regulatorVoltRegAddr + (PF1550_SW1_SLP_VOLT - PF1550_SW1_VOLT),
771                                           regulatorVoltRegContent);
772                     break;
773 
774                 case kPF1550_OperatingStatusSystemOn:
775                     (void)PF1550_WriteReg(handle, regulatorVoltRegAddr, regulatorVoltRegContent);
776                     (void)PF1550_WriteReg(handle, regulatorVoltRegAddr + (PF1550_SW1_STBY_VOLT - PF1550_SW1_VOLT),
777                                           regulatorVoltRegContent);
778                     (void)PF1550_WriteReg(handle, regulatorVoltRegAddr + (PF1550_SW1_SLP_VOLT - PF1550_SW1_VOLT),
779                                           regulatorVoltRegContent);
780                     break;
781 
782                 default:
783                     assert(false);
784                     break;
785             }
786         }
787     }
788 }
789 
PF1550_GetRegulatorOutputVoltage(pf1550_handle_t * handle,pf1550_module_t module,pf1550_operating_status_t status)790 uint32_t PF1550_GetRegulatorOutputVoltage(pf1550_handle_t *handle,
791                                           pf1550_module_t module,
792                                           pf1550_operating_status_t status)
793 {
794     uint8_t regulatorVoltRegAddr;
795     uint8_t regulatorVoltRegContent = 0U;
796     uint32_t voltage                = 0U;
797 
798     assert(handle);
799     /* Regulators are only enabled in any of the System On Statues. */
800     assert((kPF1550_OperatingStatusRun == status) || (kPF1550_OperatingStatusStandby == status) ||
801            (kPF1550_OperatingStatusSleep == status) || (kPF1550_OperatingStatusSystemOn == status));
802 
803     switch (module)
804     {
805         /* Get LDO output voltage. */
806         case kPF1550_ModuleLdo1:
807         case kPF1550_ModuleLdo2:
808         case kPF1550_ModuleLdo3:
809             /* Get Regulator Voltage Regulator. */
810             regulatorVoltRegAddr = regulatorVoltRegTab[module];
811             (void)PF1550_ReadReg(handle, regulatorVoltRegAddr, &regulatorVoltRegContent);
812             voltage = PF1550_GetRegulatorOutputVolt(handle, module, regulatorVoltRegContent);
813             break;
814 
815         /* Get Switch output voltage by operating status. */
816         case kPF1550_ModuleSwitch1:
817         case kPF1550_ModuleSwitch2:
818         case kPF1550_ModuleSwitch3:
819             /* Get Regulator Voltage Regulator. */
820             regulatorVoltRegAddr = regulatorVoltRegTab[module];
821             switch (status)
822             {
823                 case kPF1550_OperatingStatusRun:
824                     (void)PF1550_ReadReg(handle, regulatorVoltRegAddr, &regulatorVoltRegContent);
825                     voltage = PF1550_GetRegulatorOutputVolt(handle, module, regulatorVoltRegContent);
826                     break;
827 
828                 case kPF1550_OperatingStatusStandby:
829                     (void)PF1550_ReadReg(handle, regulatorVoltRegAddr + (PF1550_SW1_STBY_VOLT - PF1550_SW1_VOLT),
830                                          &regulatorVoltRegContent);
831                     voltage = PF1550_GetRegulatorOutputVolt(handle, module, regulatorVoltRegContent);
832                     break;
833 
834                 case kPF1550_OperatingStatusSleep:
835                     (void)PF1550_ReadReg(handle, regulatorVoltRegAddr + (PF1550_SW1_SLP_VOLT - PF1550_SW1_VOLT),
836                                          &regulatorVoltRegContent);
837                     voltage = PF1550_GetRegulatorOutputVolt(handle, module, regulatorVoltRegContent);
838                     break;
839 
840                 default:
841                     voltage = 0U;
842                     break;
843             }
844             break;
845 
846         case kPF1550_ModuleVsnvs:
847             voltage = PF1550_VSNVS_OUTPUT_VOLTAGE;
848             break;
849 
850         /* Vref DDR = Vref DDR In / 2. */
851         case kPF1550_ModuleVrefDdr:
852         default:
853             voltage = 0U;
854             break;
855     }
856 
857     return voltage;
858 }
859 
PF1550_SetSwitchAttribute(pf1550_handle_t * handle,pf1550_module_t module,const pf1550_switch_attribute_t * attribute)860 void PF1550_SetSwitchAttribute(pf1550_handle_t *handle,
861                                pf1550_module_t module,
862                                const pf1550_switch_attribute_t *attribute)
863 {
864     uint8_t regulatorCtrlRegAddr;
865     uint8_t temp;
866 
867     assert(handle);
868     assert(attribute);
869     assert((kPF1550_ModuleSwitch1 == module) || (kPF1550_ModuleSwitch2 == module) || (kPF1550_ModuleSwitch3 == module));
870 
871     /* Set Regulator Control Register. */
872     regulatorCtrlRegAddr = regulatorCtrlRegTab[module];
873     temp                 = ((attribute->enableLowPowerMode ? PF1550_SW_CTRL_LPWR_MASK : 0U) |
874             (attribute->enableForcedPwm ? PF1550_SW_CTRL_FPWM_MASK : 0U) |
875             (attribute->enableDischargeResistor ? PF1550_SW_CTRL_RDIS_EN_MASK : 0U));
876     if (PF1550_IsRegulatorSupportDvs(handle, module))
877     {
878         temp |= (PF1550_SW_CTRL_DVSSPEED(attribute->dvsSpeed) |
879                  (attribute->enableForcedPwmInDvs ? PF1550_SW_CTRL_FPWM_IN_DVS_MASK : 0U));
880     }
881     (void)PF1550_ModifyReg(handle, regulatorCtrlRegAddr,
882                            PF1550_SW_CTRL_RDIS_EN_MASK | PF1550_SW_CTRL_FPWM_MASK | PF1550_SW_CTRL_FPWM_IN_DVS_MASK |
883                                PF1550_SW_CTRL_DVSSPEED_MASK | PF1550_SW_CTRL_LPWR_MASK,
884                            temp);
885 
886     /* Set Power Down Control Register. */
887     (void)PF1550_WriteReg(handle, powerDownRegTab[module], (uint8_t)attribute->powerDownSequence);
888 
889     switch (module)
890     {
891         case kPF1550_ModuleSwitch1:
892             (void)PF1550_WriteReg(handle, PF1550_SW1_CTRL1, (uint8_t)attribute->currentLimit);
893             break;
894 
895         case kPF1550_ModuleSwitch2:
896             (void)PF1550_WriteReg(handle, PF1550_SW2_CTRL1, (uint8_t)attribute->currentLimit);
897             break;
898 
899         case kPF1550_ModuleSwitch3:
900             (void)PF1550_WriteReg(handle, PF1550_SW3_CTRL1, (uint8_t)attribute->currentLimit);
901             break;
902 
903         default:
904             assert(false);
905             break;
906     }
907 }
908 
PF1550_SetLdoAttribute(pf1550_handle_t * handle,pf1550_module_t module,const pf1550_ldo_attribute_t * attribute)909 void PF1550_SetLdoAttribute(pf1550_handle_t *handle, pf1550_module_t module, const pf1550_ldo_attribute_t *attribute)
910 {
911     assert(handle);
912     assert(attribute);
913     assert((kPF1550_ModuleLdo1 == module) || (kPF1550_ModuleLdo2 == module) || (kPF1550_ModuleLdo3 == module));
914 
915     /* Set Power Down Control Register. */
916     (void)PF1550_WriteReg(handle, powerDownRegTab[module], (uint8_t)attribute->powerDownSequence);
917 
918     /* Set LDO to load switch mode. */
919     switch (module)
920     {
921         case kPF1550_ModuleLdo1:
922             (void)PF1550_ModifyReg(handle, PF1550_LDO1_CTRL, PF1550_LDO_CTRL_LPWR_MASK | PF1550_LDO_CTRL_LS_EN_MASK,
923                                    (attribute->enableLowPowerMode ? PF1550_LDO_CTRL_LPWR_MASK : 0U) |
924                                        (attribute->enableLoadSwitch ? PF1550_LDO_CTRL_LS_EN_MASK : 0U));
925             break;
926 
927         case kPF1550_ModuleLdo2:
928             /* LDO2 does not support Load Switch Mode. */
929             (void)PF1550_ModifyReg(handle, PF1550_LDO2_CTRL, PF1550_LDO_CTRL_LPWR_MASK,
930                                    (attribute->enableLowPowerMode ? PF1550_LDO_CTRL_LPWR_MASK : 0U));
931             break;
932 
933         case kPF1550_ModuleLdo3:
934             (void)PF1550_ModifyReg(handle, PF1550_LDO3_CTRL, PF1550_LDO_CTRL_LPWR_MASK | PF1550_LDO_CTRL_LS_EN_MASK,
935                                    (attribute->enableLowPowerMode ? PF1550_LDO_CTRL_LPWR_MASK : 0U) |
936                                        (attribute->enableLoadSwitch ? PF1550_LDO_CTRL_LS_EN_MASK : 0U));
937             break;
938 
939         default:
940             assert(false);
941             break;
942     }
943 }
944 
PF1550_SetVrefDdrAttribute(pf1550_handle_t * handle,const pf1550_vrefddr_attribute_t * attribute)945 void PF1550_SetVrefDdrAttribute(pf1550_handle_t *handle, const pf1550_vrefddr_attribute_t *attribute)
946 {
947     assert(handle);
948     assert(attribute);
949 
950     /* Set Power Down Control Register. */
951     (void)PF1550_WriteReg(handle, powerDownRegTab[kPF1550_ModuleVrefDdr], (uint8_t)attribute->powerDownSequence);
952 }
953 
PF1550_SetVsnvsAttribute(pf1550_handle_t * handle,const pf1550_vsnvs_attribute_t * attribute)954 void PF1550_SetVsnvsAttribute(pf1550_handle_t *handle, const pf1550_vsnvs_attribute_t *attribute)
955 {
956     assert(handle);
957     assert(attribute);
958 
959     /* Set Coin Cell Control Register. */
960     (void)PF1550_WriteReg(handle, PF1550_COINCELL_CONTROL,
961                           (uint8_t)attribute->coinCellChargingVoltage |
962                               (attribute->enableCoinCellCharger ? PF1550_COINCELL_CONTROL_COINCHEN_MASK : 0U));
963 
964     /* Set Vsnvs Control Register. */
965     (void)PF1550_ModifyReg(handle, PF1550_VSNVS_CTRL, PF1550_VSNVS_CTRL_LIBGDIS_MASK,
966                            attribute->enableLocalBandgapInCoinCellMode ? PF1550_VSNVS_CTRL_LIBGDIS_MASK : 0U);
967 }
968 
PF1550_SetOnKeyPadAttibute(pf1550_handle_t * handle,const pf1550_onkey_attribute_t * attribute)969 void PF1550_SetOnKeyPadAttibute(pf1550_handle_t *handle, const pf1550_onkey_attribute_t *attribute)
970 {
971     assert(handle);
972     assert(attribute);
973 
974     /* Set Power Control Register 1. */
975     (void)PF1550_ModifyReg(handle, PF1550_PWRCTRL1, PF1550_PWRCTRL1_ONKEYDBNC_MASK | PF1550_PWRCTRL1_ONKEY_RST_EN_MASK,
976                            (PF1550_PWRCTRL1_ONKEYDBNC(attribute->debounce) |
977                             (attribute->enableTurnOffSystemViaOnkey ? PF1550_PWRCTRL1_ONKEY_RST_EN_MASK : 0U)));
978 
979     /* Set Power Control Register 0. */
980     (void)PF1550_ModifyReg(handle, PF1550_PWRCTRL0, PF1550_PWRCTRL0_TGRESET_MASK,
981                            (uint8_t)PF1550_PWRCTRL0_TGRESET(attribute->pushTime));
982 }
983 
PF1550_SetPwrOnPadAttibute(pf1550_handle_t * handle,const pf1550_power_on_attribute_t * attribute)984 void PF1550_SetPwrOnPadAttibute(pf1550_handle_t *handle, const pf1550_power_on_attribute_t *attribute)
985 {
986     assert(handle);
987     assert(attribute);
988 
989     /* Set Power Control Register 1. */
990     (void)PF1550_ModifyReg(
991         handle, PF1550_PWRCTRL1,
992         PF1550_PWRCTRL1_PWRONDBNC_MASK | PF1550_PWRCTRL1_PWRONRSTEN_MASK | PF1550_PWRCTRL1_RESTARTEN_MASK,
993         ((uint8_t)attribute->debounce |
994          (attribute->longPressGoToRegsDisableOrSleep ? PF1550_PWRCTRL1_PWRONRSTEN_MASK : 0U) |
995          (attribute->longPressRestartToRunStauts ? PF1550_PWRCTRL1_RESTARTEN_MASK : 0U)));
996 }
997 
PF1550_SetStandbyPadAttibute(pf1550_handle_t * handle,const pf1550_standby_attribute_t * attribute)998 void PF1550_SetStandbyPadAttibute(pf1550_handle_t *handle, const pf1550_standby_attribute_t *attribute)
999 {
1000     assert(handle);
1001     assert(attribute);
1002 
1003     /* Set Power Control Register 0. */
1004     (void)PF1550_ModifyReg(
1005         handle, PF1550_PWRCTRL0, PF1550_PWRCTRL0_STANDBYDLY_MASK | PF1550_PWRCTRL0_STANDBYINV_MASK,
1006         (uint8_t)attribute->standbyDelay | (uint8_t)PF1550_PWRCTRL0_STANDBYINV(attribute->standbyPolarity));
1007 }
1008 
PF1550_GetOperatingStatus(pf1550_handle_t * handle)1009 pf1550_operating_status_t PF1550_GetOperatingStatus(pf1550_handle_t *handle)
1010 {
1011     uint8_t operatingStatus = 0U;
1012 
1013     assert(handle);
1014 
1015     (void)PF1550_ReadReg(handle, PF1550_STATE_INFO, &operatingStatus);
1016 
1017     return (pf1550_operating_status_t)((uint8_t)(operatingStatus & 0x7U));
1018 }
1019 
PF1550_IsRegulatorSupportDvs(pf1550_handle_t * handle,pf1550_module_t module)1020 bool PF1550_IsRegulatorSupportDvs(pf1550_handle_t *handle, pf1550_module_t module)
1021 {
1022     uint8_t registerContent = 0U;
1023     bool result;
1024 
1025     assert(handle);
1026 
1027     switch (module)
1028     {
1029         /* Switch1 DVS is enabled/disabled in OPT Configuration. */
1030         case kPF1550_ModuleSwitch1:
1031             (void)PF1550_ReadOtp(handle, PF1550_OTP_SW1_SW2, &registerContent);
1032             result = ((PF1550_OTP_SW1_SW2_OTP_SW1_DVS_ENB_MASK & registerContent) != 0U) ? false : true;
1033             break;
1034 
1035         /* Switch2 DVS is enabled/disabled in OPT Configuration. */
1036         case kPF1550_ModuleSwitch2:
1037             (void)PF1550_ReadOtp(handle, PF1550_OTP_SW2_SW3, &registerContent);
1038             result = ((PF1550_OTP_SW2_SW3_OTP_SW2_DVS_ENB_MASK & registerContent) != 0U) ? false : true;
1039             break;
1040 
1041         /* LDOs always support DVS feature. */
1042         case kPF1550_ModuleLdo1:
1043         case kPF1550_ModuleLdo2:
1044         case kPF1550_ModuleLdo3:
1045             result = true;
1046             break;
1047 
1048         /* Switch3, Vsnvs and Vref DDR does not support DVS in all OPT Configuration. */
1049         case kPF1550_ModuleSwitch3:
1050         case kPF1550_ModuleVsnvs:
1051         case kPF1550_ModuleVrefDdr:
1052             result = false;
1053             break;
1054 
1055         default:
1056             result = false;
1057             break;
1058     }
1059 
1060     return result;
1061 }
1062 
1063 /*******************************************************************************
1064  * EOF
1065  ******************************************************************************/
1066