]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
c8a7ba9e TC |
2 | /* |
3 | * Copyright (C) 2015 Thomas Chou <[email protected]> | |
c8a7ba9e TC |
4 | */ |
5 | ||
6 | #ifndef _TIMER_H_ | |
7 | #define _TIMER_H_ | |
8 | ||
aff60aba SA |
9 | /** |
10 | * dm_timer_init() - initialize a timer for time keeping. On success | |
c8336975 M |
11 | * initializes gd->timer so that lib/timer can use it for future |
12 | * referrence. | |
13 | * | |
aff60aba | 14 | * Return: 0 on success or error number |
c8336975 M |
15 | */ |
16 | int dm_timer_init(void); | |
17 | ||
35761216 SA |
18 | /** |
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 | */ | |
31 | int timer_timebase_fallback(struct udevice *dev); | |
32 | ||
aff60aba SA |
33 | /** |
34 | * timer_conv_64() - convert 32-bit counter value to 64-bit | |
9ca07ebb | 35 | * @count: 32-bit counter value |
aff60aba SA |
36 | * |
37 | * Return: 64-bit counter value | |
9ca07ebb BM |
38 | */ |
39 | u64 timer_conv_64(u32 count); | |
40 | ||
aff60aba SA |
41 | /** |
42 | * timer_get_count() - Get the current timer count | |
435ae76e | 43 | * @dev: The timer device |
c8a7ba9e | 44 | * @count: pointer that returns the current timer count |
aff60aba SA |
45 | * |
46 | * Return: 0 if OK, -ve on error | |
c8a7ba9e | 47 | */ |
9ca07ebb | 48 | int timer_get_count(struct udevice *dev, u64 *count); |
435ae76e | 49 | |
aff60aba SA |
50 | /** |
51 | * timer_get_rate() - Get the timer input clock frequency | |
435ae76e | 52 | * @dev: The timer device |
aff60aba SA |
53 | * |
54 | * Return: the timer input clock frequency | |
c8a7ba9e TC |
55 | */ |
56 | unsigned long timer_get_rate(struct udevice *dev); | |
57 | ||
aff60aba | 58 | /** |
435ae76e | 59 | * struct timer_ops - Driver model timer operations |
c8a7ba9e | 60 | * |
435ae76e | 61 | * The uclass interface is implemented by all timer devices which use |
c8a7ba9e TC |
62 | * driver model. |
63 | */ | |
64 | struct timer_ops { | |
aff60aba SA |
65 | /** |
66 | * @get_count: Get the current timer count | |
c8a7ba9e | 67 | * |
435ae76e | 68 | * @dev: The timer device |
aff60aba | 69 | * |
8af7bb91 SA |
70 | * 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. | |
aff60aba | 74 | * |
8af7bb91 | 75 | * Return: The current 64-bit timer count |
c8a7ba9e | 76 | */ |
8af7bb91 | 77 | u64 (*get_count)(struct udevice *dev); |
c8a7ba9e TC |
78 | }; |
79 | ||
aff60aba | 80 | /** |
c8a7ba9e TC |
81 | * struct timer_dev_priv - information about a device used by the uclass |
82 | * | |
83 | * @clock_rate: the timer input clock frequency | |
84 | */ | |
85 | struct timer_dev_priv { | |
86 | unsigned long clock_rate; | |
87 | }; | |
88 | ||
c95fec31 SG |
89 | /** |
90 | * timer_early_get_count() - Implement timer_get_count() before driver model | |
91 | * | |
aff60aba | 92 | * If ``CONFIG_TIMER_EARLY`` is enabled, this function wil be called to return |
c95fec31 SG |
93 | * 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 | */ | |
97 | u64 timer_early_get_count(void); | |
98 | ||
99 | /** | |
100 | * timer_early_get_rate() - Get the timer rate before driver model | |
101 | * | |
aff60aba | 102 | * If ``CONFIG_TIMER_EARLY`` is enabled, this function wil be called to return |
c95fec31 SG |
103 | * 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 | */ | |
108 | unsigned long timer_early_get_rate(void); | |
109 | ||
c8a7ba9e | 110 | #endif /* _TIMER_H_ */ |