From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Chou Date: Tue, 29 Sep 2015 09:32:03 +0800 Subject: [U-Boot] [PATCH 1/2] dm: implement a Timer uclass In-Reply-To: <1443446357-21393-1-git-send-email-thomas@wytron.com.tw> References: <1443446357-21393-1-git-send-email-thomas@wytron.com.tw> Message-ID: <5609EA13.4000400@wytron.com.tw> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 > + * > + * SPDX-License-Identifier: GPL-2.0+ > + */ > + > +#include > +#include > +#include > +#include > + > +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;