[U-Boot] [PATCH 1/2] dm: implement a Timer uclass

Thomas Chou thomas at wytron.com.tw
Tue Sep 29 03:32:03 CEST 2015



On 09/28/2015 09:19 PM, Thomas Chou wrote:
> diff --git a/drivers/timer/timer.c b/drivers/timer/timer.c
> new file mode 100644
> index 0000000..648fd06
> --- /dev/null
> +++ b/drivers/timer/timer.c
> @@ -0,0 +1,51 @@
> +/*
> + * Copyright (C) 2015 Thomas Chou <thomas at wytron.com.tw>
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <errno.h>
> +#include <timer.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +unsigned long notrace get_tbclk(void)
> +{
> +	struct udevice *dev;
> +	unsigned long rate;
> +
> +	uclass_first_device(UCLASS_TIMER, &dev);
> +	if (!dev)
> +		return 100000000; /* 100MHz, fail-safe */
		return -ENODEV;

> +
> +	timer_get_rate(dev, &rate);
> +
> +	return rate;
> +}
> +
> +unsigned long notrace timer_read_counter(void)
> +{
> +	struct udevice *dev;
> +	unsigned long count;
> +
> +	uclass_first_device(UCLASS_TIMER, &dev);
> +	if (!dev)
> +		return 0; /* 0, fail-safe */
		return -ENODEV;



More information about the U-Boot mailing list