if (rdev->constraints->always_on)
rdev->use_count++;
} else if (rdev->desc->off_on_delay) {
- rdev->last_off_jiffy = jiffies;
+ rdev->last_off = ktime_get();
}
print_constraints(rdev);
trace_regulator_enable(rdev_get_name(rdev));
- if (rdev->desc->off_on_delay) {
+ if (rdev->desc->off_on_delay && rdev->last_off) {
/* if needed, keep a distance of off_on_delay from last time
* this regulator was disabled.
*/
- unsigned long start_jiffy = jiffies;
- unsigned long intended, max_delay, remaining;
-
- max_delay = usecs_to_jiffies(rdev->desc->off_on_delay);
- intended = rdev->last_off_jiffy + max_delay;
-
- if (time_before(start_jiffy, intended)) {
- /* calc remaining jiffies to deal with one-time
- * timer wrapping.
- * in case of multiple timer wrapping, either it can be
- * detected by out-of-range remaining, or it cannot be
- * detected and we get a penalty of
- * _regulator_enable_delay().
- */
- remaining = intended - start_jiffy;
- if (remaining <= max_delay)
- _regulator_enable_delay(
- jiffies_to_usecs(remaining));
- }
+ ktime_t end = ktime_add_us(rdev->last_off, rdev->desc->off_on_delay);
+ s64 remaining = ktime_us_delta(end, ktime_get());
+
+ if (remaining > 0)
+ _regulator_enable_delay(remaining);
}
if (rdev->ena_pin) {
return ret;
}
- /* cares about last_off_jiffy only if off_on_delay is required by
- * device.
- */
if (rdev->desc->off_on_delay)
- rdev->last_off_jiffy = jiffies;
+ rdev->last_off = ktime_get();
trace_regulator_disable_complete(rdev_get_name(rdev));