All of lore.kernel.org
 help / color / mirror / Atom feed
From: Piotr Wilczek <p.wilczek@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 01/12] pmic:max77686: add function to set voltage and mode
Date: Fri, 17 May 2013 14:55:44 +0200	[thread overview]
Message-ID: <1368795355-6717-2-git-send-email-p.wilczek@samsung.com> (raw)
In-Reply-To: <1368795355-6717-1-git-send-email-p.wilczek@samsung.com>

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: None
Changes in v2:
- changed printf to debug

 drivers/power/pmic/pmic_max77686.c |  186 ++++++++++++++++++++++++++++++++++++
 include/power/max77686_pmic.h      |   11 +++
 2 files changed, 197 insertions(+)

diff --git a/drivers/power/pmic/pmic_max77686.c b/drivers/power/pmic/pmic_max77686.c
index 7fcb4c0..dabd6b6 100644
--- a/drivers/power/pmic/pmic_max77686.c
+++ b/drivers/power/pmic/pmic_max77686.c
@@ -30,6 +30,192 @@
 
 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;
+	const unsigned int max_hex = 0x3f;
+
+	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 (0 <= hex && hex <= 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, mask;
+
+	if (ldo < 1 && 26 < ldo) {
+		printf("%s: %d is wrong ldo number\n", __func__, ldo);
+		return -1;
+	}
+
+	adr = MAX77686_REG_PMIC_LDO1CTRL1 + ldo - 1;
+	mask = 0x3f;
+	hex = max77686_ldo_volt2hex(ldo, uV);
+
+	if (!hex)
+		return -1;
+
+	ret = pmic_reg_read(p, adr, &val);
+	val &= ~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, mask, 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;
+
+	/* mask */
+	mask = 0xc0;
+
+	/* mode */
+	if (opmode == OPMODE_OFF) {
+		mode = 0x00;
+	} else if (opmode == 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 = 0x40;
+			break;
+		default:
+			mode = 0xff;
+		}
+	} else if (opmode == OPMODE_LPM) {
+		mode = 0x80;
+	} else if (opmode == OPMODE_ON) {
+		mode = 0xc0;
+	} else {
+		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);
+	val &= ~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;
+
+	size = sizeof(max77686_buck_addr) / sizeof(*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:
+		mask = 0x30;
+		break;
+	default:
+		mask = 0x03;
+	}
+
+	/* mode */
+	if (opmode == OPMODE_OFF) {
+		mode = 0x00;
+	} else if (opmode == OPMODE_STANDBY) {
+		switch (buck) {
+		case 1:
+			mode = 0x01;
+			break;
+		case 2:
+		case 3:
+		case 4:
+			mode = 0x10;
+			break;
+		default:
+			mode = 0xff;
+		}
+	} else if (opmode == OPMODE_LPM) {
+		switch (buck) {
+		case 2:
+		case 3:
+		case 4:
+			mode = 0x20;
+			break;
+		default:
+			mode = 0xff;
+		}
+	} else if (opmode == OPMODE_ON) {
+		switch (buck) {
+		case 2:
+		case 3:
+		case 4:
+			mode = 0x30;
+			break;
+		default:
+			mode = 0x03;
+		}
+	} else {
+		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);
+	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 fdc7ca9..ce58c02 100644
--- a/include/power/max77686_pmic.h
+++ b/include/power/max77686_pmic.h
@@ -155,6 +155,17 @@ 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);
+
 /* Buck1 1 volt value */
 #define MAX77686_BUCK1OUT_1V	0x5
 #define MAX77686_BUCK1CTRL_EN	(3 << 0)
-- 
1.7.9.5

  reply	other threads:[~2013-05-17 12:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-17 12:55 [U-Boot] [PATCH v3 0/12] Introduce Samsung's new board Trats2 Piotr Wilczek
2013-05-17 12:55 ` Piotr Wilczek [this message]
2013-05-17 12:55 ` [U-Boot] [PATCH v3 02/12] drivers:power:max77693: add support for new multi function pmic max77693 Piotr Wilczek
2013-05-17 12:55 ` [U-Boot] [PATCH v3 03/12] arm:exynos:gpio: fix s5p_gpio_part_max for exynos4x12 Piotr Wilczek
2013-05-17 12:55 ` [U-Boot] [PATCH v3 04/12] i2c:multi_i2c: adapt file to new i2c framework Piotr Wilczek
2013-05-17 12:55 ` [U-Boot] [PATCH v3 05/12] power: fix pmic command Piotr Wilczek
2013-05-17 12:55 ` [U-Boot] [PATCH v3 06/12] drivers:power:power_i2c: adapt file to new i2c framework Piotr Wilczek
2013-05-17 12:55 ` [U-Boot] [PATCH v3 07/12] driver:i2c:s3c24x0: adapt driver " Piotr Wilczek
2013-05-17 12:55 ` [U-Boot] [PATCH v3 08/12] drivers:video:s6e8ax0: change data_to_send array to static Piotr Wilczek
2013-05-17 12:55 ` [U-Boot] [PATCH v3 09/12] drivers:lcd: fix unaligned access on lcd Piotr Wilczek
2013-05-17 12:55 ` [U-Boot] [PATCH v3 10/12] samsung: trats2: add support for new board Trats2 Piotr Wilczek
2013-05-17 12:55 ` [U-Boot] [PATCH v3 11/12] board:VCMA9 switch to ne i2c framework Piotr Wilczek
2013-05-17 12:55 ` [U-Boot] [PATCH v3 12/12] board:smdk5250: switch to new " Piotr Wilczek
2013-05-21  8:35 ` [U-Boot] [PATCH v3 0/12] Introduce Samsung's new board Trats2 Minkyu Kang
2013-05-21  9:00   ` Piotr Wilczek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1368795355-6717-2-git-send-email-p.wilczek@samsung.com \
    --to=p.wilczek@samsung.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.