]> Git Repo - J-u-boot.git/blame - include/timer.h
Merge branch 'next' of https://source.denx.de/u-boot/custodians/u-boot-riscv into...
[J-u-boot.git] / include / timer.h
CommitLineData
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
1e766a04
OP
9#define timer_get_ops(dev) ((struct timer_ops *)(dev)->driver->ops)
10
aff60aba 11/**
4aa5053d 12 * dm_timer_init() - set up a timer for time keeping
c8336975 13 *
4aa5053d
SG
14 * Sets up gd->timer if the device is not already bound, making sure it is
15 * probed and ready for use
16 *
17 * On success, inits gd->timer so that lib/timer can use it for future reference
18 *
19 * Returns: 0 on success, -EAGAIN if driver model is not ready yet, -ENODEV if
20 * no timer could be found, other error if the timer could not be bound or
21 * probed
c8336975
M
22 */
23int dm_timer_init(void);
24
35761216
SA
25/**
26 * timer_timebase_fallback() - Helper for timers using timebase fallback
27 * @dev: A timer partially-probed timer device
28 *
29 * This is a helper function designed for timers which need to fall back on the
30 * cpu's timebase. This function is designed to be called during the driver's
31 * probe(). If there is a clocks or clock-frequency property in the timer's
32 * binding, then it will be used. Otherwise, the timebase of the current cpu
33 * will be used. This is initialized by the cpu driver, and usually gotten from
34 * ``/cpus/timebase-frequency`` or ``/cpus/cpu@X/timebase-frequency``.
35 *
36 * Return: 0 if OK, or negative error code on failure
37 */
38int timer_timebase_fallback(struct udevice *dev);
39
aff60aba
SA
40/**
41 * timer_conv_64() - convert 32-bit counter value to 64-bit
9ca07ebb 42 * @count: 32-bit counter value
aff60aba
SA
43 *
44 * Return: 64-bit counter value
9ca07ebb
BM
45 */
46u64 timer_conv_64(u32 count);
47
aff60aba
SA
48/**
49 * timer_get_count() - Get the current timer count
435ae76e 50 * @dev: The timer device
c8a7ba9e 51 * @count: pointer that returns the current timer count
aff60aba
SA
52 *
53 * Return: 0 if OK, -ve on error
c8a7ba9e 54 */
9ca07ebb 55int timer_get_count(struct udevice *dev, u64 *count);
435ae76e 56
aff60aba 57/**
c00b289b 58 * timer_get_rate() - Get the timer input clock frequency in Hz
435ae76e 59 * @dev: The timer device
aff60aba 60 *
c00b289b 61 * Return: the timer input clock frequency in Hz
c8a7ba9e
TC
62 */
63unsigned long timer_get_rate(struct udevice *dev);
64
aff60aba 65/**
435ae76e 66 * struct timer_ops - Driver model timer operations
c8a7ba9e 67 *
435ae76e 68 * The uclass interface is implemented by all timer devices which use
c8a7ba9e
TC
69 * driver model.
70 */
71struct timer_ops {
aff60aba
SA
72 /**
73 * @get_count: Get the current timer count
c8a7ba9e 74 *
435ae76e 75 * @dev: The timer device
aff60aba 76 *
8af7bb91
SA
77 * This function may be called at any time after the driver is probed.
78 * All necessary initialization must be completed by the time probe()
79 * returns. The count returned by this functions should be monotonic.
80 * This function must succeed.
aff60aba 81 *
8af7bb91 82 * Return: The current 64-bit timer count
c8a7ba9e 83 */
8af7bb91 84 u64 (*get_count)(struct udevice *dev);
c8a7ba9e
TC
85};
86
aff60aba 87/**
c8a7ba9e
TC
88 * struct timer_dev_priv - information about a device used by the uclass
89 *
c00b289b 90 * @clock_rate: the timer input clock frequency in Hz
c8a7ba9e
TC
91 */
92struct timer_dev_priv {
93 unsigned long clock_rate;
94};
95
c95fec31
SG
96/**
97 * timer_early_get_count() - Implement timer_get_count() before driver model
98 *
aff60aba 99 * If ``CONFIG_TIMER_EARLY`` is enabled, this function wil be called to return
c95fec31
SG
100 * the current timer value before the proper driver model timer is ready.
101 * It should be implemented by one of the timer values. This is mostly useful
102 * for tracing.
103 */
104u64 timer_early_get_count(void);
105
106/**
107 * timer_early_get_rate() - Get the timer rate before driver model
108 *
aff60aba 109 * If ``CONFIG_TIMER_EARLY`` is enabled, this function wil be called to return
c95fec31
SG
110 * the current timer rate in Hz before the proper driver model timer is ready.
111 * It should be implemented by one of the timer values. This is mostly useful
112 * for tracing. This corresponds to the clock_rate value in struct
113 * timer_dev_priv.
114 */
115unsigned long timer_early_get_rate(void);
116
c8a7ba9e 117#endif /* _TIMER_H_ */
This page took 0.55735 seconds and 4 git commands to generate.