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 | |
| 9 | /* |
Mugunthan V N | c833697 | 2016-01-16 21:33:58 +0530 | [diff] [blame] | 10 | * dm_timer_init - initialize a timer for time keeping. On success |
| 11 | * initializes gd->timer so that lib/timer can use it for future |
| 12 | * referrence. |
| 13 | * |
| 14 | * @return - 0 on success or error number |
| 15 | */ |
| 16 | int dm_timer_init(void); |
| 17 | |
| 18 | /* |
Bin Meng | 9ca07eb | 2015-11-24 13:31:17 -0700 | [diff] [blame] | 19 | * timer_conv_64 - convert 32-bit counter value to 64-bit |
| 20 | * |
| 21 | * @count: 32-bit counter value |
| 22 | * @return: 64-bit counter value |
| 23 | */ |
| 24 | u64 timer_conv_64(u32 count); |
| 25 | |
| 26 | /* |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 27 | * Get the current timer count |
| 28 | * |
Bin Meng | 435ae76 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 29 | * @dev: The timer device |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 30 | * @count: pointer that returns the current timer count |
| 31 | * @return: 0 if OK, -ve on error |
| 32 | */ |
Bin Meng | 9ca07eb | 2015-11-24 13:31:17 -0700 | [diff] [blame] | 33 | int timer_get_count(struct udevice *dev, u64 *count); |
Bin Meng | 435ae76 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 34 | |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 35 | /* |
| 36 | * Get the timer input clock frequency |
| 37 | * |
Bin Meng | 435ae76 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 38 | * @dev: The timer device |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 39 | * @return: the timer input clock frequency |
| 40 | */ |
| 41 | unsigned long timer_get_rate(struct udevice *dev); |
| 42 | |
| 43 | /* |
Bin Meng | 435ae76 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 44 | * struct timer_ops - Driver model timer operations |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 45 | * |
Bin Meng | 435ae76 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 46 | * The uclass interface is implemented by all timer devices which use |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 47 | * driver model. |
| 48 | */ |
| 49 | struct timer_ops { |
| 50 | /* |
| 51 | * Get the current timer count |
| 52 | * |
Bin Meng | 435ae76 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 53 | * @dev: The timer device |
Bin Meng | 9ca07eb | 2015-11-24 13:31:17 -0700 | [diff] [blame] | 54 | * @count: pointer that returns the current 64-bit timer count |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 55 | * @return: 0 if OK, -ve on error |
| 56 | */ |
Bin Meng | 9ca07eb | 2015-11-24 13:31:17 -0700 | [diff] [blame] | 57 | int (*get_count)(struct udevice *dev, u64 *count); |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | /* |
| 61 | * struct timer_dev_priv - information about a device used by the uclass |
| 62 | * |
| 63 | * @clock_rate: the timer input clock frequency |
| 64 | */ |
| 65 | struct timer_dev_priv { |
| 66 | unsigned long clock_rate; |
| 67 | }; |
| 68 | |
Simon Glass | c95fec3 | 2016-02-24 09:14:49 -0700 | [diff] [blame] | 69 | /** |
| 70 | * timer_early_get_count() - Implement timer_get_count() before driver model |
| 71 | * |
| 72 | * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return |
| 73 | * the current timer value before the proper driver model timer is ready. |
| 74 | * It should be implemented by one of the timer values. This is mostly useful |
| 75 | * for tracing. |
| 76 | */ |
| 77 | u64 timer_early_get_count(void); |
| 78 | |
| 79 | /** |
| 80 | * timer_early_get_rate() - Get the timer rate before driver model |
| 81 | * |
| 82 | * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return |
| 83 | * the current timer rate in Hz before the proper driver model timer is ready. |
| 84 | * It should be implemented by one of the timer values. This is mostly useful |
| 85 | * for tracing. This corresponds to the clock_rate value in struct |
| 86 | * timer_dev_priv. |
| 87 | */ |
| 88 | unsigned long timer_early_get_rate(void); |
| 89 | |
Thomas Chou | c8a7ba9 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 90 | #endif /* _TIMER_H_ */ |