staging: hikey9xx: hi6421v600-regulator: fix delay logic
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 21 Jan 2021 07:18:12 +0000 (08:18 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 26 Jan 2021 17:52:54 +0000 (18:52 +0100)
The original driver, which can be seen at
commit 42f24d9d446a ("staging: regulator: add a regulator driver for HiSilicon 6421v600 SPMI PMIC")
had a complex logic to ensure that there won't be multiple power
enable/disable commands running at the same time. At the original
logic, it were ensured that:

- a next power up/down would wait for at least the on/off period;
- an extra delay would be granted. It turns that such extra delay
  has a value of zero, but it was relying on gettimeofday()
  call, which can take some time.

This was later simplified, but there are still some possible
issues. In order to avoid that, let's simply add a delay
to wait for the power up line to stabilize after powering up
a device.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Link: https://lore.kernel.org/r/6733dac9813ba6688def404142cb7b964accf758.1611212783.git.mchehab+huawei@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/hikey9xx/hi6421v600-regulator.c
include/linux/mfd/hi6421-spmi-pmic.h

index 5e78eeb..e5a492e 100644 (file)
@@ -113,14 +113,15 @@ static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev)
 
        /* cannot enable more than one regulator at one time */
        mutex_lock(&sreg->enable_mutex);
-       usleep_range(HISI_REGS_ENA_PROTECT_TIME,
-                    HISI_REGS_ENA_PROTECT_TIME + 1000);
 
        /* set enable register */
        ret = hi6421_spmi_pmic_rmw(pmic, rdev->desc->enable_reg,
                                   rdev->desc->enable_mask,
                                   rdev->desc->enable_mask);
 
+       /* Avoid powering up multiple devices at the same time */
+       usleep_range(rdev->desc->off_on_delay, rdev->desc->off_on_delay + 60);
+
        mutex_unlock(&sreg->enable_mutex);
 
        return ret;
index 2c8896f..0c22146 100644 (file)
@@ -13,7 +13,6 @@
 
 #include <linux/irqdomain.h>
 
-#define HISI_REGS_ENA_PROTECT_TIME     (0)     /* in microseconds */
 #define HISI_ECO_MODE_ENABLE           (1)
 #define HISI_ECO_MODE_DISABLE          (0)