Timer Subsystem

int dm_timer_init(void)

set up a timer for time keeping

Parameters

void

no arguments

Description

Sets up gd->timer if the device is not already bound, making sure it is probed and ready for use

On success, inits gd->timer so that lib/timer can use it for future reference

Return

0 on success, -EAGAIN if driver model is not ready yet, -ENODEV if no timer could be found, other error if the timer could not be bound or probed

int timer_timebase_fallback(struct udevice *dev)

Helper for timers using timebase fallback

Parameters

struct udevice *dev

A timer partially-probed timer device

Description

This is a helper function designed for timers which need to fall back on the cpu’s timebase. This function is designed to be called during the driver’s probe(). If there is a clocks or clock-frequency property in the timer’s binding, then it will be used. Otherwise, the timebase of the current cpu will be used. This is initialized by the cpu driver, and usually gotten from /cpus/timebase-frequency or /cpus/cpu**X**/timebase-frequency.

Return

0 if OK, or negative error code on failure

u64 timer_conv_64(u32 count)

convert 32-bit counter value to 64-bit

Parameters

u32 count

32-bit counter value

Return

64-bit counter value

int timer_get_count(struct udevice *dev, u64 *count)

Get the current timer count

Parameters

struct udevice *dev

The timer device

u64 *count

pointer that returns the current timer count

Return

0 if OK, -ve on error

unsigned long timer_get_rate(struct udevice *dev)

Get the timer input clock frequency in Hz

Parameters

struct udevice *dev

The timer device

Return

the timer input clock frequency in Hz

struct timer_ops

Driver model timer operations

Definition

struct timer_ops {
  u64 (*get_count)(struct udevice *dev);
};

Members

get_count

Get the current timer count

dev: The timer device

This function may be called at any time after the driver is probed. All necessary initialization must be completed by the time probe() returns. The count returned by this functions should be monotonic. This function must succeed.

Return: The current 64-bit timer count

Description

The uclass interface is implemented by all timer devices which use driver model.

struct timer_dev_priv

information about a device used by the uclass

Definition

struct timer_dev_priv {
  unsigned long clock_rate;
};

Members

clock_rate

the timer input clock frequency in Hz

u64 timer_early_get_count(void)

Implement timer_get_count() before driver model

Parameters

void

no arguments

Description

If CONFIG_TIMER_EARLY is enabled, this function wil be called to return the current timer value before the proper driver model timer is ready. It should be implemented by one of the timer values. This is mostly useful for tracing.

unsigned long timer_early_get_rate(void)

Get the timer rate before driver model

Parameters

void

no arguments

Description

If CONFIG_TIMER_EARLY is enabled, this function wil be called to return the current timer rate in Hz before the proper driver model timer is ready. It should be implemented by one of the timer values. This is mostly useful for tracing. This corresponds to the clock_rate value in struct timer_dev_priv.