From patchwork Fri Mar 10 22:40:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 737602 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3vg2Kq6Ccrz9s86 for ; Sat, 11 Mar 2017 09:41:02 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 2E5E9C21C66; Fri, 10 Mar 2017 22:40:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A52B8C21C3C; Fri, 10 Mar 2017 22:40:55 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 286DCC21C3C; Fri, 10 Mar 2017 22:40:54 +0000 (UTC) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.9]) by lists.denx.de (Postfix) with ESMTPS id C46B3C21C39 for ; Fri, 10 Mar 2017 22:40:53 +0000 (UTC) Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3vg2Kd1FPzz3hjdd; Fri, 10 Mar 2017 23:40:53 +0100 (CET) Received: from localhost (dynscan01.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3vg2Kc72phz3jgYr; Fri, 10 Mar 2017 23:40:52 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan01.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id pfX53oltd4Yv; Fri, 10 Mar 2017 23:40:50 +0100 (CET) X-Auth-Info: y78Ko6uhsS4ZMYdW+AI8g/07cCgAeqsi4ENIFYlayOs= Received: from localhost.localdomain (89-77-92-62.dynamic.chello.pl [89.77.92.62]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Fri, 10 Mar 2017 23:40:50 +0100 (CET) From: Lukasz Majewski To: u-boot@lists.denx.de, Tom Rini Date: Fri, 10 Mar 2017 23:40:27 +0100 Message-Id: <1489185627-13467-1-git-send-email-lukma@denx.de> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Cc: Stefan Agner Subject: [U-Boot] [PATCH] PMIC: TI: TPS65903X errata (SLIA087) code X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- drivers/power/palmas.c | 110 +++++++++++++++++++++++++++++++++++++++++++++ drivers/power/pmic/Kconfig | 8 ++++ include/palmas.h | 21 +++++++++ 3 files changed, 139 insertions(+) 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 */