blob: 8b9fa51c53d3b22c71c4551ee9f299d0d948ccc2 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Thomas Chouc8a7ba92015-10-09 13:46:34 +08002/*
3 * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
Thomas Chouc8a7ba92015-10-09 13:46:34 +08004 */
5
6#ifndef _TIMER_H_
7#define _TIMER_H_
8
9/*
Mugunthan V Nc8336972016-01-16 21:33:58 +053010 * dm_timer_init - initialize a timer for time keeping. On success
11 * initializes gd->timer so that lib/timer can use it for future
12 * referrence.
13 *
14 * @return - 0 on success or error number
15 */
16int dm_timer_init(void);
17
Sean Anderson35761212020-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
Mugunthan V Nc8336972016-01-16 21:33:58 +053033/*
Bin Meng9ca07eb2015-11-24 13:31:17 -070034 * timer_conv_64 - convert 32-bit counter value to 64-bit
35 *
36 * @count: 32-bit counter value
37 * @return: 64-bit counter value
38 */
39u64 timer_conv_64(u32 count);
40
41/*
Thomas Chouc8a7ba92015-10-09 13:46:34 +080042 * Get the current timer count
43 *
Bin Meng435ae762015-11-13 00:11:14 -080044 * @dev: The timer device
Thomas Chouc8a7ba92015-10-09 13:46:34 +080045 * @count: pointer that returns the current timer count
46 * @return: 0 if OK, -ve on error
47 */
Bin Meng9ca07eb2015-11-24 13:31:17 -070048int timer_get_count(struct udevice *dev, u64 *count);
Bin Meng435ae762015-11-13 00:11:14 -080049
Thomas Chouc8a7ba92015-10-09 13:46:34 +080050/*
51 * Get the timer input clock frequency
52 *
Bin Meng435ae762015-11-13 00:11:14 -080053 * @dev: The timer device
Thomas Chouc8a7ba92015-10-09 13:46:34 +080054 * @return: the timer input clock frequency
55 */
56unsigned long timer_get_rate(struct udevice *dev);
57
58/*
Bin Meng435ae762015-11-13 00:11:14 -080059 * struct timer_ops - Driver model timer operations
Thomas Chouc8a7ba92015-10-09 13:46:34 +080060 *
Bin Meng435ae762015-11-13 00:11:14 -080061 * The uclass interface is implemented by all timer devices which use
Thomas Chouc8a7ba92015-10-09 13:46:34 +080062 * driver model.
63 */
64struct timer_ops {
65 /*
66 * Get the current timer count
67 *
Bin Meng435ae762015-11-13 00:11:14 -080068 * @dev: The timer device
Bin Meng9ca07eb2015-11-24 13:31:17 -070069 * @count: pointer that returns the current 64-bit timer count
Thomas Chouc8a7ba92015-10-09 13:46:34 +080070 * @return: 0 if OK, -ve on error
71 */
Bin Meng9ca07eb2015-11-24 13:31:17 -070072 int (*get_count)(struct udevice *dev, u64 *count);
Thomas Chouc8a7ba92015-10-09 13:46:34 +080073};
74
75/*
76 * struct timer_dev_priv - information about a device used by the uclass
77 *
78 * @clock_rate: the timer input clock frequency
79 */
80struct timer_dev_priv {
81 unsigned long clock_rate;
82};
83
Simon Glassc95fec32016-02-24 09:14:49 -070084/**
85 * timer_early_get_count() - Implement timer_get_count() before driver model
86 *
87 * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
88 * the current timer value before the proper driver model timer is ready.
89 * It should be implemented by one of the timer values. This is mostly useful
90 * for tracing.
91 */
92u64 timer_early_get_count(void);
93
94/**
95 * timer_early_get_rate() - Get the timer rate before driver model
96 *
97 * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
98 * the current timer rate in Hz before the proper driver model timer is ready.
99 * It should be implemented by one of the timer values. This is mostly useful
100 * for tracing. This corresponds to the clock_rate value in struct
101 * timer_dev_priv.
102 */
103unsigned long timer_early_get_rate(void);
104
Thomas Chouc8a7ba92015-10-09 13:46:34 +0800105#endif /* _TIMER_H_ */