[U-Boot] [PATCH v2 0/3] pmic:pfuze support buck regulator mode switch

This patch set is to support buck regulator can working in different switching modes. To improve system efficiency the buck regulators can operate in different switching modes.
patch 1/3 is to add related bit definitions and registers. patch 2/3 is to implement the switching mode init function. patch 3/3 is to add related mode init function in board code.
mx6slevk board is not included in this patch set, since power and i2c interface are not implemented for it. Future patch will cover this to add PAD setting, power_init_board and etc.
Changes v2: implement set mode for each regulator
Peng Fan (3): pmic:pfuz100 add switch mode and more registers pmic:pfuze implement pmic_mode_init imx:mx6 set normal APS and standby PFM mode
board/freescale/common/pfuze.c | 43 ++++++++++++++++++++++ board/freescale/common/pfuze.h | 2 + board/freescale/mx6qsabreauto/mx6qsabreauto.c | 6 +++ board/freescale/mx6sabresd/mx6sabresd.c | 6 ++- board/freescale/mx6sxsabresd/mx6sxsabresd.c | 6 ++- include/power/pfuze100_pmic.h | 53 +++++++++++++++++++++++++++ 6 files changed, 114 insertions(+), 2 deletions(-)

Add more pfuze register offset. And switch mode definition.
Signed-off-by: Peng Fan Peng.Fan@freescale.com ---
Changes v2: none
include/power/pfuze100_pmic.h | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
diff --git a/include/power/pfuze100_pmic.h b/include/power/pfuze100_pmic.h index 1118489..7474afb 100644 --- a/include/power/pfuze100_pmic.h +++ b/include/power/pfuze100_pmic.h @@ -16,14 +16,34 @@ enum {
PFUZE100_SW1ABVOL = 0x20, PFUZE100_SW1ABSTBY = 0x21, + PFUZE100_SW1ABOFF = 0x22, + PFUZE100_SW1ABMODE = 0x23, PUZE_100_SW1ABCONF = 0x24, PFUZE100_SW1CVOL = 0x2e, PFUZE100_SW1CSTBY = 0x2f, + PFUZE100_SW1COFF = 0x30, + PFUZE100_SW1CMODE = 0x31, PFUZE100_SW1CCONF = 0x32, PFUZE100_SW2VOL = 0x35, + PFUZE100_SW2STBY = 0x36, + PFUZE100_SW2OFF = 0x37, + PFUZE100_SW2MODE = 0x38, + PFUZE100_SW2CONF = 0x39, PFUZE100_SW3AVOL = 0x3c, + PFUZE100_SW3ASTBY = 0x3D, + PFUZE100_SW3AOFF = 0x3E, + PFUZE100_SW3AMODE = 0x3F, + PFUZE100_SW3ACONF = 0x40, PFUZE100_SW3BVOL = 0x43, + PFUZE100_SW3BSTBY = 0x44, + PFUZE100_SW3BOFF = 0x45, + PFUZE100_SW3BMODE = 0x46, + PFUZE100_SW3BCONF = 0x47, PFUZE100_SW4VOL = 0x4a, + PFUZE100_SW4STBY = 0x4b, + PFUZE100_SW4OFF = 0x4c, + PFUZE100_SW4MODE = 0x4d, + PFUZE100_SW4CONF = 0x4e, PFUZE100_SWBSTCON1 = 0x66, PFUZE100_VREFDDRCON = 0x6a, PFUZE100_VSNVSVOL = 0x6b, @@ -177,5 +197,38 @@ enum { #define SWBST_MODE_AUTO (2 << 2) #define SWBST_MODE_APS (2 << 3)
+/* + * Regulator Mode Control + * + * OFF: The regulator is switched off and the output voltage is discharged. + * PFM: In this mode, the regulator is always in PFM mode, which is useful + * at light loads for optimized efficiency. + * PWM: In this mode, the regulator is always in PWM mode operation + * regardless of load conditions. + * APS: In this mode, the regulator moves automatically between pulse + * skipping mode and PWM mode depending on load conditions. + * + * SWxMODE[3:0] + * Normal Mode | Standby Mode | value + * OFF OFF 0x0 + * PWM OFF 0x1 + * PFM OFF 0x3 + * APS OFF 0x4 + * PWM PWM 0x5 + * PWM APS 0x6 + * APS APS 0x8 + * APS PFM 0xc + * PWM PFM 0xd + */ +#define OFF_OFF 0x0 +#define PWM_OFF 0x1 +#define PFM_OFF 0x3 +#define APS_OFF 0x4 +#define PWM_PWM 0x5 +#define PWM_APS 0x6 +#define APS_APS 0x8 +#define APS_PFM 0xc +#define PWM_PFM 0xd + int power_pfuze100_init(unsigned char bus); #endif

This patch is to implement pfuze_mode_init and pfuze_regulator_mode_set function, and add prototype in header file.
pfuze_mode_init is to set switching mode for all buck regulators to improve system efficiency. pfuze_regulator_mode_set is to set the regulator's mode according input parameter.
Mode: OFF: The regulator is switched off and the output voltage is discharged. PFM: In this mode, the regulator is always in PFM mode, which is useful at light loads for optimized efficiency. PWM: In this mode, the regulator is always in PWM mode operation regardless of load conditions. APS: In this mode, the regulator moves automatically between pulse skipping mode and PWM mode depending on load conditions.
Signed-off-by: Peng Fan Peng.Fan@freescale.com ---
Changes v2: implement one function mode for one regulator.
board/freescale/common/pfuze.c | 43 ++++++++++++++++++++++++++++++++++++++++++ board/freescale/common/pfuze.h | 2 ++ 2 files changed, 45 insertions(+)
diff --git a/board/freescale/common/pfuze.c b/board/freescale/common/pfuze.c index 2cd1794..f2fffc1 100644 --- a/board/freescale/common/pfuze.c +++ b/board/freescale/common/pfuze.c @@ -8,6 +8,49 @@ #include <power/pmic.h> #include <power/pfuze100_pmic.h>
+/* Set one switch regulator's mode */ +int pfuze_regulator_mode_set(struct pmic *p, u32 regulator, u32 mode) +{ + return pmic_reg_write(p, regulator, mode); +} + +/* Set all switch regulators' working mode */ +int pfuze_mode_init(struct pmic *p, u32 mode) +{ + unsigned char offset, i, switch_num; + u32 id, ret; + + pmic_reg_read(p, PFUZE100_DEVICEID, &id); + id = id & 0xf; + + if (id == 0) { + switch_num = 6; + offset = PFUZE100_SW1CMODE; + } else if (id == 1) { + switch_num = 4; + offset = PFUZE100_SW2MODE; + } else { + printf("Not supported, id=%d\n", id); + return -1; + } + + ret = pfuze_regulator_mode_set(p, PFUZE100_SW1ABMODE, mode); + if (ret < 0) { + printf("Set SW1AB mode error!\n"); + return ret; + } + + for (i = 0; i < switch_num - 1; i++) { + ret = pfuze_regulator_mode_set(p, offset + i * 7, mode); + if (ret < 0) { + printf("Set switch%x mode error!\n", offset + i * 7); + return ret; + } + } + + return ret; +} + struct pmic *pfuze_common_init(unsigned char i2cbus) { struct pmic *p; diff --git a/board/freescale/common/pfuze.h b/board/freescale/common/pfuze.h index 7a4126c..7c316c6 100644 --- a/board/freescale/common/pfuze.h +++ b/board/freescale/common/pfuze.h @@ -8,5 +8,7 @@ #define __PFUZE_BOARD_HELPER__
struct pmic *pfuze_common_init(unsigned char i2cbus); +int pfuze_mode_init(struct pmic *p, u32 mode); +int pfuze_regulator_mode_set(struct pmic *p, u32 regulator, u32 mode);
#endif

Hello Peng,
On 01/15/2015 11:18 AM, Peng Fan wrote:
This patch is to implement pfuze_mode_init and pfuze_regulator_mode_set function, and add prototype in header file.
pfuze_mode_init is to set switching mode for all buck regulators to improve system efficiency. pfuze_regulator_mode_set is to set the regulator's mode according input parameter.
Mode: OFF: The regulator is switched off and the output voltage is discharged. PFM: In this mode, the regulator is always in PFM mode, which is useful at light loads for optimized efficiency. PWM: In this mode, the regulator is always in PWM mode operation regardless of load conditions. APS: In this mode, the regulator moves automatically between pulse skipping mode and PWM mode depending on load conditions.
Signed-off-by: Peng Fan Peng.Fan@freescale.com
Changes v2: implement one function mode for one regulator.
board/freescale/common/pfuze.c | 43 ++++++++++++++++++++++++++++++++++++++++++ board/freescale/common/pfuze.h | 2 ++ 2 files changed, 45 insertions(+)
diff --git a/board/freescale/common/pfuze.c b/board/freescale/common/pfuze.c index 2cd1794..f2fffc1 100644 --- a/board/freescale/common/pfuze.c +++ b/board/freescale/common/pfuze.c @@ -8,6 +8,49 @@ #include <power/pmic.h> #include <power/pfuze100_pmic.h>
+/* Set one switch regulator's mode */
This is not exactly what I mean. Actually by doing this, we have pmic_reg_write() function with just the other name.
+int pfuze_regulator_mode_set(struct pmic *p, u32 regulator, u32 mode) +{
- return pmic_reg_write(p, regulator, mode);
+}
The 'u32 regulator' suggests to pass the regulator number rather than defined mode register address - little unclear.
And the "pfuze.." function name is general and should be implemented by pfuze driver, which could be 'temporary' implemented in:
drivers/power/pmic/pmic_pfuze100.c
And this driver should take care of the PFUZE id and write the given mode to proper pmic register address.
I mean 'temporary' because, soon we will move to the next pmic framework, finally I hope to send it at the end of the next week.
+/* Set all switch regulators' working mode */
So I think, that the below function without the loop could be implemented in the pfuze driver file.
+int pfuze_mode_init(struct pmic *p, u32 mode)
Starting with some like this:
int pfuze_sw_regulator_mode_set(struct pmic *p, u32 ??switch_num??, u32 mode)
+{
- unsigned char offset, i, switch_num;
- u32 id, ret;
- pmic_reg_read(p, PFUZE100_DEVICEID, &id);
- id = id & 0xf;
- if (id == 0) {
switch_num = 6;
offset = PFUZE100_SW1CMODE;
- } else if (id == 1) {
switch_num = 4;
offset = PFUZE100_SW2MODE;
- } else {
printf("Not supported, id=%d\n", id);
return -1;
- }
Ending with something like this: ret = pmic_reg_write(p, offset + switch_num * 7, mode); if (ret ... ... }
And this code below can stay in the 'common.c' code, with small changes: ret = pfuze_sw_regulator_mode_set(p, 1, mode);
- ret = pfuze_regulator_mode_set(p, PFUZE100_SW1ABMODE, mode);
- if (ret < 0) {
printf("Set SW1AB mode error!\n");
return ret;
- }
- for (i = 0; i < switch_num - 1; i++) {
ret = pfuze_sw_regulator_mode_set(p, i, mode);
ret = pfuze_regulator_mode_set(p, offset + i * 7, mode);
if (ret < 0) {
printf("Set switch%x mode error!\n", offset + i * 7);
return ret;
}
- }
- return ret;
+}
- struct pmic *pfuze_common_init(unsigned char i2cbus) { struct pmic *p;
diff --git a/board/freescale/common/pfuze.h b/board/freescale/common/pfuze.h index 7a4126c..7c316c6 100644 --- a/board/freescale/common/pfuze.h +++ b/board/freescale/common/pfuze.h @@ -8,5 +8,7 @@ #define __PFUZE_BOARD_HELPER__
struct pmic *pfuze_common_init(unsigned char i2cbus); +int pfuze_mode_init(struct pmic *p, u32 mode);
+int pfuze_regulator_mode_set(struct pmic *p, u32 regulator, u32 mode);
And this:
int pfuze_sw_regulator_mode_set(...);
should go here: include/power/pfuze100_pmic.h
#endif
I suggested the 'sw' in the function name for the switching regulator type, so then we can pass just switching regulator number as an argument: e.g. 1,2,3...
And maybe in the future you will need ldo or some else regulator type, so adding 'pfuze_ldo_regulator_mode_set' function, will keep the code consistence.
I would like to keep the driver specific code in driver file and common code in the common file.
I think it is reasonable. If you now prefer to keep the first version of this patch set, then you have still my ACK for it:).
Best regards,

Hi, Przemyslaw
On 1/15/2015 10:58 PM, Przemyslaw Marczak wrote:
Hello Peng,
On 01/15/2015 11:18 AM, Peng Fan wrote:
This patch is to implement pfuze_mode_init and pfuze_regulator_mode_set function, and add prototype in header file.
pfuze_mode_init is to set switching mode for all buck regulators to improve system efficiency. pfuze_regulator_mode_set is to set the regulator's mode according input parameter.
Mode: OFF: The regulator is switched off and the output voltage is discharged. PFM: In this mode, the regulator is always in PFM mode, which is useful at light loads for optimized efficiency. PWM: In this mode, the regulator is always in PWM mode operation regardless of load conditions. APS: In this mode, the regulator moves automatically between pulse skipping mode and PWM mode depending on load conditions.
Signed-off-by: Peng Fan Peng.Fan@freescale.com
Changes v2: implement one function mode for one regulator.
board/freescale/common/pfuze.c | 43 ++++++++++++++++++++++++++++++++++++++++++ board/freescale/common/pfuze.h | 2 ++ 2 files changed, 45 insertions(+)
diff --git a/board/freescale/common/pfuze.c b/board/freescale/common/pfuze.c index 2cd1794..f2fffc1 100644 --- a/board/freescale/common/pfuze.c +++ b/board/freescale/common/pfuze.c @@ -8,6 +8,49 @@ #include <power/pmic.h> #include <power/pfuze100_pmic.h>
+/* Set one switch regulator's mode */
This is not exactly what I mean. Actually by doing this, we have pmic_reg_write() function with just the other name.
+int pfuze_regulator_mode_set(struct pmic *p, u32 regulator, u32 mode) +{
- return pmic_reg_write(p, regulator, mode);
+}
The 'u32 regulator' suggests to pass the regulator number rather than defined mode register address - little unclear.
And the "pfuze.." function name is general and should be implemented by pfuze driver, which could be 'temporary' implemented in:
drivers/power/pmic/pmic_pfuze100.c
And this driver should take care of the PFUZE id and write the given mode to proper pmic register address.
I mean 'temporary' because, soon we will move to the next pmic framework, finally I hope to send it at the end of the next week.
+/* Set all switch regulators' working mode */
So I think, that the below function without the loop could be implemented in the pfuze driver file.
+int pfuze_mode_init(struct pmic *p, u32 mode)
Starting with some like this:
int pfuze_sw_regulator_mode_set(struct pmic *p, u32 ??switch_num??, u32 mode)
+{
- unsigned char offset, i, switch_num;
- u32 id, ret;
- pmic_reg_read(p, PFUZE100_DEVICEID, &id);
- id = id & 0xf;
- if (id == 0) {
switch_num = 6;
offset = PFUZE100_SW1CMODE;
- } else if (id == 1) {
switch_num = 4;
offset = PFUZE100_SW2MODE;
- } else {
printf("Not supported, id=%d\n", id);
return -1;
- }
Ending with something like this: ret = pmic_reg_write(p, offset + switch_num * 7, mode); if (ret ... ... }
And this code below can stay in the 'common.c' code, with small changes: ret = pfuze_sw_regulator_mode_set(p, 1, mode);
- ret = pfuze_regulator_mode_set(p, PFUZE100_SW1ABMODE, mode);
- if (ret < 0) {
printf("Set SW1AB mode error!\n");
return ret;
- }
- for (i = 0; i < switch_num - 1; i++) {
ret = pfuze_sw_regulator_mode_set(p, i, mode);
ret = pfuze_regulator_mode_set(p, offset + i * 7, mode);
if (ret < 0) {
printf("Set switch%x mode error!\n", offset + i * 7);
return ret;
}
- }
- return ret;
+}
- struct pmic *pfuze_common_init(unsigned char i2cbus) { struct pmic *p;
diff --git a/board/freescale/common/pfuze.h b/board/freescale/common/pfuze.h index 7a4126c..7c316c6 100644 --- a/board/freescale/common/pfuze.h +++ b/board/freescale/common/pfuze.h @@ -8,5 +8,7 @@ #define __PFUZE_BOARD_HELPER__
struct pmic *pfuze_common_init(unsigned char i2cbus); +int pfuze_mode_init(struct pmic *p, u32 mode);
+int pfuze_regulator_mode_set(struct pmic *p, u32 regulator, u32 mode);
And this:
int pfuze_sw_regulator_mode_set(...);
should go here: include/power/pfuze100_pmic.h
#endif
I suggested the 'sw' in the function name for the switching regulator type, so then we can pass just switching regulator number as an argument: e.g. 1,2,3...
And maybe in the future you will need ldo or some else regulator type, so adding 'pfuze_ldo_regulator_mode_set' function, will keep the code consistence.
I would like to keep the driver specific code in driver file and common code in the common file.
Thanks for your review. Get it. I think this first version is fine for me now, this new feature can be done in future patch.
I think it is reasonable. If you now prefer to keep the first version of this patch set, then you have still my ACK for it:).
Best regards,
Regards, Peng.

To normal mode, use APS switching mode. To standy mode, use PFM switching mode.
Signed-off-by: Peng Fan Peng.Fan@freescale.com ---
Changes: none
board/freescale/mx6qsabreauto/mx6qsabreauto.c | 6 ++++++ board/freescale/mx6sabresd/mx6sabresd.c | 6 +++++- board/freescale/mx6sxsabresd/mx6sxsabresd.c | 6 +++++- 3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/board/freescale/mx6qsabreauto/mx6qsabreauto.c b/board/freescale/mx6qsabreauto/mx6qsabreauto.c index 59387ff..7f0c60b 100644 --- a/board/freescale/mx6qsabreauto/mx6qsabreauto.c +++ b/board/freescale/mx6qsabreauto/mx6qsabreauto.c @@ -29,6 +29,7 @@ #include <asm/arch/crm_regs.h> #include <pca953x.h> #include <power/pmic.h> +#include <power/pfuze100_pmic.h> #include "../common/pfuze.h"
DECLARE_GLOBAL_DATA_PTR; @@ -515,11 +516,16 @@ int board_spi_cs_gpio(unsigned bus, unsigned cs) int power_init_board(void) { struct pmic *p; + unsigned int ret;
p = pfuze_common_init(I2C_PMIC); if (!p) return -ENODEV;
+ ret = pfuze_mode_init(p, APS_PFM); + if (ret < 0) + return -EIO; + return 0; }
diff --git a/board/freescale/mx6sabresd/mx6sabresd.c b/board/freescale/mx6sabresd/mx6sabresd.c index 2f7198d..59544d9 100644 --- a/board/freescale/mx6sabresd/mx6sabresd.c +++ b/board/freescale/mx6sabresd/mx6sabresd.c @@ -631,12 +631,16 @@ int board_init(void) int power_init_board(void) { struct pmic *p; - unsigned int reg; + unsigned int reg, ret;
p = pfuze_common_init(I2C_PMIC); if (!p) return -ENODEV;
+ ret = pfuze_mode_init(p, APS_PFM); + if (ret < 0) + return -EIO; + /* Increase VGEN3 from 2.5 to 2.8V */ pmic_reg_read(p, PFUZE100_VGEN3VOL, ®); reg &= ~LDO_VOL_MASK; diff --git a/board/freescale/mx6sxsabresd/mx6sxsabresd.c b/board/freescale/mx6sxsabresd/mx6sxsabresd.c index 5cc58ac..fbf3337 100644 --- a/board/freescale/mx6sxsabresd/mx6sxsabresd.c +++ b/board/freescale/mx6sxsabresd/mx6sxsabresd.c @@ -199,12 +199,16 @@ static struct i2c_pads_info i2c_pad_info1 = { int power_init_board(void) { struct pmic *p; - unsigned int reg; + unsigned int reg, ret;
p = pfuze_common_init(I2C_PMIC); if (!p) return -ENODEV;
+ ret = pfuze_mode_init(p, APS_PFM); + if (ret < 0) + return -EIO; + /* Enable power of VGEN5 3V3, needed for SD3 */ pmic_reg_read(p, PFUZE100_VGEN5VOL, ®); reg &= ~LDO_VOL_MASK;

On Thu, Jan 15, 2015 at 8:18 AM, Peng Fan Peng.Fan@freescale.com wrote:
@@ -515,11 +516,16 @@ int board_spi_cs_gpio(unsigned bus, unsigned cs) int power_init_board(void) { struct pmic *p;
unsigned int ret; p = pfuze_common_init(I2C_PMIC); if (!p) return -ENODEV;
ret = pfuze_mode_init(p, APS_PFM);
if (ret < 0)
return -EIO;
You should return 'ret' here instead.
return 0;
}
diff --git a/board/freescale/mx6sabresd/mx6sabresd.c b/board/freescale/mx6sabresd/mx6sabresd.c index 2f7198d..59544d9 100644 --- a/board/freescale/mx6sabresd/mx6sabresd.c +++ b/board/freescale/mx6sabresd/mx6sabresd.c @@ -631,12 +631,16 @@ int board_init(void) int power_init_board(void) { struct pmic *p;
unsigned int reg;
unsigned int reg, ret; p = pfuze_common_init(I2C_PMIC); if (!p) return -ENODEV;
ret = pfuze_mode_init(p, APS_PFM);
if (ret < 0)
return -EIO;
Same here.
/* Increase VGEN3 from 2.5 to 2.8V */ pmic_reg_read(p, PFUZE100_VGEN3VOL, ®); reg &= ~LDO_VOL_MASK;
diff --git a/board/freescale/mx6sxsabresd/mx6sxsabresd.c b/board/freescale/mx6sxsabresd/mx6sxsabresd.c index 5cc58ac..fbf3337 100644 --- a/board/freescale/mx6sxsabresd/mx6sxsabresd.c +++ b/board/freescale/mx6sxsabresd/mx6sxsabresd.c @@ -199,12 +199,16 @@ static struct i2c_pads_info i2c_pad_info1 = { int power_init_board(void) { struct pmic *p;
unsigned int reg;
unsigned int reg, ret; p = pfuze_common_init(I2C_PMIC); if (!p) return -ENODEV;
ret = pfuze_mode_init(p, APS_PFM);
if (ret < 0)
return -EIO;
Same here.
participants (4)
-
Fabio Estevam
-
Peng Fan
-
Peng Fan
-
Przemyslaw Marczak