1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
9 #define timer_get_ops(dev) ((struct timer_ops *)(dev)->driver->ops)
12 * dm_timer_init() - initialize a timer for time keeping. On success
13 * initializes gd->timer so that lib/timer can use it for future
16 * Return: 0 on success or error number
18 int dm_timer_init(void);
21 * timer_timebase_fallback() - Helper for timers using timebase fallback
22 * @dev: A timer partially-probed timer device
24 * This is a helper function designed for timers which need to fall back on the
25 * cpu's timebase. This function is designed to be called during the driver's
26 * probe(). If there is a clocks or clock-frequency property in the timer's
27 * binding, then it will be used. Otherwise, the timebase of the current cpu
28 * will be used. This is initialized by the cpu driver, and usually gotten from
29 * ``/cpus/timebase-frequency`` or ``/cpus/cpu@X/timebase-frequency``.
31 * Return: 0 if OK, or negative error code on failure
33 int timer_timebase_fallback(struct udevice *dev);
36 * timer_conv_64() - convert 32-bit counter value to 64-bit
37 * @count: 32-bit counter value
39 * Return: 64-bit counter value
41 u64 timer_conv_64(u32 count);
44 * timer_get_count() - Get the current timer count
45 * @dev: The timer device
46 * @count: pointer that returns the current timer count
48 * Return: 0 if OK, -ve on error
50 int timer_get_count(struct udevice *dev, u64 *count);
53 * timer_get_rate() - Get the timer input clock frequency
54 * @dev: The timer device
56 * Return: the timer input clock frequency
58 unsigned long timer_get_rate(struct udevice *dev);
61 * struct timer_ops - Driver model timer operations
63 * The uclass interface is implemented by all timer devices which use
68 * @get_count: Get the current timer count
70 * @dev: The timer device
72 * This function may be called at any time after the driver is probed.
73 * All necessary initialization must be completed by the time probe()
74 * returns. The count returned by this functions should be monotonic.
75 * This function must succeed.
77 * Return: The current 64-bit timer count
79 u64 (*get_count)(struct udevice *dev);
83 * struct timer_dev_priv - information about a device used by the uclass
85 * @clock_rate: the timer input clock frequency
87 struct timer_dev_priv {
88 unsigned long clock_rate;
92 * timer_early_get_count() - Implement timer_get_count() before driver model
94 * If ``CONFIG_TIMER_EARLY`` is enabled, this function wil be called to return
95 * the current timer value before the proper driver model timer is ready.
96 * It should be implemented by one of the timer values. This is mostly useful
99 u64 timer_early_get_count(void);
102 * timer_early_get_rate() - Get the timer rate before driver model
104 * If ``CONFIG_TIMER_EARLY`` is enabled, this function wil be called to return
105 * the current timer rate in Hz before the proper driver model timer is ready.
106 * It should be implemented by one of the timer values. This is mostly useful
107 * for tracing. This corresponds to the clock_rate value in struct
110 unsigned long timer_early_get_rate(void);
112 #endif /* _TIMER_H_ */