Thomas Chou | fb798b1 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 1 | /* |
| 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 N | 6f89d04 | 2016-01-16 21:33:58 +0530 | [diff] [blame] | 11 | * 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 | */ |
| 17 | int dm_timer_init(void); |
| 18 | |
| 19 | /* |
Bin Meng | ab841b6 | 2015-11-24 13:31:17 -0700 | [diff] [blame] | 20 | * 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 | */ |
| 25 | u64 timer_conv_64(u32 count); |
| 26 | |
| 27 | /* |
Thomas Chou | fb798b1 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 28 | * Get the current timer count |
| 29 | * |
Bin Meng | 8a7b864 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 30 | * @dev: The timer device |
Thomas Chou | fb798b1 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 31 | * @count: pointer that returns the current timer count |
| 32 | * @return: 0 if OK, -ve on error |
| 33 | */ |
Bin Meng | ab841b6 | 2015-11-24 13:31:17 -0700 | [diff] [blame] | 34 | int timer_get_count(struct udevice *dev, u64 *count); |
Bin Meng | 8a7b864 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 35 | |
Thomas Chou | fb798b1 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 36 | /* |
| 37 | * Get the timer input clock frequency |
| 38 | * |
Bin Meng | 8a7b864 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 39 | * @dev: The timer device |
Thomas Chou | fb798b1 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 40 | * @return: the timer input clock frequency |
| 41 | */ |
| 42 | unsigned long timer_get_rate(struct udevice *dev); |
| 43 | |
| 44 | /* |
Bin Meng | 8a7b864 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 45 | * struct timer_ops - Driver model timer operations |
Thomas Chou | fb798b1 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 46 | * |
Bin Meng | 8a7b864 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 47 | * The uclass interface is implemented by all timer devices which use |
Thomas Chou | fb798b1 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 48 | * driver model. |
| 49 | */ |
| 50 | struct timer_ops { |
| 51 | /* |
| 52 | * Get the current timer count |
| 53 | * |
Bin Meng | 8a7b864 | 2015-11-13 00:11:14 -0800 | [diff] [blame] | 54 | * @dev: The timer device |
Bin Meng | ab841b6 | 2015-11-24 13:31:17 -0700 | [diff] [blame] | 55 | * @count: pointer that returns the current 64-bit timer count |
Thomas Chou | fb798b1 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 56 | * @return: 0 if OK, -ve on error |
| 57 | */ |
Bin Meng | ab841b6 | 2015-11-24 13:31:17 -0700 | [diff] [blame] | 58 | int (*get_count)(struct udevice *dev, u64 *count); |
Thomas Chou | fb798b1 | 2015-10-09 13:46:34 +0800 | [diff] [blame] | 59 | }; |
| 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 | */ |
| 66 | struct timer_dev_priv { |
| 67 | unsigned long clock_rate; |
| 68 | }; |
| 69 | |
| 70 | #endif /* _TIMER_H_ */ |