Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw> |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _TIMER_H_ |
| 7 | #define _TIMER_H_ |
| 8 | |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 9 | /** |
| 10 | * dm_timer_init() - initialize a timer for time keeping. On success |
Mugunthan V N | c833697 | 2016-01-16 21:33:58 +0530 | [diff] [blame] | 11 | * initializes gd->timer so that lib/timer can use it for future |
| 12 | * referrence. |
| 13 | * |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 14 | * Return: 0 on success or error number |
Mugunthan V N | c833697 | 2016-01-16 21:33:58 +0530 | [diff] [blame] | 15 | */ |
| 16 | int dm_timer_init(void); |
| 17 | |
Sean Anderson | 3576121 | 2020-09-28 10:52:22 -0400 | [diff] [blame] | 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 | |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 33 | /** |
| 34 | * timer_conv_64() - convert 32-bit counter value to 64-bit |
Bin Meng | 9ca07eb | 2015-11-24 13:31:17 -0700 | [diff] [blame] | 35 | * @count: 32-bit counter value |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 36 | * |
| 37 | * Return: 64-bit counter value |
Bin Meng | 9ca07eb | 2015-11-24 13:31:17 -0700 | [diff] [blame] | 38 | */ |
| 39 | u64 timer_conv_64(u32 count); |
| 40 | |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 41 | /** |
| 42 | * timer_get_count() - Get the current timer count |
Bin Meng | 435ae76 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 43 | * @dev: The timer device |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 44 | * @count: pointer that returns the current timer count |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 45 | * |
| 46 | * Return: 0 if OK, -ve on error |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 47 | */ |
Bin Meng | 9ca07eb | 2015-11-24 13:31:17 -0700 | [diff] [blame] | 48 | int timer_get_count(struct udevice *dev, u64 *count); |
Bin Meng | 435ae76 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 49 | |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 50 | /** |
| 51 | * timer_get_rate() - Get the timer input clock frequency |
Bin Meng | 435ae76 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 52 | * @dev: The timer device |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 53 | * |
| 54 | * Return: the timer input clock frequency |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 55 | */ |
| 56 | unsigned long timer_get_rate(struct udevice *dev); |
| 57 | |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 58 | /** |
Bin Meng | 435ae76 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 59 | * struct timer_ops - Driver model timer operations |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 60 | * |
Bin Meng | 435ae76 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 61 | * The uclass interface is implemented by all timer devices which use |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 62 | * driver model. |
| 63 | */ |
| 64 | struct timer_ops { |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 65 | /** |
| 66 | * @get_count: Get the current timer count |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 67 | * |
Bin Meng | 435ae76 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 68 | * @dev: The timer device |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 69 | * |
Bin Meng | 9ca07eb | 2015-11-24 13:31:17 -0700 | [diff] [blame] | 70 | * @count: pointer that returns the current 64-bit timer count |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 71 | * |
| 72 | * Return: 0 if OK, -ve on error |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 73 | */ |
Bin Meng | 9ca07eb | 2015-11-24 13:31:17 -0700 | [diff] [blame] | 74 | int (*get_count)(struct udevice *dev, u64 *count); |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 75 | }; |
| 76 | |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 77 | /** |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 78 | * struct timer_dev_priv - information about a device used by the uclass |
| 79 | * |
| 80 | * @clock_rate: the timer input clock frequency |
| 81 | */ |
| 82 | struct timer_dev_priv { |
| 83 | unsigned long clock_rate; |
| 84 | }; |
| 85 | |
Simon Glass | c95fec3 | 2016-02-24 09:14:49 -0700 | [diff] [blame] | 86 | /** |
| 87 | * timer_early_get_count() - Implement timer_get_count() before driver model |
| 88 | * |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 89 | * If ``CONFIG_TIMER_EARLY`` is enabled, this function wil be called to return |
Simon Glass | c95fec3 | 2016-02-24 09:14:49 -0700 | [diff] [blame] | 90 | * the current timer value before the proper driver model timer is ready. |
| 91 | * It should be implemented by one of the timer values. This is mostly useful |
| 92 | * for tracing. |
| 93 | */ |
| 94 | u64 timer_early_get_count(void); |
| 95 | |
| 96 | /** |
| 97 | * timer_early_get_rate() - Get the timer rate before driver model |
| 98 | * |
Sean Anderson | aff60ab | 2020-10-07 14:37:43 -0400 | [diff] [blame^] | 99 | * If ``CONFIG_TIMER_EARLY`` is enabled, this function wil be called to return |
Simon Glass | c95fec3 | 2016-02-24 09:14:49 -0700 | [diff] [blame] | 100 | * the current timer rate in Hz 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. This corresponds to the clock_rate value in struct |
| 103 | * timer_dev_priv. |
| 104 | */ |
| 105 | unsigned long timer_early_get_rate(void); |
| 106 | |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 107 | #endif /* _TIMER_H_ */ |