blob: dcc803c392a014ae589d6e7768fcf3b39e5d42fc [file] [log] [blame]
Thomas Chouc8a7ba92015-10-09 13:46:34 +08001/*
2 * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#ifndef _TIMER_H_
8#define _TIMER_H_
9
10/*
Mugunthan V Nc8336972016-01-16 21:33:58 +053011 * dm_timer_init - initialize a timer for time keeping. On success
12 * initializes gd->timer so that lib/timer can use it for future
13 * referrence.
14 *
15 * @return - 0 on success or error number
16 */
17int dm_timer_init(void);
18
19/*
Bin Meng9ca07eb2015-11-24 13:31:17 -070020 * timer_conv_64 - convert 32-bit counter value to 64-bit
21 *
22 * @count: 32-bit counter value
23 * @return: 64-bit counter value
24 */
25u64 timer_conv_64(u32 count);
26
27/*
Thomas Chouc8a7ba92015-10-09 13:46:34 +080028 * Get the current timer count
29 *
Bin Meng435ae762015-11-13 00:11:14 -080030 * @dev: The timer device
Thomas Chouc8a7ba92015-10-09 13:46:34 +080031 * @count: pointer that returns the current timer count
32 * @return: 0 if OK, -ve on error
33 */
Bin Meng9ca07eb2015-11-24 13:31:17 -070034int timer_get_count(struct udevice *dev, u64 *count);
Bin Meng435ae762015-11-13 00:11:14 -080035
Thomas Chouc8a7ba92015-10-09 13:46:34 +080036/*
37 * Get the timer input clock frequency
38 *
Bin Meng435ae762015-11-13 00:11:14 -080039 * @dev: The timer device
Thomas Chouc8a7ba92015-10-09 13:46:34 +080040 * @return: the timer input clock frequency
41 */
42unsigned long timer_get_rate(struct udevice *dev);
43
44/*
Bin Meng435ae762015-11-13 00:11:14 -080045 * struct timer_ops - Driver model timer operations
Thomas Chouc8a7ba92015-10-09 13:46:34 +080046 *
Bin Meng435ae762015-11-13 00:11:14 -080047 * The uclass interface is implemented by all timer devices which use
Thomas Chouc8a7ba92015-10-09 13:46:34 +080048 * driver model.
49 */
50struct timer_ops {
51 /*
52 * Get the current timer count
53 *
Bin Meng435ae762015-11-13 00:11:14 -080054 * @dev: The timer device
Bin Meng9ca07eb2015-11-24 13:31:17 -070055 * @count: pointer that returns the current 64-bit timer count
Thomas Chouc8a7ba92015-10-09 13:46:34 +080056 * @return: 0 if OK, -ve on error
57 */
Bin Meng9ca07eb2015-11-24 13:31:17 -070058 int (*get_count)(struct udevice *dev, u64 *count);
Thomas Chouc8a7ba92015-10-09 13:46:34 +080059};
60
61/*
62 * struct timer_dev_priv - information about a device used by the uclass
63 *
64 * @clock_rate: the timer input clock frequency
65 */
66struct timer_dev_priv {
67 unsigned long clock_rate;
68};
69
Simon Glassc95fec32016-02-24 09:14:49 -070070/**
71 * timer_early_get_count() - Implement timer_get_count() before driver model
72 *
73 * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
74 * the current timer value before the proper driver model timer is ready.
75 * It should be implemented by one of the timer values. This is mostly useful
76 * for tracing.
77 */
78u64 timer_early_get_count(void);
79
80/**
81 * timer_early_get_rate() - Get the timer rate before driver model
82 *
83 * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
84 * the current timer rate in Hz before the proper driver model timer is ready.
85 * It should be implemented by one of the timer values. This is mostly useful
86 * for tracing. This corresponds to the clock_rate value in struct
87 * timer_dev_priv.
88 */
89unsigned long timer_early_get_rate(void);
90
Thomas Chouc8a7ba92015-10-09 13:46:34 +080091#endif /* _TIMER_H_ */