All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lubomir Popov <lpopov@mm-sol.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V2] OMAP5: Power: Add more functionality to Palmas driver
Date: Wed, 15 May 2013 17:51:45 +0300	[thread overview]
Message-ID: <5193A101.80002@mm-sol.com> (raw)

Add some useful functions, and the corresponding definitions.

Signed-off-by: Lubomir Popov <lpopov@mm-sol.com>
---
V2 aligns to changed PMIC name (and file names accordingly)
from twl6035 to Palmas and is based on current u-boot-ti
master.

 drivers/power/palmas.c |  108 ++++++++++++++++++++++++++++++++++++++++++------
 include/palmas.h       |   81 +++++++++++++++++++++++++++++++++---
 2 files changed, 171 insertions(+), 18 deletions(-)

diff --git a/drivers/power/palmas.c b/drivers/power/palmas.c
index 09c832d..1f9bd7e 100644
--- a/drivers/power/palmas.c
+++ b/drivers/power/palmas.c
@@ -25,28 +25,112 @@
 
 void palmas_init_settings(void)
 {
-	return;
+#ifdef CONFIG_PALMAS_SMPS7_FPWM
+	int err;
+	/*
+	 * Set SMPS7 (1.8 V I/O supply) to forced PWM mode.
+	 * This reduces noise (but affects efficiency).
+	 */
+	u8 val = SMPS_MODE_SLP_FPWM | SMPS_MODE_ACT_FPWM;
+	if ((err = palmas_i2c_write_u8(PALMAS_CHIP_P1, SMPS7_CTRL, val)))
+		printf("palmas: Could not force PWM for SMPS7: err = %d\n", err);
+#endif
 }
 
 int palmas_mmc1_poweron_ldo(void)
 {
 	u8 val = 0;
 
-	/* set LDO9 TWL6035 to 3V */
-	val = 0x2b; /* (3 -.9)*28 +1 */
-
-	if (palmas_i2c_write_u8(0x48, LDO9_VOLTAGE, val)) {
-		printf("twl6035: could not set LDO9 voltage.\n");
+	/* Set Palmas LDO9 to 3.0 V */
+	val = LDO_VOLT_3V0;
+	if (palmas_i2c_write_u8(PALMAS_CHIP_P1, LDO9_VOLTAGE, val)) {
+		printf("palmas: could not set LDO9 voltage.\n");
 		return 1;
 	}
-
 	/* TURN ON LDO9 */
-	val = LDO_ON | LDO_MODE_SLEEP | LDO_MODE_ACTIVE;
-
-	if (palmas_i2c_write_u8(0x48, LDO9_CTRL, val)) {
-		printf("twl6035: could not turn on LDO9.\n");
+	val = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
+	if (palmas_i2c_write_u8(PALMAS_CHIP_P1, LDO9_CTRL, val)) {
+		printf("palmas: could not turn on LDO9.\n");
 		return 1;
 	}
-
 	return 0;
 }
+
+/*
+ * On some hardware the SD card socket and LDO9_IN are powered by an
+ * external 3.3 V regulator, while the output of LDO9 delivers VDDS_SDCARD
+ * for the OMAP interface only. This implies that LDO9 could be set to
+ * 'bypass' mode when required (e.g. for 3.3 V cards).
+ */
+int palmas_mmc1_set_ldo9(u8 vsel)
+{
+	u8 cval=0, vval=0;	/* Off by default */
+	int err;
+
+	if (vsel) {
+		/* Turn on */
+		if (vsel > LDO_VOLT_3V3) {
+			/* Put LDO9 in bypass */
+			cval = LDO9_BYP_EN | RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
+			vval = LDO_VOLT_3V3;
+		}
+		else {
+			cval = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
+			vval = vsel & 0x3f;
+		}
+	}
+	if ((err = palmas_i2c_write_u8(PALMAS_CHIP_P1, LDO9_VOLTAGE, vval))) {
+		printf("palmas: could not set LDO9 %s: err = %d\n", 
+			vsel > LDO_VOLT_3V3 ? "bypass" : "voltage", err);
+		return err;
+	}
+	if ((err = palmas_i2c_write_u8(PALMAS_CHIP_P1, LDO9_CTRL, cval)))
+		printf("palmas: could not turn %s LDO9: err = %d\n",
+			cval ? "on" : "off", err);
+	return err;
+}
+
+/* Turn audio codec power and 32 kHz clock on/off. Use for TWL604x only. */
+int palmas_audio_power(u8 on)
+{
+	u8 cval=0, vval=0, c32k=0;
+	int err;
+
+	if (on) {
+		vval = SMPS_VOLT_2V1;
+		cval = SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO;
+		c32k = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
+	}
+	/* Set SMPS9 to 2.1 V (for TWL604x), or to 0 (off) */
+	if ((err = palmas_i2c_write_u8(PALMAS_CHIP_P1, SMPS9_VOLTAGE, vval))) {
+		printf("palmas: could not set SMPS9 voltage: err = %d\n", err);
+		return err;
+	}
+	/* Turn on or off SMPS9 */
+	if ((err = palmas_i2c_write_u8(PALMAS_CHIP_P1, SMPS9_CTRL, cval))) {
+		printf("palmas: could not turn SMPS9 %s: err = %d\n",
+			cval ? "on" : "off", err);
+		return err;
+	}
+	/* Output 32 kHz clock on or off */
+	if ((err = palmas_i2c_write_u8(PALMAS_CHIP_P1, CLK32KGAUDIO_CTRL, c32k)))
+		printf("palmas: could not turn CLK32KGAUDIO %s: err = %d\n",
+			c32k ? "on" : "off", err);
+	return err;
+}
+
+/*
+ * Enable/disable back-up battery (or super cap) charging.
+ * Please use defined BB_xxx values.
+ */
+int palmas_enable_bb_charge(u8 bb_fields)
+{
+	u8 val = bb_fields & 0x0f;
+	int err;
+
+	val |= (VRTC_EN_SLP | VRTC_EN_OFF | VRTC_PWEN);
+	if ((err = palmas_i2c_write_u8(PALMAS_CHIP_P1, BB_VRTC_CTRL, val)))
+		printf("palmas: could not set BB_VRTC_CTRL to 0x%02x: err = %d\n", val, err);
+	return err;
+}
+
diff --git a/include/palmas.h b/include/palmas.h
index 3b18589..7becb97 100644
--- a/include/palmas.h
+++ b/include/palmas.h
@@ -27,16 +27,82 @@
 #include <i2c.h>
 
 /* I2C chip addresses */
-#define PALMAS_CHIP_ADDR	0x48
+#define PALMAS_CHIP_P1		0x48	/* Page 1 */
+#define PALMAS_CHIP_P2		0x49	/* Page 2 */
+#define PALMAS_CHIP_P3		0x4a	/* Page 3 */
 
-/* 0x1XY translates to page 1, register address 0xXY */
+/* Page 1 registers (0x1XY translates to page 1, reg addr 0xXY): */
+
+/* LDO9_CTRL */
 #define LDO9_CTRL		0x60
 #define LDO9_VOLTAGE		0x61
 
-/* Bit field definitions for LDOx_CTRL */
-#define LDO_ON			(1 << 4)
-#define LDO_MODE_SLEEP		(1 << 2)
-#define LDO_MODE_ACTIVE		(1 << 0)
+/* LDOUSB_CTRL */
+#define LDOUSB_CTRL		0x64
+#define LDOUSB_VOLTAGE		0x65
+
+/* Control of 32 kHz audio clock */
+#define CLK32KGAUDIO_CTRL	0xd5
+
+/* SYSEN2_CTRL for VCC_3v3_AUX supply on the sEVM */
+#define SYSEN2_CTRL		0xd9
+
+/*
+ * Bit field definitions for LDOx_CTRL, SYSENx_CTRL 
+ * and some other xxx_CTRL resources:
+ */
+#define LDO9_BYP_EN		(1 << 6)	/* LDO9 only! */
+#define RSC_STAT_ON		(1 << 4)	/* RO bit! */
+#define RSC_MODE_SLEEP		(1 << 2)
+#define RSC_MODE_ACTIVE		(1 << 0)
+
+/* Some LDO voltage values */
+#define LDO_VOLT_OFF		0
+#define LDO_VOLT_1V8		0x13
+#define LDO_VOLT_3V0		0x2b
+#define LDO_VOLT_3V3		0x31
+/* Request bypass, LDO9 only */
+#define LDO9_BYPASS		0x3f
+
+/* SMPS7_CTRL */
+#define SMPS7_CTRL		0x30
+
+/* SMPS9_CTRL */
+#define SMPS9_CTRL		0x38
+#define SMPS9_VOLTAGE		0x3b
+
+/* Bit field definitions for SMPSx_CTRL */
+#define SMPS_MODE_ACT_AUTO	1
+#define SMPS_MODE_ACT_ECO	2
+#define SMPS_MODE_ACT_FPWM	3
+#define SMPS_MODE_SLP_AUTO	(1 << 2)
+#define SMPS_MODE_SLP_ECO	(2 << 2)
+#define SMPS_MODE_SLP_FPWM	(3 << 2)
+
+/*
+ * Some popular SMPS voltages, all with RANGE=1; note
+ * that RANGE cannot be changed on the fly
+ */
+#define SMPS_VOLT_OFF		0
+#define SMPS_VOLT_1V2		0x90
+#define SMPS_VOLT_1V8		0xae
+#define SMPS_VOLT_2V1		0xbd
+#define SMPS_VOLT_3V0		0xea
+#define SMPS_VOLT_3V3		0xf9
+
+/* Backup Battery & VRTC Control */
+#define BB_VRTC_CTRL		0xa8
+/* Bit definitions for BB_VRTC_CTRL */
+#define VRTC_EN_SLP		(1 << 6)
+#define VRTC_EN_OFF		(1 << 5)
+#define VRTC_PWEN		(1 << 4)
+#define BB_LOW_ICHRG		(1 << 3)
+#define BB_HIGH_ICHRG		(0 << 3)
+#define BB_VSEL_3V0		(0 << 1)
+#define BB_VSEL_2V5		(1 << 1)
+#define BB_VSEL_3V15		(2 << 1)
+#define BB_VSEL_VBAT		(3 << 1)
+#define BB_CHRG_EN		(1 << 0)
 
 /*
  * Functions to read and write from TPS659038/TWL6035/TWL6037
@@ -54,5 +120,8 @@ static inline int palmas_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
 
 void palmas_init_settings(void);
 int palmas_mmc1_poweron_ldo(void);
+int palmas_mmc1_set_ldo9(u8 vsel);
+int palmas_audio_power(u8 on);
+int palmas_enable_bb_charge(u8 bb_fields);
 
 #endif /* PALMAS_H */
-- 
1.7.9.5

             reply	other threads:[~2013-05-15 14:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-15 14:51 Lubomir Popov [this message]
2013-05-16 18:29 ` [U-Boot] [PATCH V2] OMAP5: Power: Add more functionality to Palmas driver menon.nishanth at gmail.com
2013-05-16 19:03   ` Lubomir Popov
2013-05-16 19:19     ` menon.nishanth at gmail.com
2013-05-16 20:14       ` Lubomir Popov
2013-05-16 20:45         ` menon.nishanth at gmail.com

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=5193A101.80002@mm-sol.com \
    --to=lpopov@mm-sol.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.