lkml.org 
[lkml]   [2020]   [Aug]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 25/44] staging: regulator: hi6421v600-regulator: port it to upstream
Date
The driver was originally written for Kernel 4.9. It needs to
be ported to upstream:

- Got rid of timeval;
- Removed a bogus dependency;
- Did cleanups at the header file.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
.../staging/hikey9xx/hi6421v600-regulator.c | 34 +++----------------
1 file changed, 5 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c
index 7bc0ae27b110..904cb64b1dcd 100644
--- a/drivers/staging/hikey9xx/hi6421v600-regulator.c
+++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c
@@ -49,7 +49,6 @@ struct hisi_regulator_register_info {
struct hisi_regulator {
const char *name;
struct hisi_regulator_register_info register_info;
- struct timeval last_off_time;
u32 off_on_delay;
u32 eco_uA;
struct regulator_desc rdesc;
@@ -57,8 +56,6 @@ struct hisi_regulator {
};

static DEFINE_MUTEX(enable_mutex);
-struct timeval last_enabled;
-

static inline struct hisi_pmic *rdev_to_pmic(struct regulator_dev *dev)
{
@@ -72,27 +69,6 @@ static inline struct hisi_pmic *rdev_to_pmic(struct regulator_dev *dev)
/* helper function to ensure when it returns it is at least 'delay_us'
* microseconds after 'since'.
*/
-static void ensured_time_after(struct timeval since, u32 delay_us)
-{
- struct timeval now;
- u64 elapsed_ns64, delay_ns64;
- u32 actual_us32;
-
- delay_ns64 = delay_us * NSEC_PER_USEC;
- do_gettimeofday(&now);
- elapsed_ns64 = timeval_to_ns(&now) - timeval_to_ns(&since);
- if (delay_ns64 > elapsed_ns64) {
- actual_us32 = ((u32)(delay_ns64 - elapsed_ns64) /
- NSEC_PER_USEC);
- if (actual_us32 >= 1000) {
- mdelay(actual_us32 / 1000); /*lint !e647 */
- udelay(actual_us32 % 1000);
- } else if (actual_us32 > 0) {
- udelay(actual_us32);
- }
- }
- return;
-}

static int hisi_regulator_is_enabled(struct regulator_dev *dev)
{
@@ -113,13 +89,16 @@ static int hisi_regulator_enable(struct regulator_dev *dev)
struct hisi_pmic *pmic = rdev_to_pmic(dev);

/* keep a distance of off_on_delay from last time disabled */
- ensured_time_after(sreg->last_off_time, sreg->off_on_delay);
+ usleep_range(sreg->off_on_delay, sreg->off_on_delay + 1000);

pr_debug("<[%s]: off_on_delay=%dus>\n", __func__, sreg->off_on_delay);

/* cannot enable more than one regulator at one time */
mutex_lock(&enable_mutex);
- ensured_time_after(last_enabled, HISI_REGS_ENA_PROTECT_TIME);
+ usleep_range(HISI_REGS_ENA_PROTECT_TIME,
+ HISI_REGS_ENA_PROTECT_TIME + 1000);
+
+

/* set enable register */
hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg,
@@ -128,7 +107,6 @@ static int hisi_regulator_enable(struct regulator_dev *dev)
pr_debug("<[%s]: ctrl_reg=0x%x,enable_mask=0x%x>\n", __func__, sreg->register_info.ctrl_reg,\
sreg->register_info.enable_mask);

- do_gettimeofday(&last_enabled);
mutex_unlock(&enable_mutex);

return 0;
@@ -143,8 +121,6 @@ static int hisi_regulator_disable(struct regulator_dev *dev)
hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg,
sreg->register_info.enable_mask, 0);

- do_gettimeofday(&sreg->last_off_time);
-
return 0;
}

--
2.26.2
\
 
 \ /
  Last update: 2020-08-12 17:59    [W:0.386 / U:0.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site