Skip to content

Commit 59a06dc

Browse files
anna-marialxbroonie
authored andcommitted
regulator: core: Use fsleep() to get best sleep mechanism
_regulator_delay_helper() implements the recommondation of the outdated documentation which sleep mechanism should be used. There is already a function in place which does everything and also maps to reality called fsleep(). Use fsleep() directly. Cc: Liam Girdwood <lgirdwood@gmail.com> Cc: Mark Brown <broonie@kernel.org> Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Link: https://patch.msgid.link/20241014-devel-anna-maria-b4-timers-flseep-v3-11-dc8b907cb62f@linutronix.de Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent fceffbf commit 59a06dc

File tree

1 file changed

+4
-43
lines changed

1 file changed

+4
-43
lines changed

drivers/regulator/core.c

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,45 +2642,6 @@ static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable)
26422642
return 0;
26432643
}
26442644

2645-
/**
2646-
* _regulator_delay_helper - a delay helper function
2647-
* @delay: time to delay in microseconds
2648-
*
2649-
* Delay for the requested amount of time as per the guidelines in:
2650-
*
2651-
* Documentation/timers/timers-howto.rst
2652-
*
2653-
* The assumption here is that these regulator operations will never used in
2654-
* atomic context and therefore sleeping functions can be used.
2655-
*/
2656-
static void _regulator_delay_helper(unsigned int delay)
2657-
{
2658-
unsigned int ms = delay / 1000;
2659-
unsigned int us = delay % 1000;
2660-
2661-
if (ms > 0) {
2662-
/*
2663-
* For small enough values, handle super-millisecond
2664-
* delays in the usleep_range() call below.
2665-
*/
2666-
if (ms < 20)
2667-
us += ms * 1000;
2668-
else
2669-
msleep(ms);
2670-
}
2671-
2672-
/*
2673-
* Give the scheduler some room to coalesce with any other
2674-
* wakeup sources. For delays shorter than 10 us, don't even
2675-
* bother setting up high-resolution timers and just busy-
2676-
* loop.
2677-
*/
2678-
if (us >= 10)
2679-
usleep_range(us, us + 100);
2680-
else
2681-
udelay(us);
2682-
}
2683-
26842645
/**
26852646
* _regulator_check_status_enabled - check if regulator status can be
26862647
* interpreted as "regulator is enabled"
@@ -2733,7 +2694,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
27332694
s64 remaining = ktime_us_delta(end, ktime_get_boottime());
27342695

27352696
if (remaining > 0)
2736-
_regulator_delay_helper(remaining);
2697+
fsleep(remaining);
27372698
}
27382699

27392700
if (rdev->ena_pin) {
@@ -2767,7 +2728,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
27672728
int time_remaining = delay;
27682729

27692730
while (time_remaining > 0) {
2770-
_regulator_delay_helper(rdev->desc->poll_enabled_time);
2731+
fsleep(rdev->desc->poll_enabled_time);
27712732

27722733
if (rdev->desc->ops->get_status) {
27732734
ret = _regulator_check_status_enabled(rdev);
@@ -2786,7 +2747,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
27862747
return -ETIMEDOUT;
27872748
}
27882749
} else {
2789-
_regulator_delay_helper(delay);
2750+
fsleep(delay);
27902751
}
27912752

27922753
trace_regulator_enable_complete(rdev_get_name(rdev));
@@ -3730,7 +3691,7 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
37303691
}
37313692

37323693
/* Insert any necessary delays */
3733-
_regulator_delay_helper(delay);
3694+
fsleep(delay);
37343695

37353696
if (best_val >= 0) {
37363697
unsigned long data = best_val;

0 commit comments

Comments
 (0)