Patchwork [U-Boot,v3] drivers:power:max77686: add function to set voltage and mode

login
register
mail settings
Submitter Piotr Wilczek
Date June 25, 2013, 7:59 a.m.
Message ID <1372147187-19518-1-git-send-email-p.wilczek@samsung.com>
Download mbox | patch
Permalink /patch/254056/
State Accepted
Delegated to: Minkyu Kang
Headers show

Comments

Piotr Wilczek - June 25, 2013, 7:59 a.m.
This patch add new functions to pmic max77686 to set voltage and mode.

Signed-off-by: Piotr Wilczek <p.wilczek@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
CC: Minkyu Kang <mk7.kang@samsung.com>
CC: Rajeshwari Shinde <rajeshwari.s@samsung.com>

Acked-by: Rajeshwari Shinde <rajeshwari.s@samsung.com>
---
Changes in v3:
- removed magic values
- used ARRAY_SIZE() for array size calculation
- used switch case instead if else if
- added return when pmic read error occurs

Changes in v2:
- changed printf to debug

 drivers/power/pmic/pmic_max77686.c |  192 ++++++++++++++++++++++++++++++++++++
 include/power/max77686_pmic.h      |   26 +++++
 2 files changed, 218 insertions(+)
Piotr Wilczek - July 4, 2013, 7:54 a.m.
Dear Minkyu Kang,

Please let me know if you have any more comments on this patch.

Also, there is another patchset to review:
http://patchwork.ozlabs.org/patch/245307/

Best regards,
Piotr Wilczek

> -----Original Message-----
> From: Piotr Wilczek [mailto:p.wilczek@samsung.com]
> Sent: Tuesday, June 25, 2013 10:00 AM
> To: u-boot@lists.denx.de
> Cc: Minkyu Kang; Kyungmin Park; Lukasz Majewski; Piotr Wilczek;
> Rajeshwari Shinde
> Subject: [PATCH v3] drivers:power:max77686: add function to set voltage
> and mode
> 
> This patch add new functions to pmic max77686 to set voltage and mode.
> 
> Signed-off-by: Piotr Wilczek <p.wilczek@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> CC: Minkyu Kang <mk7.kang@samsung.com>
> CC: Rajeshwari Shinde <rajeshwari.s@samsung.com>
> 
> Acked-by: Rajeshwari Shinde <rajeshwari.s@samsung.com>
> ---
> Changes in v3:
> - removed magic values
> - used ARRAY_SIZE() for array size calculation
> - used switch case instead if else if
> - added return when pmic read error occurs
> 
> Changes in v2:
> - changed printf to debug
> 
>  drivers/power/pmic/pmic_max77686.c |  192
> ++++++++++++++++++++++++++++++++++++
>  include/power/max77686_pmic.h      |   26 +++++
>  2 files changed, 218 insertions(+)
> 
> diff --git a/drivers/power/pmic/pmic_max77686.c
> b/drivers/power/pmic/pmic_max77686.c
> index 7fcb4c0..3960ca9 100644
> --- a/drivers/power/pmic/pmic_max77686.c
> +++ b/drivers/power/pmic/pmic_max77686.c
> @@ -30,6 +30,198 @@
> 
>  DECLARE_GLOBAL_DATA_PTR;
> 
> +static const char max77686_buck_addr[] = {
> +	0xff, 0x10, 0x12, 0x1c, 0x26, 0x30, 0x32, 0x34, 0x36, 0x38 };
> +
> +static unsigned int max77686_ldo_volt2hex(int ldo, ulong uV) {
> +	unsigned int hex = 0;
> +
> +	switch (ldo) {
> +	case 1:
> +	case 2:
> +	case 6:
> +	case 7:
> +	case 8:
> +	case 15:
> +		hex = (uV - 800000) / 25000;
> +		break;
> +	default:
> +		hex = (uV - 800000) / 50000;
> +	}
> +
> +	if (hex >= 0 && hex <= MAX77686_LDO_VOLT_MAX_HEX)
> +		return hex;
> +
> +	debug("%s: %ld is wrong voltage value for LDO%d\n", __func__, uV,
> ldo);
> +	return 0;
> +}
> +
> +int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV) {
> +	unsigned int val, ret, hex, adr;
> +
> +	if (ldo < 1 && ldo > 26) {
> +		printf("%s: %d is wrong ldo number\n", __func__, ldo);
> +		return -1;
> +	}
> +
> +	adr = MAX77686_REG_PMIC_LDO1CTRL1 + ldo - 1;
> +	hex = max77686_ldo_volt2hex(ldo, uV);
> +
> +	if (!hex)
> +		return -1;
> +
> +	ret = pmic_reg_read(p, adr, &val);
> +	if (ret)
> +		return ret;
> +
> +	val &= ~MAX77686_LDO_VOLT_MASK;
> +	val |= hex;
> +	ret |= pmic_reg_write(p, adr, val);
> +
> +	return ret;
> +}
> +
> +int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode) {
> +	unsigned int val, ret, adr, mode;
> +
> +	if (ldo < 1 && 26 < ldo) {
> +		printf("%s: %d is wrong ldo number\n", __func__, ldo);
> +		return -1;
> +	}
> +
> +	adr = MAX77686_REG_PMIC_LDO1CTRL1 + ldo - 1;
> +
> +	/* mode */
> +	switch (opmode) {
> +	case OPMODE_OFF:
> +		mode = MAX77686_LDO_MODE_OFF;
> +		break;
> +	case OPMODE_STANDBY:
> +		switch (ldo) {
> +		case 2:
> +		case 6:
> +		case 7:
> +		case 8:
> +		case 10:
> +		case 11:
> +		case 12:
> +		case 14:
> +		case 15:
> +		case 16:
> +			mode = MAX77686_LDO_MODE_STANDBY;
> +			break;
> +		default:
> +			mode = 0xff;
> +		}
> +		break;
> +	case OPMODE_LPM:
> +		mode = MAX77686_LDO_MODE_LPM;
> +		break;
> +	case OPMODE_ON:
> +		mode = MAX77686_LDO_MODE_ON;
> +		break;
> +	default:
> +		mode = 0xff;
> +	}
> +
> +	if (mode == 0xff) {
> +		printf("%s: %d is not supported on LDO%d\n",
> +		       __func__, opmode, ldo);
> +		return -1;
> +	}
> +
> +	ret = pmic_reg_read(p, adr, &val);
> +	if (ret)
> +		return ret;
> +
> +	val &= ~MAX77686_LDO_MODE_MASK;
> +	val |= mode;
> +	ret |= pmic_reg_write(p, adr, val);
> +
> +	return ret;
> +}
> +
> +int max77686_set_buck_mode(struct pmic *p, int buck, char opmode) {
> +	unsigned int val, ret, mask, adr, size, mode, mode_shift;
> +
> +	size = ARRAY_SIZE(max77686_buck_addr);
> +	if (buck >= size) {
> +		printf("%s: %d is wrong buck number\n", __func__, buck);
> +		return -1;
> +	}
> +
> +	adr = max77686_buck_addr[buck];
> +
> +	/* mask */
> +	switch (buck) {
> +	case 2:
> +	case 3:
> +	case 4:
> +		mode_shift = MAX77686_BUCK_MODE_SHIFT_2;
> +		break;
> +	default:
> +		mode_shift = MAX77686_BUCK_MODE_SHIFT_1;
> +	}
> +
> +	mask = MAX77686_BUCK_MODE_MASK << mode_shift;
> +
> +	/* mode */
> +	switch (opmode) {
> +	case OPMODE_OFF:
> +		mode = MAX77686_BUCK_MODE_OFF;
> +		break;
> +	case OPMODE_STANDBY:
> +		switch (buck) {
> +		case 1:
> +		case 2:
> +		case 3:
> +		case 4:
> +			mode = MAX77686_BUCK_MODE_STANDBY << mode_shift;
> +			break;
> +		default:
> +			mode = 0xff;
> +		}
> +		break;
> +	case OPMODE_LPM:
> +		switch (buck) {
> +		case 2:
> +		case 3:
> +		case 4:
> +			mode = MAX77686_BUCK_MODE_LPM << mode_shift;
> +			break;
> +		default:
> +			mode = 0xff;
> +		}
> +		break;
> +	case OPMODE_ON:
> +		mode = MAX77686_BUCK_MODE_ON << mode_shift;
> +		break;
> +	default:
> +		mode = 0xff;
> +	}
> +
> +	if (mode == 0xff) {
> +		printf("%s: %d is not supported on BUCK%d\n",
> +		       __func__, opmode, buck);
> +		return -1;
> +	}
> +
> +	ret = pmic_reg_read(p, adr, &val);
> +	if (ret)
> +		return ret;
> +
> +	val &= ~mask;
> +	val |= mode;
> +	ret |= pmic_reg_write(p, adr, val);
> +
> +	return ret;
> +}
> +
>  int pmic_init(unsigned char bus)
>  {
>  	static const char name[] = "MAX77686_PMIC"; diff --git
> a/include/power/max77686_pmic.h b/include/power/max77686_pmic.h index
> 1c374a9..7339a3e 100644
> --- a/include/power/max77686_pmic.h
> +++ b/include/power/max77686_pmic.h
> @@ -155,6 +155,32 @@ enum {
>  	EN_LDO = (0x3 << 6),
>  };
> 
> +enum {
> +	OPMODE_OFF = 0,
> +	OPMODE_STANDBY,
> +	OPMODE_LPM,
> +	OPMODE_ON,
> +};
> +
> +int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV); int
> +max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode); int
> +max77686_set_buck_mode(struct pmic *p, int buck, char opmode);
> +
> +#define MAX77686_LDO_VOLT_MAX_HEX	0x3f
> +#define MAX77686_LDO_VOLT_MASK		0x3f
> +#define MAX77686_LDO_MODE_MASK		0xc0
> +#define MAX77686_LDO_MODE_OFF		(0x00 << 0x06)
> +#define MAX77686_LDO_MODE_STANDBY	(0x01 << 0x06)
> +#define MAX77686_LDO_MODE_LPM		(0x02 << 0x06)
> +#define MAX77686_LDO_MODE_ON		(0x03 << 0x06)
> +#define MAX77686_BUCK_MODE_MASK		0x03
> +#define MAX77686_BUCK_MODE_SHIFT_1	0x00
> +#define MAX77686_BUCK_MODE_SHIFT_2	0x04
> +#define MAX77686_BUCK_MODE_OFF		0x00
> +#define MAX77686_BUCK_MODE_STANDBY	0x01
> +#define MAX77686_BUCK_MODE_LPM		0x02
> +#define MAX77686_BUCK_MODE_ON		0x03
> +
>  /* Buck1 1 volt value */
>  #define MAX77686_BUCK1OUT_1V	0x5
>  /* Buck1 1.05 volt value */
> --
> 1.7.9.5
Piotr Wilczek - July 15, 2013, 11:29 a.m.
Dear Tom,

This patch is delegated to you. Could you review this patch for the next 
release?

Best regards,
Piotr Wilczek

--
Samsung R&D Institute Poland (SRPOL)

On 06/25/2013 09:59 AM, Piotr Wilczek wrote:
> This patch add new functions to pmic max77686 to set voltage and mode.
>
> Signed-off-by: Piotr Wilczek <p.wilczek@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> CC: Minkyu Kang <mk7.kang@samsung.com>
> CC: Rajeshwari Shinde <rajeshwari.s@samsung.com>
>
> Acked-by: Rajeshwari Shinde <rajeshwari.s@samsung.com>
> ---
> Changes in v3:
> - removed magic values
> - used ARRAY_SIZE() for array size calculation
> - used switch case instead if else if
> - added return when pmic read error occurs
>
> Changes in v2:
> - changed printf to debug
>
>   drivers/power/pmic/pmic_max77686.c |  192 ++++++++++++++++++++++++++++++++++++
>   include/power/max77686_pmic.h      |   26 +++++
>   2 files changed, 218 insertions(+)
>
> diff --git a/drivers/power/pmic/pmic_max77686.c b/drivers/power/pmic/pmic_max77686.c
> index 7fcb4c0..3960ca9 100644
> --- a/drivers/power/pmic/pmic_max77686.c
> +++ b/drivers/power/pmic/pmic_max77686.c
> @@ -30,6 +30,198 @@
>
>   DECLARE_GLOBAL_DATA_PTR;
>
> +static const char max77686_buck_addr[] = {
> +	0xff, 0x10, 0x12, 0x1c, 0x26, 0x30, 0x32, 0x34, 0x36, 0x38
> +};
> +
> +static unsigned int max77686_ldo_volt2hex(int ldo, ulong uV)
> +{
> +	unsigned int hex = 0;
> +
> +	switch (ldo) {
> +	case 1:
> +	case 2:
> +	case 6:
> +	case 7:
> +	case 8:
> +	case 15:
> +		hex = (uV - 800000) / 25000;
> +		break;
> +	default:
> +		hex = (uV - 800000) / 50000;
> +	}
> +
> +	if (hex >= 0 && hex <= MAX77686_LDO_VOLT_MAX_HEX)
> +		return hex;
> +
> +	debug("%s: %ld is wrong voltage value for LDO%d\n", __func__, uV, ldo);
> +	return 0;
> +}
> +
> +int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV)
> +{
> +	unsigned int val, ret, hex, adr;
> +
> +	if (ldo < 1 && ldo > 26) {
> +		printf("%s: %d is wrong ldo number\n", __func__, ldo);
> +		return -1;
> +	}
> +
> +	adr = MAX77686_REG_PMIC_LDO1CTRL1 + ldo - 1;
> +	hex = max77686_ldo_volt2hex(ldo, uV);
> +
> +	if (!hex)
> +		return -1;
> +
> +	ret = pmic_reg_read(p, adr, &val);
> +	if (ret)
> +		return ret;
> +
> +	val &= ~MAX77686_LDO_VOLT_MASK;
> +	val |= hex;
> +	ret |= pmic_reg_write(p, adr, val);
> +
> +	return ret;
> +}
> +
> +int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode)
> +{
> +	unsigned int val, ret, adr, mode;
> +
> +	if (ldo < 1 && 26 < ldo) {
> +		printf("%s: %d is wrong ldo number\n", __func__, ldo);
> +		return -1;
> +	}
> +
> +	adr = MAX77686_REG_PMIC_LDO1CTRL1 + ldo - 1;
> +
> +	/* mode */
> +	switch (opmode) {
> +	case OPMODE_OFF:
> +		mode = MAX77686_LDO_MODE_OFF;
> +		break;
> +	case OPMODE_STANDBY:
> +		switch (ldo) {
> +		case 2:
> +		case 6:
> +		case 7:
> +		case 8:
> +		case 10:
> +		case 11:
> +		case 12:
> +		case 14:
> +		case 15:
> +		case 16:
> +			mode = MAX77686_LDO_MODE_STANDBY;
> +			break;
> +		default:
> +			mode = 0xff;
> +		}
> +		break;
> +	case OPMODE_LPM:
> +		mode = MAX77686_LDO_MODE_LPM;
> +		break;
> +	case OPMODE_ON:
> +		mode = MAX77686_LDO_MODE_ON;
> +		break;
> +	default:
> +		mode = 0xff;
> +	}
> +
> +	if (mode == 0xff) {
> +		printf("%s: %d is not supported on LDO%d\n",
> +		       __func__, opmode, ldo);
> +		return -1;
> +	}
> +
> +	ret = pmic_reg_read(p, adr, &val);
> +	if (ret)
> +		return ret;
> +
> +	val &= ~MAX77686_LDO_MODE_MASK;
> +	val |= mode;
> +	ret |= pmic_reg_write(p, adr, val);
> +
> +	return ret;
> +}
> +
> +int max77686_set_buck_mode(struct pmic *p, int buck, char opmode)
> +{
> +	unsigned int val, ret, mask, adr, size, mode, mode_shift;
> +
> +	size = ARRAY_SIZE(max77686_buck_addr);
> +	if (buck >= size) {
> +		printf("%s: %d is wrong buck number\n", __func__, buck);
> +		return -1;
> +	}
> +
> +	adr = max77686_buck_addr[buck];
> +
> +	/* mask */
> +	switch (buck) {
> +	case 2:
> +	case 3:
> +	case 4:
> +		mode_shift = MAX77686_BUCK_MODE_SHIFT_2;
> +		break;
> +	default:
> +		mode_shift = MAX77686_BUCK_MODE_SHIFT_1;
> +	}
> +
> +	mask = MAX77686_BUCK_MODE_MASK << mode_shift;
> +
> +	/* mode */
> +	switch (opmode) {
> +	case OPMODE_OFF:
> +		mode = MAX77686_BUCK_MODE_OFF;
> +		break;
> +	case OPMODE_STANDBY:
> +		switch (buck) {
> +		case 1:
> +		case 2:
> +		case 3:
> +		case 4:
> +			mode = MAX77686_BUCK_MODE_STANDBY << mode_shift;
> +			break;
> +		default:
> +			mode = 0xff;
> +		}
> +		break;
> +	case OPMODE_LPM:
> +		switch (buck) {
> +		case 2:
> +		case 3:
> +		case 4:
> +			mode = MAX77686_BUCK_MODE_LPM << mode_shift;
> +			break;
> +		default:
> +			mode = 0xff;
> +		}
> +		break;
> +	case OPMODE_ON:
> +		mode = MAX77686_BUCK_MODE_ON << mode_shift;
> +		break;
> +	default:
> +		mode = 0xff;
> +	}
> +
> +	if (mode == 0xff) {
> +		printf("%s: %d is not supported on BUCK%d\n",
> +		       __func__, opmode, buck);
> +		return -1;
> +	}
> +
> +	ret = pmic_reg_read(p, adr, &val);
> +	if (ret)
> +		return ret;
> +
> +	val &= ~mask;
> +	val |= mode;
> +	ret |= pmic_reg_write(p, adr, val);
> +
> +	return ret;
> +}
> +
>   int pmic_init(unsigned char bus)
>   {
>   	static const char name[] = "MAX77686_PMIC";
> diff --git a/include/power/max77686_pmic.h b/include/power/max77686_pmic.h
> index 1c374a9..7339a3e 100644
> --- a/include/power/max77686_pmic.h
> +++ b/include/power/max77686_pmic.h
> @@ -155,6 +155,32 @@ enum {
>   	EN_LDO = (0x3 << 6),
>   };
>
> +enum {
> +	OPMODE_OFF = 0,
> +	OPMODE_STANDBY,
> +	OPMODE_LPM,
> +	OPMODE_ON,
> +};
> +
> +int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV);
> +int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode);
> +int max77686_set_buck_mode(struct pmic *p, int buck, char opmode);
> +
> +#define MAX77686_LDO_VOLT_MAX_HEX	0x3f
> +#define MAX77686_LDO_VOLT_MASK		0x3f
> +#define MAX77686_LDO_MODE_MASK		0xc0
> +#define MAX77686_LDO_MODE_OFF		(0x00 << 0x06)
> +#define MAX77686_LDO_MODE_STANDBY	(0x01 << 0x06)
> +#define MAX77686_LDO_MODE_LPM		(0x02 << 0x06)
> +#define MAX77686_LDO_MODE_ON		(0x03 << 0x06)
> +#define MAX77686_BUCK_MODE_MASK		0x03
> +#define MAX77686_BUCK_MODE_SHIFT_1	0x00
> +#define MAX77686_BUCK_MODE_SHIFT_2	0x04
> +#define MAX77686_BUCK_MODE_OFF		0x00
> +#define MAX77686_BUCK_MODE_STANDBY	0x01
> +#define MAX77686_BUCK_MODE_LPM		0x02
> +#define MAX77686_BUCK_MODE_ON		0x03
> +
>   /* Buck1 1 volt value */
>   #define MAX77686_BUCK1OUT_1V	0x5
>   /* Buck1 1.05 volt value */
>
Tom Rini - July 15, 2013, 2:46 p.m.
On Tue, Jun 25, 2013 at 09:59:47AM +0200, Piotr Wilczek wrote:

> This patch add new functions to pmic max77686 to set voltage and mode.
> 
> Signed-off-by: Piotr Wilczek <p.wilczek@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> CC: Minkyu Kang <mk7.kang@samsung.com>
> CC: Rajeshwari Shinde <rajeshwari.s@samsung.com>
> 
> Acked-by: Rajeshwari Shinde <rajeshwari.s@samsung.com>

Acked-by: Tom Rini <trini@ti.com>

And re-assigned to Minkyu as I assume there's other patches needed that
enable this on a samsung board of some sort.
Minkyu Kang - Aug. 30, 2013, 3:26 a.m.
On 15/07/13 23:46, Tom Rini wrote:
> On Tue, Jun 25, 2013 at 09:59:47AM +0200, Piotr Wilczek wrote:
> 
>> This patch add new functions to pmic max77686 to set voltage and mode.
>>
>> Signed-off-by: Piotr Wilczek <p.wilczek@samsung.com>
>> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
>> CC: Minkyu Kang <mk7.kang@samsung.com>
>> CC: Rajeshwari Shinde <rajeshwari.s@samsung.com>
>>
>> Acked-by: Rajeshwari Shinde <rajeshwari.s@samsung.com>
> 
> Acked-by: Tom Rini <trini@ti.com>
> 
> And re-assigned to Minkyu as I assume there's other patches needed that
> enable this on a samsung board of some sort.

applied to u-boot-samsung.

Thanks,
Minkyu Kang.

Patch

diff --git a/drivers/power/pmic/pmic_max77686.c b/drivers/power/pmic/pmic_max77686.c
index 7fcb4c0..3960ca9 100644
--- a/drivers/power/pmic/pmic_max77686.c
+++ b/drivers/power/pmic/pmic_max77686.c
@@ -30,6 +30,198 @@ 
 
 DECLARE_GLOBAL_DATA_PTR;
 
+static const char max77686_buck_addr[] = {
+	0xff, 0x10, 0x12, 0x1c, 0x26, 0x30, 0x32, 0x34, 0x36, 0x38
+};
+
+static unsigned int max77686_ldo_volt2hex(int ldo, ulong uV)
+{
+	unsigned int hex = 0;
+
+	switch (ldo) {
+	case 1:
+	case 2:
+	case 6:
+	case 7:
+	case 8:
+	case 15:
+		hex = (uV - 800000) / 25000;
+		break;
+	default:
+		hex = (uV - 800000) / 50000;
+	}
+
+	if (hex >= 0 && hex <= MAX77686_LDO_VOLT_MAX_HEX)
+		return hex;
+
+	debug("%s: %ld is wrong voltage value for LDO%d\n", __func__, uV, ldo);
+	return 0;
+}
+
+int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV)
+{
+	unsigned int val, ret, hex, adr;
+
+	if (ldo < 1 && ldo > 26) {
+		printf("%s: %d is wrong ldo number\n", __func__, ldo);
+		return -1;
+	}
+
+	adr = MAX77686_REG_PMIC_LDO1CTRL1 + ldo - 1;
+	hex = max77686_ldo_volt2hex(ldo, uV);
+
+	if (!hex)
+		return -1;
+
+	ret = pmic_reg_read(p, adr, &val);
+	if (ret)
+		return ret;
+
+	val &= ~MAX77686_LDO_VOLT_MASK;
+	val |= hex;
+	ret |= pmic_reg_write(p, adr, val);
+
+	return ret;
+}
+
+int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode)
+{
+	unsigned int val, ret, adr, mode;
+
+	if (ldo < 1 && 26 < ldo) {
+		printf("%s: %d is wrong ldo number\n", __func__, ldo);
+		return -1;
+	}
+
+	adr = MAX77686_REG_PMIC_LDO1CTRL1 + ldo - 1;
+
+	/* mode */
+	switch (opmode) {
+	case OPMODE_OFF:
+		mode = MAX77686_LDO_MODE_OFF;
+		break;
+	case OPMODE_STANDBY:
+		switch (ldo) {
+		case 2:
+		case 6:
+		case 7:
+		case 8:
+		case 10:
+		case 11:
+		case 12:
+		case 14:
+		case 15:
+		case 16:
+			mode = MAX77686_LDO_MODE_STANDBY;
+			break;
+		default:
+			mode = 0xff;
+		}
+		break;
+	case OPMODE_LPM:
+		mode = MAX77686_LDO_MODE_LPM;
+		break;
+	case OPMODE_ON:
+		mode = MAX77686_LDO_MODE_ON;
+		break;
+	default:
+		mode = 0xff;
+	}
+
+	if (mode == 0xff) {
+		printf("%s: %d is not supported on LDO%d\n",
+		       __func__, opmode, ldo);
+		return -1;
+	}
+
+	ret = pmic_reg_read(p, adr, &val);
+	if (ret)
+		return ret;
+
+	val &= ~MAX77686_LDO_MODE_MASK;
+	val |= mode;
+	ret |= pmic_reg_write(p, adr, val);
+
+	return ret;
+}
+
+int max77686_set_buck_mode(struct pmic *p, int buck, char opmode)
+{
+	unsigned int val, ret, mask, adr, size, mode, mode_shift;
+
+	size = ARRAY_SIZE(max77686_buck_addr);
+	if (buck >= size) {
+		printf("%s: %d is wrong buck number\n", __func__, buck);
+		return -1;
+	}
+
+	adr = max77686_buck_addr[buck];
+
+	/* mask */
+	switch (buck) {
+	case 2:
+	case 3:
+	case 4:
+		mode_shift = MAX77686_BUCK_MODE_SHIFT_2;
+		break;
+	default:
+		mode_shift = MAX77686_BUCK_MODE_SHIFT_1;
+	}
+
+	mask = MAX77686_BUCK_MODE_MASK << mode_shift;
+
+	/* mode */
+	switch (opmode) {
+	case OPMODE_OFF:
+		mode = MAX77686_BUCK_MODE_OFF;
+		break;
+	case OPMODE_STANDBY:
+		switch (buck) {
+		case 1:
+		case 2:
+		case 3:
+		case 4:
+			mode = MAX77686_BUCK_MODE_STANDBY << mode_shift;
+			break;
+		default:
+			mode = 0xff;
+		}
+		break;
+	case OPMODE_LPM:
+		switch (buck) {
+		case 2:
+		case 3:
+		case 4:
+			mode = MAX77686_BUCK_MODE_LPM << mode_shift;
+			break;
+		default:
+			mode = 0xff;
+		}
+		break;
+	case OPMODE_ON:
+		mode = MAX77686_BUCK_MODE_ON << mode_shift;
+		break;
+	default:
+		mode = 0xff;
+	}
+
+	if (mode == 0xff) {
+		printf("%s: %d is not supported on BUCK%d\n",
+		       __func__, opmode, buck);
+		return -1;
+	}
+
+	ret = pmic_reg_read(p, adr, &val);
+	if (ret)
+		return ret;
+
+	val &= ~mask;
+	val |= mode;
+	ret |= pmic_reg_write(p, adr, val);
+
+	return ret;
+}
+
 int pmic_init(unsigned char bus)
 {
 	static const char name[] = "MAX77686_PMIC";
diff --git a/include/power/max77686_pmic.h b/include/power/max77686_pmic.h
index 1c374a9..7339a3e 100644
--- a/include/power/max77686_pmic.h
+++ b/include/power/max77686_pmic.h
@@ -155,6 +155,32 @@  enum {
 	EN_LDO = (0x3 << 6),
 };
 
+enum {
+	OPMODE_OFF = 0,
+	OPMODE_STANDBY,
+	OPMODE_LPM,
+	OPMODE_ON,
+};
+
+int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV);
+int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode);
+int max77686_set_buck_mode(struct pmic *p, int buck, char opmode);
+
+#define MAX77686_LDO_VOLT_MAX_HEX	0x3f
+#define MAX77686_LDO_VOLT_MASK		0x3f
+#define MAX77686_LDO_MODE_MASK		0xc0
+#define MAX77686_LDO_MODE_OFF		(0x00 << 0x06)
+#define MAX77686_LDO_MODE_STANDBY	(0x01 << 0x06)
+#define MAX77686_LDO_MODE_LPM		(0x02 << 0x06)
+#define MAX77686_LDO_MODE_ON		(0x03 << 0x06)
+#define MAX77686_BUCK_MODE_MASK		0x03
+#define MAX77686_BUCK_MODE_SHIFT_1	0x00
+#define MAX77686_BUCK_MODE_SHIFT_2	0x04
+#define MAX77686_BUCK_MODE_OFF		0x00
+#define MAX77686_BUCK_MODE_STANDBY	0x01
+#define MAX77686_BUCK_MODE_LPM		0x02
+#define MAX77686_BUCK_MODE_ON		0x03
+
 /* Buck1 1 volt value */
 #define MAX77686_BUCK1OUT_1V	0x5
 /* Buck1 1.05 volt value */