From a2f88b40c62ccdbf3c9ab285bf07164682afe65c Mon Sep 17 00:00:00 2001 From: Sebastiano Barezzi Date: Tue, 15 Nov 2022 16:58:05 +0100 Subject: [PATCH] drivers: regulator: Import Xiaomi changes * From dagu-s-oss Change-Id: I9e27aed218eb449ee481cece50eb1cea474fd298 --- drivers/regulator/Kconfig | 5 +++ drivers/regulator/qcom_pm8008-regulator.c | 41 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 97197e43fb1f..3554b72ff64f 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -1177,5 +1177,10 @@ config REGULATOR_PM8008 This driver controls PM8008 PMIC chip and the voltage regulators found in Qualcomm Technologies Inc. PM8008 PMIC. + +config I2C_RETRY + bool "Stub Regulator" + help + This help control I2C retry functions endif diff --git a/drivers/regulator/qcom_pm8008-regulator.c b/drivers/regulator/qcom_pm8008-regulator.c index 1fa15a9aacf1..d712b9aa51a5 100644 --- a/drivers/regulator/qcom_pm8008-regulator.c +++ b/drivers/regulator/qcom_pm8008-regulator.c @@ -70,6 +70,10 @@ #define MAX_REG_NAME 20 #define PM8008_MAX_LDO 7 +#ifdef CONFIG_I2C_RETRY +#define MAX_RETRY_TIME 5 +#endif + enum pmic_subtype { PM8008_SUBTYPE, PM8010_SUBTYPE, @@ -167,10 +171,21 @@ static int pm8008_read(struct regmap *regmap, u16 reg, u8 *val, int count) { int rc; +#ifdef CONFIG_I2C_RETRY + int retry = 0; + do { + rc = regmap_bulk_read(regmap, reg, val, count); + } while (rc < 0 && retry++ < MAX_RETRY_TIME); + if (retry > 0) + pr_err("failed to read 0x%04x retry time %d success\n", reg, retry); + if (rc < 0) + pr_err("failed to read 0x%04x\n", reg); +#else rc = regmap_bulk_read(regmap, reg, val, count); if (rc < 0) pr_err("failed to read 0x%04x\n", reg); +#endif return rc; } @@ -179,11 +194,23 @@ static int pm8008_write(struct regmap *regmap, u16 reg, const u8 *val, { int rc; +#ifdef CONFIG_I2C_RETRY + int retry = 0; + pr_debug("Writing 0x%02x to 0x%04x\n", val, reg); + do { + rc = regmap_bulk_write(regmap, reg, val, count); + } while (rc < 0 && retry++ < MAX_RETRY_TIME); + if (retry > 0) + pr_err("failed to write 0x%04x retry time %d success\n", reg, retry); + if (rc < 0) + pr_err("failed to write 0x%04x\n", reg); +#else pr_debug("Writing 0x%02x to 0x%04x\n", val, reg); rc = regmap_bulk_write(regmap, reg, val, count); if (rc < 0) pr_err("failed to write 0x%04x\n", reg); +#endif return rc; } @@ -192,12 +219,26 @@ static int pm8008_masked_write(struct regmap *regmap, u16 reg, u8 mask, { int rc; +#ifdef CONFIG_I2C_RETRY + int retry = 0; + pr_debug("Writing 0x%02x to 0x%04x with mask 0x%02x\n", val, reg, mask); + do { + rc = regmap_update_bits(regmap, reg, mask, val); + } while (rc < 0 && retry++ < MAX_RETRY_TIME); + if (retry > 0) + pr_err("failed to write 0x%02x to 0x%04x with mask 0x%02x retry time %d success\n", + val, reg, retry); + if (rc < 0) + pr_err("failed to write 0x%02x to 0x%04x with mask 0x%02x\n", + val, reg, mask); +#else pr_debug("Writing 0x%02x to 0x%04x with mask 0x%02x\n", val, reg, mask); rc = regmap_update_bits(regmap, reg, mask, val); if (rc < 0) pr_err("failed to write 0x%02x to 0x%04x with mask 0x%02x\n", val, reg, mask); +#endif return rc; }