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