xref: /OK3568_Linux_fs/u-boot/include/timer.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #ifndef _TIMER_H_
8*4882a593Smuzhiyun #define _TIMER_H_
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun /*
11*4882a593Smuzhiyun  * dm_timer_init - initialize a timer for time keeping. On success
12*4882a593Smuzhiyun  * initializes gd->timer so that lib/timer can use it for future
13*4882a593Smuzhiyun  * referrence.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * @return - 0 on success or error number
16*4882a593Smuzhiyun  */
17*4882a593Smuzhiyun int dm_timer_init(void);
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun /*
20*4882a593Smuzhiyun  * timer_conv_64 - convert 32-bit counter value to 64-bit
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  * @count: 32-bit counter value
23*4882a593Smuzhiyun  * @return: 64-bit counter value
24*4882a593Smuzhiyun  */
25*4882a593Smuzhiyun u64 timer_conv_64(u32 count);
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun /*
28*4882a593Smuzhiyun  * Get the current timer count
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * @dev: The timer device
31*4882a593Smuzhiyun  * @count: pointer that returns the current timer count
32*4882a593Smuzhiyun  * @return: 0 if OK, -ve on error
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun int timer_get_count(struct udevice *dev, u64 *count);
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /*
37*4882a593Smuzhiyun  * Get the timer input clock frequency
38*4882a593Smuzhiyun  *
39*4882a593Smuzhiyun  * @dev: The timer device
40*4882a593Smuzhiyun  * @return: the timer input clock frequency
41*4882a593Smuzhiyun  */
42*4882a593Smuzhiyun unsigned long timer_get_rate(struct udevice *dev);
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun /*
45*4882a593Smuzhiyun  * struct timer_ops - Driver model timer operations
46*4882a593Smuzhiyun  *
47*4882a593Smuzhiyun  * The uclass interface is implemented by all timer devices which use
48*4882a593Smuzhiyun  * driver model.
49*4882a593Smuzhiyun  */
50*4882a593Smuzhiyun struct timer_ops {
51*4882a593Smuzhiyun 	/*
52*4882a593Smuzhiyun 	 * Get the current timer count
53*4882a593Smuzhiyun 	 *
54*4882a593Smuzhiyun 	 * @dev: The timer device
55*4882a593Smuzhiyun 	 * @count: pointer that returns the current 64-bit timer count
56*4882a593Smuzhiyun 	 * @return: 0 if OK, -ve on error
57*4882a593Smuzhiyun 	 */
58*4882a593Smuzhiyun 	int (*get_count)(struct udevice *dev, u64 *count);
59*4882a593Smuzhiyun };
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun /*
62*4882a593Smuzhiyun  * struct timer_dev_priv - information about a device used by the uclass
63*4882a593Smuzhiyun  *
64*4882a593Smuzhiyun  * @clock_rate: the timer input clock frequency
65*4882a593Smuzhiyun  */
66*4882a593Smuzhiyun struct timer_dev_priv {
67*4882a593Smuzhiyun 	unsigned long clock_rate;
68*4882a593Smuzhiyun };
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun /**
71*4882a593Smuzhiyun  * timer_early_get_count() - Implement timer_get_count() before driver model
72*4882a593Smuzhiyun  *
73*4882a593Smuzhiyun  * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
74*4882a593Smuzhiyun  * the current timer value before the proper driver model timer is ready.
75*4882a593Smuzhiyun  * It should be implemented by one of the timer values. This is mostly useful
76*4882a593Smuzhiyun  * for tracing.
77*4882a593Smuzhiyun  */
78*4882a593Smuzhiyun u64 timer_early_get_count(void);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /**
81*4882a593Smuzhiyun  * timer_early_get_rate() - Get the timer rate before driver model
82*4882a593Smuzhiyun  *
83*4882a593Smuzhiyun  * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
84*4882a593Smuzhiyun  * the current timer rate in Hz before the proper driver model timer is ready.
85*4882a593Smuzhiyun  * It should be implemented by one of the timer values. This is mostly useful
86*4882a593Smuzhiyun  * for tracing. This corresponds to the clock_rate value in struct
87*4882a593Smuzhiyun  * timer_dev_priv.
88*4882a593Smuzhiyun  */
89*4882a593Smuzhiyun unsigned long timer_early_get_rate(void);
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun #endif	/* _TIMER_H_ */
92