From 65e7bb2861def68ed82bf82c2e21819102e81991 Mon Sep 17 00:00:00 2001 From: Fenglin Wu Date: Wed, 25 May 2022 09:03:04 +0800 Subject: [PATCH] input: qcom-hv-haptics: ignore disabling hBoost when it's in open-loop When hBoost is working in open-loop mode, it's supposed to be used by other modules like the charger firmware and it shouldn't be turned off by haptics driver. Ignore turning on and off hBoost in such case. Change-Id: Id3eb2c37cf7316b4617872614cc2a7adc50d12d8 Signed-off-by: Fenglin Wu --- drivers/input/misc/qcom-hv-haptics.c | 53 ++++++++++++++++------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/drivers/input/misc/qcom-hv-haptics.c b/drivers/input/misc/qcom-hv-haptics.c index 0948a30c7577..8fc4bda5e2c4 100644 --- a/drivers/input/misc/qcom-hv-haptics.c +++ b/drivers/input/misc/qcom-hv-haptics.c @@ -1266,6 +1266,31 @@ static int haptics_set_direct_play(struct haptics_chip *chip, u8 amplitude) return rc; } +static bool is_boost_vreg_enabled_in_open_loop(struct haptics_chip *chip) +{ + int rc; + u8 val; + + if (is_haptics_external_powered(chip)) + return false; + + rc = haptics_read(chip, chip->hbst_addr_base, HAP_BOOST_VREG_EN_REG, &val, 1); + if (rc < 0) + return false; + + chip->hboost_enabled = (val & VREG_EN_BIT); + rc = haptics_read(chip, chip->hbst_addr_base, HAP_BOOST_HW_CTRL_FOLLOW_REG, &val, 1); + if (rc < 0) + return false; + + if (!(val & FOLLOW_HW_EN_BIT) && chip->hboost_enabled) { + dev_dbg(chip->dev, "HBoost is enabled in open loop condition\n"); + return true; + } + + return false; +} + #define PBS_ARG_REG 0x42 #define HAP_VREG_ON_VAL 0x1 #define HAP_VREG_OFF_VAL 0x2 @@ -1287,6 +1312,12 @@ static int haptics_boost_vreg_enable(struct haptics_chip *chip, bool en) return 0; } + if (is_boost_vreg_enabled_in_open_loop(chip)) { + dev_dbg(chip->dev, "Ignore %s hBoost while it's enabled in open-loop mode\n", + en ? "enabling" : "disabling"); + return 0; + } + if (chip->hboost_enabled == en) return 0; @@ -1327,28 +1358,6 @@ static bool is_swr_play_enabled(struct haptics_chip *chip) return false; } -static bool is_boost_vreg_enabled_in_open_loop(struct haptics_chip *chip) -{ - int rc; - u8 val; - - if (is_haptics_external_powered(chip)) - return false; - - rc = haptics_read(chip, chip->hbst_addr_base, - HAP_BOOST_HW_CTRL_FOLLOW_REG, &val, 1); - if (!rc && !(val & FOLLOW_HW_EN_BIT)) { - rc = haptics_read(chip, chip->hbst_addr_base, - HAP_BOOST_VREG_EN_REG, &val, 1); - if (!rc && (val & VREG_EN_BIT)) { - dev_dbg(chip->dev, "HBoost is enabled in open loop condition\n"); - return true; - } - } - - return false; -} - #define HBOOST_WAIT_READY_COUNT 100 #define HBOOST_WAIT_READY_INTERVAL_US 200 static int haptics_wait_hboost_ready(struct haptics_chip *chip)