2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2016-12-27 15:36:00 +00:00
|
|
|
|
|
|
|
#ifndef _TIME_H
|
|
|
|
#define _TIME_H
|
|
|
|
|
2016-12-27 15:36:02 +00:00
|
|
|
#include <linux/typecheck.h>
|
2019-06-02 19:02:10 +00:00
|
|
|
#include <linux/types.h>
|
2016-12-27 15:36:02 +00:00
|
|
|
|
2019-12-28 17:44:59 +00:00
|
|
|
ulong get_tbclk(void);
|
|
|
|
|
2016-12-27 15:36:00 +00:00
|
|
|
unsigned long get_timer(unsigned long base);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the current value of a monotonically increasing microsecond timer.
|
|
|
|
* Granularity may be larger than 1us if hardware does not support this.
|
|
|
|
*/
|
|
|
|
unsigned long timer_get_us(void);
|
2019-10-15 20:43:41 +00:00
|
|
|
uint64_t get_timer_us(uint64_t base);
|
2016-12-27 15:36:00 +00:00
|
|
|
|
2020-07-10 00:43:14 +00:00
|
|
|
/**
|
|
|
|
* get_timer_us_long() - Get the number of elapsed microseconds
|
|
|
|
*
|
|
|
|
* This uses 32-bit arithmetic on 32-bit machines, which is enough to handle
|
|
|
|
* delays of over an hour. For 64-bit machines it uses a 64-bit value.
|
|
|
|
*
|
|
|
|
*@base: Base time to consider
|
2022-01-19 17:05:50 +00:00
|
|
|
*Return: elapsed time since @base
|
2020-07-10 00:43:14 +00:00
|
|
|
*/
|
|
|
|
unsigned long get_timer_us_long(unsigned long base);
|
|
|
|
|
regmap: fix regmap_read_poll_timeout warning about sandbox_timer_add_offset
When fixing sandbox test for regmap_read_poll_timeout(), the
sandbox_timer_add_offset was introduced but only defined in sandbox code
thus generating warnings when used out of sandbox :
include/regmap.h:289:2: note: in expansion of macro 'regmap_read_poll_timeout_test'
regmap_read_poll_timeout_test(map, addr, val, cond, sleep_us, \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/spi/meson_spifc.c:169:8: note: in expansion of macro 'regmap_read_poll_timeout'
ret = regmap_read_poll_timeout(spifc->regmap, REG_SLAVE, data,
^~~~~~~~~~~~~~~~~~~~~~~~
drivers/spi/meson_spifc.c: In function 'meson_spifc_txrx':
include/regmap.h:277:4: warning: implicit declaration of function 'sandbox_timer_add_offset' [-Wimplicit-function-declaration]
This fix adds a timer_test_add_offset() only defined in sandbox, and
renames the previous sandbox_timer_add_offset() to it.
Cc: Simon Glass <sjg@chromium.org>
Reported-by: Tom Rini <trini@konsulko.com>
Fixes: df9cf1cc08 ("test: dm: regmap: Fix the long test delay")
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2019-04-11 15:01:23 +00:00
|
|
|
/*
|
|
|
|
* timer_test_add_offset()
|
|
|
|
*
|
|
|
|
* Allow tests to add to the time reported through lib/time.c functions
|
|
|
|
* offset: number of milliseconds to advance the system time
|
|
|
|
*/
|
|
|
|
void timer_test_add_offset(unsigned long offset);
|
|
|
|
|
2019-06-02 19:02:10 +00:00
|
|
|
/**
|
|
|
|
* usec_to_tick() - convert microseconds to clock ticks
|
|
|
|
*
|
|
|
|
* @usec: duration in microseconds
|
|
|
|
* Return: duration in clock ticks
|
|
|
|
*/
|
|
|
|
uint64_t usec_to_tick(unsigned long usec);
|
|
|
|
|
2016-12-27 15:36:02 +00:00
|
|
|
/*
|
|
|
|
* These inlines deal with timer wrapping correctly. You are
|
|
|
|
* strongly encouraged to use them
|
|
|
|
* 1. Because people otherwise forget
|
|
|
|
* 2. Because if the timer wrap changes in future you won't have to
|
|
|
|
* alter your driver code.
|
|
|
|
*
|
|
|
|
* time_after(a,b) returns true if the time a is after time b.
|
|
|
|
*
|
|
|
|
* Do this with "<0" and ">=0" to only test the sign of the result. A
|
|
|
|
* good compiler would generate better code (and a really good compiler
|
|
|
|
* wouldn't care). Gcc is currently neither.
|
|
|
|
*/
|
|
|
|
#define time_after(a,b) \
|
|
|
|
(typecheck(unsigned long, a) && \
|
|
|
|
typecheck(unsigned long, b) && \
|
|
|
|
((long)((b) - (a)) < 0))
|
|
|
|
#define time_before(a,b) time_after(b,a)
|
|
|
|
|
|
|
|
#define time_after_eq(a,b) \
|
|
|
|
(typecheck(unsigned long, a) && \
|
|
|
|
typecheck(unsigned long, b) && \
|
|
|
|
((long)((a) - (b)) >= 0))
|
|
|
|
#define time_before_eq(a,b) time_after_eq(b,a)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate whether a is in the range of [b, c].
|
|
|
|
*/
|
|
|
|
#define time_in_range(a,b,c) \
|
|
|
|
(time_after_eq(a,b) && \
|
|
|
|
time_before_eq(a,c))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate whether a is in the range of [b, c).
|
|
|
|
*/
|
|
|
|
#define time_in_range_open(a,b,c) \
|
|
|
|
(time_after_eq(a,b) && \
|
|
|
|
time_before(a,c))
|
|
|
|
|
2022-09-02 11:57:47 +00:00
|
|
|
/* Same as above, but does so with platform independent 64bit types.
|
|
|
|
* These must be used when utilizing jiffies_64 (i.e. return value of
|
|
|
|
* get_jiffies_64() */
|
|
|
|
#define time_after64(a,b) \
|
|
|
|
(typecheck(__u64, a) && \
|
|
|
|
typecheck(__u64, b) && \
|
|
|
|
((__s64)((b) - (a)) < 0))
|
|
|
|
#define time_before64(a,b) time_after64(b,a)
|
|
|
|
|
|
|
|
#define time_after_eq64(a,b) \
|
|
|
|
(typecheck(__u64, a) && \
|
|
|
|
typecheck(__u64, b) && \
|
|
|
|
((__s64)((a) - (b)) >= 0))
|
|
|
|
#define time_before_eq64(a,b) time_after_eq64(b,a)
|
|
|
|
|
|
|
|
#define time_in_range64(a, b, c) \
|
|
|
|
(time_after_eq64(a, b) && \
|
|
|
|
time_before_eq64(a, c))
|
|
|
|
|
2019-11-14 19:57:26 +00:00
|
|
|
/**
|
|
|
|
* usec2ticks() - Convert microseconds to internal ticks
|
|
|
|
*
|
|
|
|
* @usec: Value of microseconds to convert
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: Corresponding internal ticks value, calculated using get_tbclk()
|
2019-11-14 19:57:26 +00:00
|
|
|
*/
|
|
|
|
ulong usec2ticks(unsigned long usec);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ticks2usec() - Convert internal ticks to microseconds
|
|
|
|
*
|
|
|
|
* @ticks: Value of ticks to convert
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: Corresponding microseconds value, calculated using get_tbclk()
|
2019-11-14 19:57:26 +00:00
|
|
|
*/
|
|
|
|
ulong ticks2usec(unsigned long ticks);
|
|
|
|
|
2019-11-14 19:57:27 +00:00
|
|
|
/**
|
|
|
|
* wait_ticks() - waits a given number of ticks
|
|
|
|
*
|
|
|
|
* This is an internal function typically used to implement udelay() and
|
|
|
|
* similar. Normally you should use udelay() or mdelay() instead.
|
|
|
|
*
|
|
|
|
* @ticks: Number of ticks to wait
|
|
|
|
*/
|
|
|
|
void wait_ticks(unsigned long ticks);
|
|
|
|
|
2019-11-14 19:57:29 +00:00
|
|
|
/**
|
|
|
|
* timer_get_us() - Get monotonic microsecond timer
|
|
|
|
*
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: value of monotonic microsecond timer
|
2019-11-14 19:57:29 +00:00
|
|
|
*/
|
|
|
|
unsigned long timer_get_us(void);
|
|
|
|
|
2019-11-14 19:57:30 +00:00
|
|
|
/**
|
|
|
|
* get_ticks() - Get the current tick value
|
|
|
|
*
|
|
|
|
* This is an internal value used by the timer on the system. Ticks increase
|
|
|
|
* monotonically at the rate given by get_tbclk().
|
|
|
|
*
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: current tick value
|
2019-11-14 19:57:30 +00:00
|
|
|
*/
|
|
|
|
uint64_t get_ticks(void);
|
|
|
|
|
2016-12-27 15:36:00 +00:00
|
|
|
#endif /* _TIME_H */
|