1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */ 2c8a7ba9eSThomas Chou /* 3c8a7ba9eSThomas Chou * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw> 4c8a7ba9eSThomas Chou */ 5c8a7ba9eSThomas Chou 6c8a7ba9eSThomas Chou #ifndef _TIMER_H_ 7c8a7ba9eSThomas Chou #define _TIMER_H_ 8c8a7ba9eSThomas Chou 9c8a7ba9eSThomas Chou /* 10c8336975SMugunthan V N * dm_timer_init - initialize a timer for time keeping. On success 11c8336975SMugunthan V N * initializes gd->timer so that lib/timer can use it for future 12c8336975SMugunthan V N * referrence. 13c8336975SMugunthan V N * 14c8336975SMugunthan V N * @return - 0 on success or error number 15c8336975SMugunthan V N */ 16c8336975SMugunthan V N int dm_timer_init(void); 17c8336975SMugunthan V N 18c8336975SMugunthan V N /* 199ca07ebbSBin Meng * timer_conv_64 - convert 32-bit counter value to 64-bit 209ca07ebbSBin Meng * 219ca07ebbSBin Meng * @count: 32-bit counter value 229ca07ebbSBin Meng * @return: 64-bit counter value 239ca07ebbSBin Meng */ 249ca07ebbSBin Meng u64 timer_conv_64(u32 count); 259ca07ebbSBin Meng 269ca07ebbSBin Meng /* 27c8a7ba9eSThomas Chou * Get the current timer count 28c8a7ba9eSThomas Chou * 29435ae76eSBin Meng * @dev: The timer device 30c8a7ba9eSThomas Chou * @count: pointer that returns the current timer count 31c8a7ba9eSThomas Chou * @return: 0 if OK, -ve on error 32c8a7ba9eSThomas Chou */ 339ca07ebbSBin Meng int timer_get_count(struct udevice *dev, u64 *count); 34435ae76eSBin Meng 35c8a7ba9eSThomas Chou /* 36c8a7ba9eSThomas Chou * Get the timer input clock frequency 37c8a7ba9eSThomas Chou * 38435ae76eSBin Meng * @dev: The timer device 39c8a7ba9eSThomas Chou * @return: the timer input clock frequency 40c8a7ba9eSThomas Chou */ 41c8a7ba9eSThomas Chou unsigned long timer_get_rate(struct udevice *dev); 42c8a7ba9eSThomas Chou 43c8a7ba9eSThomas Chou /* 44435ae76eSBin Meng * struct timer_ops - Driver model timer operations 45c8a7ba9eSThomas Chou * 46435ae76eSBin Meng * The uclass interface is implemented by all timer devices which use 47c8a7ba9eSThomas Chou * driver model. 48c8a7ba9eSThomas Chou */ 49c8a7ba9eSThomas Chou struct timer_ops { 50c8a7ba9eSThomas Chou /* 51c8a7ba9eSThomas Chou * Get the current timer count 52c8a7ba9eSThomas Chou * 53435ae76eSBin Meng * @dev: The timer device 549ca07ebbSBin Meng * @count: pointer that returns the current 64-bit timer count 55c8a7ba9eSThomas Chou * @return: 0 if OK, -ve on error 56c8a7ba9eSThomas Chou */ 579ca07ebbSBin Meng int (*get_count)(struct udevice *dev, u64 *count); 58c8a7ba9eSThomas Chou }; 59c8a7ba9eSThomas Chou 60c8a7ba9eSThomas Chou /* 61c8a7ba9eSThomas Chou * struct timer_dev_priv - information about a device used by the uclass 62c8a7ba9eSThomas Chou * 63c8a7ba9eSThomas Chou * @clock_rate: the timer input clock frequency 64c8a7ba9eSThomas Chou */ 65c8a7ba9eSThomas Chou struct timer_dev_priv { 66c8a7ba9eSThomas Chou unsigned long clock_rate; 67c8a7ba9eSThomas Chou }; 68c8a7ba9eSThomas Chou 69c95fec31SSimon Glass /** 70c95fec31SSimon Glass * timer_early_get_count() - Implement timer_get_count() before driver model 71c95fec31SSimon Glass * 72c95fec31SSimon Glass * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return 73c95fec31SSimon Glass * the current timer value before the proper driver model timer is ready. 74c95fec31SSimon Glass * It should be implemented by one of the timer values. This is mostly useful 75c95fec31SSimon Glass * for tracing. 76c95fec31SSimon Glass */ 77c95fec31SSimon Glass u64 timer_early_get_count(void); 78c95fec31SSimon Glass 79c95fec31SSimon Glass /** 80c95fec31SSimon Glass * timer_early_get_rate() - Get the timer rate before driver model 81c95fec31SSimon Glass * 82c95fec31SSimon Glass * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return 83c95fec31SSimon Glass * the current timer rate in Hz before the proper driver model timer is ready. 84c95fec31SSimon Glass * It should be implemented by one of the timer values. This is mostly useful 85c95fec31SSimon Glass * for tracing. This corresponds to the clock_rate value in struct 86c95fec31SSimon Glass * timer_dev_priv. 87c95fec31SSimon Glass */ 88c95fec31SSimon Glass unsigned long timer_early_get_rate(void); 89c95fec31SSimon Glass 90c8a7ba9eSThomas Chou #endif /* _TIMER_H_ */ 91