blob: a044cb034ed0c4c343a1af40f637a2d2a7b01691 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Thomas Choufb798b12015-10-09 13:46:34 +08002/*
3 * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
Thomas Choufb798b12015-10-09 13:46:34 +08004 */
5
6#ifndef _TIMER_H_
7#define _TIMER_H_
8
Sean Andersonb7109652020-10-07 14:37:43 -04009/**
10 * dm_timer_init() - initialize a timer for time keeping. On success
Mugunthan V N6f89d042016-01-16 21:33:58 +053011 * initializes gd->timer so that lib/timer can use it for future
12 * referrence.
13 *
Sean Andersonb7109652020-10-07 14:37:43 -040014 * Return: 0 on success or error number
Mugunthan V N6f89d042016-01-16 21:33:58 +053015 */
16int dm_timer_init(void);
17
Sean Anderson738ff532020-09-28 10:52:22 -040018/**
19 * timer_timebase_fallback() - Helper for timers using timebase fallback
20 * @dev: A timer partially-probed timer device
21 *
22 * This is a helper function designed for timers which need to fall back on the
23 * cpu's timebase. This function is designed to be called during the driver's
24 * probe(). If there is a clocks or clock-frequency property in the timer's
25 * binding, then it will be used. Otherwise, the timebase of the current cpu
26 * will be used. This is initialized by the cpu driver, and usually gotten from
27 * ``/cpus/timebase-frequency`` or ``/cpus/cpu@X/timebase-frequency``.
28 *
29 * Return: 0 if OK, or negative error code on failure
30 */
31int timer_timebase_fallback(struct udevice *dev);
32
Sean Andersonb7109652020-10-07 14:37:43 -040033/**
34 * timer_conv_64() - convert 32-bit counter value to 64-bit
Bin Mengab841b62015-11-24 13:31:17 -070035 * @count: 32-bit counter value
Sean Andersonb7109652020-10-07 14:37:43 -040036 *
37 * Return: 64-bit counter value
Bin Mengab841b62015-11-24 13:31:17 -070038 */
39u64 timer_conv_64(u32 count);
40
Sean Andersonb7109652020-10-07 14:37:43 -040041/**
42 * timer_get_count() - Get the current timer count
Bin Meng8a7b8642015-11-13 00:11:14 -080043 * @dev: The timer device
Thomas Choufb798b12015-10-09 13:46:34 +080044 * @count: pointer that returns the current timer count
Sean Andersonb7109652020-10-07 14:37:43 -040045 *
46 * Return: 0 if OK, -ve on error
Thomas Choufb798b12015-10-09 13:46:34 +080047 */
Bin Mengab841b62015-11-24 13:31:17 -070048int timer_get_count(struct udevice *dev, u64 *count);
Bin Meng8a7b8642015-11-13 00:11:14 -080049
Sean Andersonb7109652020-10-07 14:37:43 -040050/**
51 * timer_get_rate() - Get the timer input clock frequency
Bin Meng8a7b8642015-11-13 00:11:14 -080052 * @dev: The timer device
Sean Andersonb7109652020-10-07 14:37:43 -040053 *
54 * Return: the timer input clock frequency
Thomas Choufb798b12015-10-09 13:46:34 +080055 */
56unsigned long timer_get_rate(struct udevice *dev);
57
Sean Andersonb7109652020-10-07 14:37:43 -040058/**
Bin Meng8a7b8642015-11-13 00:11:14 -080059 * struct timer_ops - Driver model timer operations
Thomas Choufb798b12015-10-09 13:46:34 +080060 *
Bin Meng8a7b8642015-11-13 00:11:14 -080061 * The uclass interface is implemented by all timer devices which use
Thomas Choufb798b12015-10-09 13:46:34 +080062 * driver model.
63 */
64struct timer_ops {
Sean Andersonb7109652020-10-07 14:37:43 -040065 /**
66 * @get_count: Get the current timer count
Thomas Choufb798b12015-10-09 13:46:34 +080067 *
Bin Meng8a7b8642015-11-13 00:11:14 -080068 * @dev: The timer device
Sean Andersonb7109652020-10-07 14:37:43 -040069 *
Sean Anderson947fc2d2020-10-07 14:37:44 -040070 * This function may be called at any time after the driver is probed.
71 * All necessary initialization must be completed by the time probe()
72 * returns. The count returned by this functions should be monotonic.
73 * This function must succeed.
Sean Andersonb7109652020-10-07 14:37:43 -040074 *
Sean Anderson947fc2d2020-10-07 14:37:44 -040075 * Return: The current 64-bit timer count
Thomas Choufb798b12015-10-09 13:46:34 +080076 */
Sean Anderson947fc2d2020-10-07 14:37:44 -040077 u64 (*get_count)(struct udevice *dev);
Thomas Choufb798b12015-10-09 13:46:34 +080078};
79
Sean Andersonb7109652020-10-07 14:37:43 -040080/**
Thomas Choufb798b12015-10-09 13:46:34 +080081 * struct timer_dev_priv - information about a device used by the uclass
82 *
83 * @clock_rate: the timer input clock frequency
84 */
85struct timer_dev_priv {
86 unsigned long clock_rate;
87};
88
Simon Glass32f6c172016-02-24 09:14:49 -070089/**
90 * timer_early_get_count() - Implement timer_get_count() before driver model
91 *
Sean Andersonb7109652020-10-07 14:37:43 -040092 * If ``CONFIG_TIMER_EARLY`` is enabled, this function wil be called to return
Simon Glass32f6c172016-02-24 09:14:49 -070093 * the current timer value before the proper driver model timer is ready.
94 * It should be implemented by one of the timer values. This is mostly useful
95 * for tracing.
96 */
97u64 timer_early_get_count(void);
98
99/**
100 * timer_early_get_rate() - Get the timer rate before driver model
101 *
Sean Andersonb7109652020-10-07 14:37:43 -0400102 * If ``CONFIG_TIMER_EARLY`` is enabled, this function wil be called to return
Simon Glass32f6c172016-02-24 09:14:49 -0700103 * the current timer rate in Hz before the proper driver model timer is ready.
104 * It should be implemented by one of the timer values. This is mostly useful
105 * for tracing. This corresponds to the clock_rate value in struct
106 * timer_dev_priv.
107 */
108unsigned long timer_early_get_rate(void);
109
Thomas Choufb798b12015-10-09 13:46:34 +0800110#endif /* _TIMER_H_ */