[U-Boot] [PATCH 02/19] dm: timer: uclass: add timer init to add timer device

Simon Glass sjg at chromium.org
Fri Nov 27 20:40:04 CET 2015


Hi Mugunthan,

On 27 November 2015 at 00:31, Mugunthan V N <mugunthanvnm at ti.com> wrote:
> Adding timer_init function to create and initialize the timer
> device on platforms where u-boot,dm-pre-reloc is not used. Since
> there will be multiple timer devices in the system, adding a
> tick-timer node in chosen node to know which timer device to be
> used as tick timer in u-boot.
>
> Signed-off-by: Mugunthan V N <mugunthanvnm at ti.com>
> ---
>  doc/device-tree-bindings/chosen.txt | 43 +++++++++++++++++++++++++++++++++++++
>  drivers/timer/timer-uclass.c        | 34 +++++++++++++++++++++++++++++
>  lib/time.c                          |  5 +++++
>  3 files changed, 82 insertions(+)
>  create mode 100644 doc/device-tree-bindings/chosen.txt
>
> diff --git a/doc/device-tree-bindings/chosen.txt b/doc/device-tree-bindings/chosen.txt
> new file mode 100644
> index 0000000..58f29f9
> --- /dev/null
> +++ b/doc/device-tree-bindings/chosen.txt
> @@ -0,0 +1,43 @@
> +The chosen node
> +---------------
> +The chosen node does not represent a real device, but serves as a place
> +for passing data like which serial device to used to print the logs etc
> +
> +
> +stdout-path property
> +--------------------
> +Device trees may specify the device to be used for boot console output
> +with a stdout-path property under /chosen.
> +
> +Example
> +-------
> +/ {
> +       chosen {
> +               stdout-path = "/serial at f00:115200";
> +       };
> +
> +       serial at f00 {
> +               compatible = "vendor,some-uart";
> +               reg = <0xf00 0x10>;
> +       };
> +};
> +
> +tick-timer property
> +-------------------
> +In a system there are multiple timers, specify which timer to be used
> +as the tick-timer. Earlier it was hardcoded in the timer driver now
> +since device tree has all the timer nodes. Specify which timer to be
> +used as tick timer.
> +
> +Example
> +-------
> +/ {
> +       chosen {
> +               tick-timer = &timer2;
> +       };
> +
> +       timer2 at f00 {
> +               compatible = "vendor,some-uart";
> +               reg = <0xf00 0x10>;
> +       };
> +};
> diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c
> index 12aee5b..78ec989 100644
> --- a/drivers/timer/timer-uclass.c
> +++ b/drivers/timer/timer-uclass.c
> @@ -6,9 +6,13 @@
>
>  #include <common.h>
>  #include <dm.h>
> +#include <dm/lists.h>
> +#include <dm/device-internal.h>
>  #include <errno.h>
>  #include <timer.h>
>
> +DECLARE_GLOBAL_DATA_PTR;
> +
>  /*
>   * Implement a Timer uclass to work with lib/time.c. The timer is usually
>   * a 32 bits free-running up counter. The get_rate() method is used to get
> @@ -35,6 +39,36 @@ unsigned long timer_get_rate(struct udevice *dev)
>         return uc_priv->clock_rate;
>  }
>
> +int timer_init(void)
> +{
> +       const void *blob = gd->fdt_blob;
> +       struct udevice *dev;
> +       int node;
> +
> +       if (CONFIG_IS_ENABLED(OF_CONTROL) && blob) {
> +               /* Check for a chosen timer to be used for tick */
> +               node = fdtdec_get_chosen_node(blob, "tick-timer");
> +               if (node < 0)
> +                       return -ENODEV;

Please add a debug() here to help people diagnose problems.

> +
> +               if (uclass_get_device_by_of_offset(UCLASS_TIMER, node, &dev)) {
> +                       /*
> +                        * If the timer is not marked to be bound before
> +                        * relocation, bind it anyway.
> +                        */
> +                       if (node > 0 &&
> +                           !lists_bind_fdt(gd->dm_root, blob, node, &dev)) {
> +                               int ret = device_probe(dev);
> +                               if (ret)

debug()

> +                                       return ret;
> +                       }
> +               }
> +       }
> +
> +       gd->timer = dev;
> +       return 0;
> +}
> +
>  UCLASS_DRIVER(timer) = {
>         .id             = UCLASS_TIMER,
>         .name           = "timer",
> diff --git a/lib/time.c b/lib/time.c
> index b001745..22f7d23 100644
> --- a/lib/time.c
> +++ b/lib/time.c
> @@ -47,6 +47,11 @@ static int notrace dm_timer_init(void)
>         int ret;
>
>         if (!gd->timer) {
> +               /* Check if we have a chosen timer */
> +               timer_init();
> +               if (gd->timer)
> +                       return 0;
> +
>                 ret = uclass_first_device(UCLASS_TIMER, &dev);
>                 if (ret)
>                         return ret;

This code should move up into the timer_init() function. So the sequence is:

- look for a device with 'chosen'
- find the first device

Regards,
Simon


More information about the U-Boot mailing list