diff mbox

[U-Boot] PMIC: TI: TPS65903X errata (SLIA087) code

Message ID 1489185627-13467-1-git-send-email-lukma@denx.de
State Deferred
Delegated to: Jaehoon Chung
Headers show

Commit Message

Lukasz Majewski March 10, 2017, 10:40 p.m. UTC
This patch adds code, which comply with TPS65903X errata pseudocode
described in SLIA087 - "Guide to Using the GPADC in TPS65903x and
TPS6591x Devices".

It is enabled by proper Kconfig option, when TI's palmas PMIC support is
added.

The TI's e2e thread with test procedure description:
https://e2e.ti.com/support/power_management/pmu/f/200/p/579649/2130910#2130910

Signed-off-by: Lukasz Majewski <lukma@denx.de>
---
 drivers/power/palmas.c     | 110 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/power/pmic/Kconfig |   8 ++++
 include/palmas.h           |  21 +++++++++
 3 files changed, 139 insertions(+)

Comments

Tom Rini March 14, 2017, 1:22 p.m. UTC | #1
On Fri, Mar 10, 2017 at 11:40:27PM +0100, Lukasz Majewski wrote:

> This patch adds code, which comply with TPS65903X errata pseudocode
> described in SLIA087 - "Guide to Using the GPADC in TPS65903x and
> TPS6591x Devices".
> 
> It is enabled by proper Kconfig option, when TI's palmas PMIC support is
> added.
> 
> The TI's e2e thread with test procedure description:
> https://e2e.ti.com/support/power_management/pmu/f/200/p/579649/2130910#2130910
> 
> Signed-off-by: Lukasz Majewski <lukma@denx.de>

I assume you have hardware that also uses this, so please submit with it
as it's not clear to me when the errata function you add should be
called.  Thanks!

[snip]
> +config PMIC_TPS65903X_ERRATA
> +	bool "Enable TPS65903X errata (SLIA087)"
> +	depends on PMIC_PALMAS
> +	---help---

We just do 'help' normally and indent the text.
Lukasz Majewski March 15, 2017, 10:07 a.m. UTC | #2
On Tue, 14 Mar 2017 09:22:02 -0400
Tom Rini <trini@konsulko.com> wrote:

> On Fri, Mar 10, 2017 at 11:40:27PM +0100, Lukasz Majewski wrote:
> 
> > This patch adds code, which comply with TPS65903X errata pseudocode
> > described in SLIA087 - "Guide to Using the GPADC in TPS65903x and
> > TPS6591x Devices".
> > 
> > It is enabled by proper Kconfig option, when TI's palmas PMIC
> > support is added.
> > 
> > The TI's e2e thread with test procedure description:
> > https://e2e.ti.com/support/power_management/pmu/f/200/p/579649/2130910#2130910
> > 
> > Signed-off-by: Lukasz Majewski <lukma@denx.de>
> 
> I assume you have hardware that also uses this, so please submit with
> it as it's not clear to me when the errata function you add should be
> called. 

I'm working on AM57xx based system, which will utilize this.

I wanted to share it early, since it might take some time to make the
"devel" code suitable for ML.

Nonetheless, other TI boards can use those fixes if they use this type
of PMIC (TPS65903x) despite the lack of my board in ML.

> Thanks!
> 
> [snip]
> > +config PMIC_TPS65903X_ERRATA
> > +	bool "Enable TPS65903X errata (SLIA087)"
> > +	depends on PMIC_PALMAS
> > +	---help---
> 
> We just do 'help' normally and indent the text.
> 


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Tom Rini March 15, 2017, 1:35 p.m. UTC | #3
On Wed, Mar 15, 2017 at 11:07:34AM +0100, Lukasz Majewski wrote:
> On Tue, 14 Mar 2017 09:22:02 -0400
> Tom Rini <trini@konsulko.com> wrote:
> 
> > On Fri, Mar 10, 2017 at 11:40:27PM +0100, Lukasz Majewski wrote:
> > 
> > > This patch adds code, which comply with TPS65903X errata pseudocode
> > > described in SLIA087 - "Guide to Using the GPADC in TPS65903x and
> > > TPS6591x Devices".
> > > 
> > > It is enabled by proper Kconfig option, when TI's palmas PMIC
> > > support is added.
> > > 
> > > The TI's e2e thread with test procedure description:
> > > https://e2e.ti.com/support/power_management/pmu/f/200/p/579649/2130910#2130910
> > > 
> > > Signed-off-by: Lukasz Majewski <lukma@denx.de>
> > 
> > I assume you have hardware that also uses this, so please submit with
> > it as it's not clear to me when the errata function you add should be
> > called. 
> 
> I'm working on AM57xx based system, which will utilize this.
> 
> I wanted to share it early, since it might take some time to make the
> "devel" code suitable for ML.
> 
> Nonetheless, other TI boards can use those fixes if they use this type
> of PMIC (TPS65903x) despite the lack of my board in ML.

So, the am57xx EVMs, the dra7xx EVMs and the am57xx compulab SoM?  I
assume you have at least one of the TI EVMs, can you enable it there and
show how it would be used?  Is there a case where we would not want to
be enabling this errata?  Thanks!
Lukasz Majewski March 15, 2017, 2:23 p.m. UTC | #4
On Wed, 15 Mar 2017 09:35:29 -0400
Tom Rini <trini@konsulko.com> wrote:

> On Wed, Mar 15, 2017 at 11:07:34AM +0100, Lukasz Majewski wrote:
> > On Tue, 14 Mar 2017 09:22:02 -0400
> > Tom Rini <trini@konsulko.com> wrote:
> > 
> > > On Fri, Mar 10, 2017 at 11:40:27PM +0100, Lukasz Majewski wrote:
> > > 
> > > > This patch adds code, which comply with TPS65903X errata
> > > > pseudocode described in SLIA087 - "Guide to Using the GPADC in
> > > > TPS65903x and TPS6591x Devices".
> > > > 
> > > > It is enabled by proper Kconfig option, when TI's palmas PMIC
> > > > support is added.
> > > > 
> > > > The TI's e2e thread with test procedure description:
> > > > https://e2e.ti.com/support/power_management/pmu/f/200/p/579649/2130910#2130910
> > > > 
> > > > Signed-off-by: Lukasz Majewski <lukma@denx.de>
> > > 
> > > I assume you have hardware that also uses this, so please submit
> > > with it as it's not clear to me when the errata function you add
> > > should be called. 
> > 
> > I'm working on AM57xx based system, which will utilize this.
> > 
> > I wanted to share it early, since it might take some time to make
> > the "devel" code suitable for ML.
> > 
> > Nonetheless, other TI boards can use those fixes if they use this
> > type of PMIC (TPS65903x) despite the lack of my board in ML.
> 
> So, the am57xx EVMs, the dra7xx EVMs and the am57xx compulab SoM?

Yes, if they use this PMIC

> I
> assume you have at least one of the TI EVMs, can you enable it there
> and show how it would be used? 

I had one of them. Now I do have only my custom board(s).

> Is there a case where we would not
> want to be enabling this errata?  

This errata is about GPACD - General Purpose Analog Digital Converter
in PMIC. It is not critical for system booting, but can save some
high-level user's stress when enabled.

For example - he/she will not have to do "dummy" read to have correct
ADC values in the user space Linux program after booting.

> Thanks!
> 

I've added it to 

int board_late_init(void)
{
....
	ret = tps65903x_errata();
	if (ret)
		return ret;
....

}


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Lokesh Vutla March 16, 2017, 5:16 a.m. UTC | #5
Hi Lucas,

On Saturday 11 March 2017 04:10 AM, Lukasz Majewski wrote:
> This patch adds code, which comply with TPS65903X errata pseudocode
> described in SLIA087 - "Guide to Using the GPADC in TPS65903x and
> TPS6591x Devices".
> 
> It is enabled by proper Kconfig option, when TI's palmas PMIC support is
> added.
> 
> The TI's e2e thread with test procedure description:
> https://e2e.ti.com/support/power_management/pmu/f/200/p/579649/2130910#2130910

I could not understand the reason for why this is being done in U-Boot.
Can you explain a it more on this?

Thanks and regards,
Lokesh
Lukasz Majewski March 16, 2017, 5:49 a.m. UTC | #6
Hi Lokesh,

> Hi Lucas,
> 
> On Saturday 11 March 2017 04:10 AM, Lukasz Majewski wrote:
> > This patch adds code, which comply with TPS65903X errata pseudocode
> > described in SLIA087 - "Guide to Using the GPADC in TPS65903x and
> > TPS6591x Devices".
> > 
> > It is enabled by proper Kconfig option, when TI's palmas PMIC
> > support is added.
> > 
> > The TI's e2e thread with test procedure description:
> > https://e2e.ti.com/support/power_management/pmu/f/200/p/579649/2130910#2130910
> 
> I could not understand the reason for why this is being done in
> U-Boot. Can you explain a it more on this?

Just as a safety matter. Doing this for GPADC PMIC in u-boot avoids
"surprises" latter on - when the high level user wants to use the GPADC
results from the first measurement that he/she does (for example at
safety critical application).

The u-boot driver (as it touches it first) is responsible to give the
TPS65903x PMIC to latter boot stage as free from any known problems
(i.e erratas).

> 
> Thanks and regards,
> Lokesh


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Lokesh Vutla March 16, 2017, 10:47 a.m. UTC | #7
Hi Lucas,

On Thursday 16 March 2017 11:19 AM, Lukasz Majewski wrote:
> Hi Lokesh,
> 
>> Hi Lucas,
>>
>> On Saturday 11 March 2017 04:10 AM, Lukasz Majewski wrote:
>>> This patch adds code, which comply with TPS65903X errata pseudocode
>>> described in SLIA087 - "Guide to Using the GPADC in TPS65903x and
>>> TPS6591x Devices".
>>>
>>> It is enabled by proper Kconfig option, when TI's palmas PMIC
>>> support is added.
>>>
>>> The TI's e2e thread with test procedure description:
>>> https://e2e.ti.com/support/power_management/pmu/f/200/p/579649/2130910#2130910
>>
>> I could not understand the reason for why this is being done in
>> U-Boot. Can you explain a it more on this?
> 
> Just as a safety matter. Doing this for GPADC PMIC in u-boot avoids
> "surprises" latter on - when the high level user wants to use the GPADC
> results from the first measurement that he/she does (for example at
> safety critical application).
> 
> The u-boot driver (as it touches it first) is responsible to give the
> TPS65903x PMIC to latter boot stage as free from any known problems
> (i.e erratas).

okay. Patch as such looks good to me.

Thanks and regards,
Lokesh
diff mbox

Patch

diff --git a/drivers/power/palmas.c b/drivers/power/palmas.c
index 6430fe0..f5cc859 100644
--- a/drivers/power/palmas.c
+++ b/drivers/power/palmas.c
@@ -23,6 +23,116 @@  void palmas_init_settings(void)
 #endif
 }
 
+#ifdef CONFIG_PMIC_TPS65903X_ERRATA
+/*
+ * This errata code follows the "Workaround for known issues"
+ * -> SLIA087 – May 2015 (point 3.)
+ */
+static int tps65903x_errata_dummy_GPADC_conv(void)
+{
+	int ret, timeout = 100;
+	u16 temp = 0;
+	u8 val;
+
+	/* Unmask interrupt for GPADC_EOC_SW */
+	ret = palmas_i2c_read_u8(TPS65903X_CHIP_P2, INT3_MASK, &val);
+	val &= ~INT3_MASK_GPADC_EOC_SW;
+	ret |= palmas_i2c_write_u8(TPS65903X_CHIP_P2, INT3_MASK, val);
+
+	/* Enable software conversion and select channel 12 */
+	val = GPADC_SW_SELECT_CONV_EN | 0xC;
+	ret |= palmas_i2c_write_u8(TPS65903X_CHIP_P2, GPADC_SW_SELECT, val);
+
+	val |= GPADC_SW_SELECT_ST_CONV0;
+	ret |= palmas_i2c_write_u8(TPS65903X_CHIP_P2, GPADC_SW_SELECT, val);
+
+	/* Wait for any pending conversion to complete */
+	do {
+		val = 0;
+		ret |= palmas_i2c_read_u8(TPS65903X_CHIP_P2,
+						  GPADC_STATUS, &val);
+			udelay(10);
+	} while (!val && timeout--);
+
+	/* The "dummy" GPADC conversion is finished - read results */
+	ret |= palmas_i2c_read_u8(TPS65903X_CHIP_P2, GPADC_SW_CONV0_LSB, &val);
+	temp = val;
+	ret |= palmas_i2c_read_u8(TPS65903X_CHIP_P2, GPADC_SW_CONV0_MSB, &val);
+	temp |= (val << 8);
+
+	/*
+	 * Temperature conversion equation for tps65903x
+	 *
+	 * TEMP = ( ( ( ADC_Read_Data / 2^12) * 1.25 ) – 0.753V ) / 2.64 mV
+	 *
+	 * It might also happen that value 0x0 will be read - this is the
+	 * case when the "dummy" read is needed to have consecutive reads
+	 * from GPADC correct.
+	 */
+	debug("%s: on-die temperature (from channel 12): 0x%x\n",
+	      __func__, temp);
+
+	return ret;
+}
+
+static int tps65903x_errata_locked_GPADC(void)
+{
+	int ret, timeout = 100;
+	u8 val;
+
+	ret = palmas_i2c_read_u8(TPS65903X_CHIP_P2, GPADC_STUCK, &val);
+	if (val & GPADC_STUCK_STUCK) {
+		debug("%s: Recovering from Locked GPADC State!\n", __func__);
+
+		/* Make sure GPADC AUTO mode is disabled */
+		ret |= palmas_i2c_write_u8(TPS65903X_CHIP_P2, GPADC_AUTO_CTRL,
+					  0x00);
+
+		/* Enable flush operation */
+		ret |= palmas_i2c_write_u8(TPS65903X_CHIP_P2, GPADC_FLUSH_EN,
+					   GPADC_FLUSH_EN_FLUSH_EN);
+
+		/* Start the flush operation */
+		ret |= palmas_i2c_write_u8(TPS65903X_CHIP_P2, GPADC_FLUSH,
+					   GPADC_FLUSH_FLUSH);
+
+		/* Wait for flush operation to complete */
+		do {
+			val = 0;
+			ret |= palmas_i2c_read_u8(TPS65903X_CHIP_P2,
+						  GPADC_STUCK, &val);
+			udelay(10);
+		} while ((val & GPADC_STUCK_STUCK) && timeout--);
+
+		ret |= palmas_i2c_write_u8(TPS65903X_CHIP_P2, GPADC_FLUSH_EN,
+					   0x00);
+		ret |= palmas_i2c_write_u8(TPS65903X_CHIP_P2, GPADC_FLUSH,
+					   0x00);
+	}
+
+	return ret;
+}
+
+int tps65903x_errata(void)
+{
+	int ret;
+
+	debug("%s:\n", __func__);
+
+	ret = tps65903x_errata_dummy_GPADC_conv();
+	if (ret) {
+		error("tps65903x errata - dummy GPADC conversion failed!");
+		return ret;
+	}
+
+	ret = tps65903x_errata_locked_GPADC();
+	if (ret)
+		error("tps65903x errata - locked GPADC failed!");
+
+	return ret;
+}
+#endif
+
 int palmas_mmc1_poweron_ldo(void)
 {
 	u8 val = 0;
diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
index ce204b3..1400340 100644
--- a/drivers/power/pmic/Kconfig
+++ b/drivers/power/pmic/Kconfig
@@ -151,6 +151,14 @@  config PMIC_PALMAS
 	The PALMAS is a PMIC containing several LDOs, SMPS.
 	This driver binds the pmic children.
 
+config PMIC_TPS65903X_ERRATA
+	bool "Enable TPS65903X errata (SLIA087)"
+	depends on PMIC_PALMAS
+	---help---
+	Enable code providing errata (software workarounds for known issues)
+	for TPS65903X series of PMIC devices according to SLIA87 document
+	(Guide to Using the GPADC in TPS65903x and TPS6591x Devices).
+
 config PMIC_LP873X
 	bool "Enable driver for Texas Instruments LP873X PMIC"
 	depends on DM_PMIC
diff --git a/include/palmas.h b/include/palmas.h
index d202770..bbfab86 100644
--- a/include/palmas.h
+++ b/include/palmas.h
@@ -17,6 +17,7 @@ 
 
 /* TPS659038/39 */
 #define TPS65903X_CHIP_P1	0x58	/* Page 1 */
+#define TPS65903X_CHIP_P2	0x59	/* Page 2 */
 
 /* Page 1 registers (0x1XY translates to page 1, reg addr 0xXY): */
 
@@ -114,6 +115,25 @@ 
 /* Bit definition for SWOFF_COLDRST */
 #define SWOFF_COLDRST_RESET_IN  (1 << 3)
 
+/* GPADC - page 2 */
+#define GPADC_FLUSH             0xC2
+#define GPADC_FLUSH_FLUSH       (1 << 0)
+#define GPADC_AUTO_CTRL         0xC3
+#define GPADC_STATUS            0xC4
+#define GPADC_FLUSH_EN          0xC5
+#define GPADC_FLUSH_EN_FLUSH_EN (1 << 7)
+#define GPADC_STUCK             0xC7
+#define GPADC_STUCK_STUCK       (1 << 4)
+#define GPADC_SW_SELECT         0xCD
+#define GPADC_SW_SELECT_CONV_EN (1 << 7)
+#define GPADC_SW_SELECT_ST_CONV0 (1 << 4)
+#define GPADC_SW_CONV0_LSB      0xCE
+#define GPADC_SW_CONV0_MSB      0xCF
+
+/* INTx - page 2 */
+#define INT3_MASK               0x1B
+#define INT3_MASK_GPADC_EOC_SW  (1 << 2)
+
 /*
  * Functions to read and write from TPS659038/TWL6035/TWL6037
  * or other Palmas family of TI PMICs
@@ -134,5 +154,6 @@  int twl603x_mmc1_set_ldo9(u8 vsel);
 int twl603x_audio_power(u8 on);
 int twl603x_enable_bb_charge(u8 bb_fields);
 int palmas_enable_ss_ldo(void);
+int tps65903x_errata(void);
 
 #endif /* PALMAS_H */