All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 03/12] aspeed: Add Timer Support
Date: Sat, 14 Jan 2017 10:13:45 -0700	[thread overview]
Message-ID: <CAPnjgZ1Zpa3O+8mJAQiOWGHudYjKqAbYeyvimZbuY1_c1Bo5uA@mail.gmail.com> (raw)
In-Reply-To: <20170104194656.124368-4-maxims@google.com>

Hi Maxim,

On 4 January 2017 at 12:46, Maxim Sloyko <maxims@google.com> wrote:
> Add support for timer for Aspeed ast2400/ast2500 devices.
> The driver actually controls several devices, but because all devices
> share the same Control Register, it is somewhat difficult to completely
> decouple them. Since only one timer is needed at the moment, this should
> be OK.
>
> The timer uses fixed clock, so does not rely on a clock driver.
>
> Signed-off-by: Maxim Sloyko <maxims@google.com>
> ---
>
>  arch/arm/include/asm/arch-aspeed/timer.h | 54 ++++++++++++++++++
>  drivers/timer/Kconfig                    |  7 +++
>  drivers/timer/Makefile                   |  1 +
>  drivers/timer/ast_timer.c                | 96 ++++++++++++++++++++++++++++++++
>  4 files changed, 158 insertions(+)
>  create mode 100644 arch/arm/include/asm/arch-aspeed/timer.h
>  create mode 100644 drivers/timer/ast_timer.c

Reviewed-by: Simon Glass <sjg@chromium.org>

nits below.

>
> diff --git a/arch/arm/include/asm/arch-aspeed/timer.h b/arch/arm/include/asm/arch-aspeed/timer.h
> new file mode 100644
> index 0000000000..87c5b354ec
> --- /dev/null
> +++ b/arch/arm/include/asm/arch-aspeed/timer.h
> @@ -0,0 +1,54 @@
> +/*
> + * Copyright (c) 2016 Google, Inc
> + *
> + * SPDX-License-Identifier:    GPL-2.0+
> + */
> +#ifndef _ASM_ARCH_TIMER_H
> +#define _ASM_ARCH_TIMER_H
> +
> +/* Each timer has 4 control bits in ctrl1 register.
> + * Timer1 uses bits 0:3, Timer2 uses bits 4:7 and so on,
> + * such that timer X uses bits (4 * X - 4):(4 * X - 1)
> + * If the timer does not support PWM, bit 4 is reserved.
> + */
> +#define AST_TMC_EN                     (1 << 0)
> +#define AST_TMC_1MHZ                   (1 << 1)
> +#define AST_TMC_OVFINTR                        (1 << 2)
> +#define AST_TMC_PWM                    (1 << 3)
> +
> +/* Timers are counted from 1 in the datasheet. */
> +#define AST_TMC_CTRL1_SHIFT(n)                 (4 * ((n) - 1))
> +
> +#define AST_TMC_RATE  (1000*1000)
> +
> +#ifndef __ASSEMBLY__
> +
> +/*
> + * All timers share control registers, which makes it harder to make them
> + * separate devices. Since only one timer is needed at the moment, making
> + * it this just one device.
> + */
> +
> +struct ast_timer_counter {
> +       u32 status;
> +       u32 reload_val;
> +       u32 match1;
> +       u32 match2;
> +};
> +
> +struct ast_timer {
> +       struct ast_timer_counter timers1[3];
> +       u32 ctrl1;
> +       u32 ctrl2;
> +#ifdef CONFIG_ASPEED_AST2500
> +       u32 ctrl3;
> +       u32 ctrl1_clr;
> +#else
> +       u32 reserved[2];
> +#endif
> +       struct ast_timer_counter timers2[5];
> +};
> +
> +#endif  /* __ASSEMBLY__ */
> +
> +#endif  /* _ASM_ARCH_TIMER_H */
> diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig
> index cb18f12fc9..9c5f98bb88 100644
> --- a/drivers/timer/Kconfig
> +++ b/drivers/timer/Kconfig
> @@ -46,4 +46,11 @@ config OMAP_TIMER
>         help
>           Select this to enable an timer for Omap devices.
>
> +config AST_TIMER
> +       bool "Aspeed ast2400/ast2500 timer support"
> +       depends on TIMER
> +       default y if ARCH_ASPEED
> +       help
> +         Select this to enable timer for Aspeed ast2400/ast2500 devices.

Can you add more detail? How many channels? What features are
supported by the driver?

> +
>  endmenu
> diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile
> index f351fbb4e0..a4b1a486b0 100644
> --- a/drivers/timer/Makefile
> +++ b/drivers/timer/Makefile
> @@ -9,3 +9,4 @@ obj-$(CONFIG_ALTERA_TIMER)      += altera_timer.o
>  obj-$(CONFIG_SANDBOX_TIMER)    += sandbox_timer.o
>  obj-$(CONFIG_X86_TSC_TIMER)    += tsc_timer.o
>  obj-$(CONFIG_OMAP_TIMER)       += omap-timer.o
> +obj-$(CONFIG_AST_TIMER)        += ast_timer.o
> diff --git a/drivers/timer/ast_timer.c b/drivers/timer/ast_timer.c
> new file mode 100644
> index 0000000000..f644882f40
> --- /dev/null
> +++ b/drivers/timer/ast_timer.c
> @@ -0,0 +1,96 @@
> +/*
> + * Copyright 2016 Google Inc.
> + *
> + * SPDX-License-Identifier:    GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <errno.h>
> +#include <timer.h>
> +#include <asm/io.h>
> +#include <asm/arch/timer.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +#define AST_TICK_TIMER  1
> +#define AST_TMC_RELOAD_VAL  0xffffffff
> +
> +struct ast_timer_priv {
> +       struct ast_timer *regs;
> +};
> +
> +static struct ast_timer_counter *ast_get_timer_counter(struct ast_timer *timer,
> +                                                      int n)
> +{
> +       if (n > 3)
> +               return &timer->timers2[n - 4];
> +       else
> +               return &timer->timers1[n - 1];
> +}
> +
> +static int ast_timer_probe(struct udevice *dev)
> +{
> +       struct ast_timer_priv *priv = dev_get_priv(dev);
> +       struct ast_timer_counter *tmc = ast_get_timer_counter(priv->regs,
> +                                                             AST_TICK_TIMER);

I suppose tmc could be in your struct ast_timer_priv to save you doing
this each time?

> +       struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
> +
> +       writel(AST_TMC_RELOAD_VAL, &tmc->reload_val);
> +
> +       /*
> +        * Stop the timer. This will also load reload_val into
> +        * the status register.
> +        */
> +       clrbits_le32(&priv->regs->ctrl1,
> +                    AST_TMC_EN << AST_TMC_CTRL1_SHIFT(AST_TICK_TIMER));
> +       /* Start the timer from the fixed 1MHz clock. */
> +       setbits_le32(&priv->regs->ctrl1,
> +                    (AST_TMC_EN | AST_TMC_1MHZ) <<
> +                    AST_TMC_CTRL1_SHIFT(AST_TICK_TIMER));
> +
> +       uc_priv->clock_rate = AST_TMC_RATE;
> +
> +       return 0;
> +}
> +
> +static int ast_timer_get_count(struct udevice *dev, u64 *count)
> +{
> +       struct ast_timer_priv *priv = dev_get_priv(dev);
> +       struct ast_timer_counter *tmc = ast_get_timer_counter(priv->regs,
> +                                                             AST_TICK_TIMER);
> +
> +       *count = AST_TMC_RELOAD_VAL - readl(&tmc->status);
> +
> +       return 0;
> +}
> +
> +static int ast_timer_ofdata_to_platdata(struct udevice *dev)
> +{
> +       struct ast_timer_priv *priv = dev_get_priv(dev);
> +
> +       priv->regs = (struct ast_timer *)dev_get_addr(dev);

You can use dev_get_addr_ptr() if you like.

> +
> +       return 0;
> +}
> +
> +static const struct timer_ops ast_timer_ops = {
> +       .get_count = ast_timer_get_count,
> +};
> +
> +static const struct udevice_id ast_timer_ids[] = {
> +       { .compatible = "aspeed,ast2500-timer" },
> +       { .compatible = "aspeed,ast2400-timer" },
> +       { }
> +};
> +
> +U_BOOT_DRIVER(sandbox_timer) = {

s/sandbox/ast/ or something, as Tom, mentioned.

> +       .name = "ast_timer",
> +       .id = UCLASS_TIMER,
> +       .of_match = ast_timer_ids,
> +       .probe = ast_timer_probe,
> +       .priv_auto_alloc_size = sizeof(struct ast_timer_priv),
> +       .ofdata_to_platdata = ast_timer_ofdata_to_platdata,
> +       .ops = &ast_timer_ops,
> +       .flags = DM_FLAG_PRE_RELOC,
> +};
> --
> 2.11.0.390.gc69c2f50cf-goog

Regards,
Simon

>

  parent reply	other threads:[~2017-01-14 17:13 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-04 19:46 [U-Boot] [PATCH 00/12] arm: aspeed: Basic support for Aspeed AST2500 part and eval board Maxim Sloyko
2017-01-04 19:46 ` [U-Boot] [PATCH 01/12] aspeed: Add mach-aspeed directory and basic Kconfig Maxim Sloyko
2017-01-04 19:58   ` Rick Altherr
2017-01-04 20:23     ` Tom Rini
2017-01-14 17:13   ` Simon Glass
2017-01-18  0:15     ` Maxim Sloyko
2017-01-04 19:46 ` [U-Boot] [PATCH 02/12] aspeed: Add support for Watchdot Timer Maxim Sloyko
2017-01-04 20:58   ` Tom Rini
2017-01-14 17:13   ` Simon Glass
2017-01-04 19:46 ` [U-Boot] [PATCH 03/12] aspeed: Add Timer Support Maxim Sloyko
2017-01-04 20:58   ` Tom Rini
2017-01-14 17:13   ` Simon Glass [this message]
2017-01-17 17:57     ` Maxim Sloyko
2017-01-17 21:37       ` Simon Glass
2017-01-17 23:59     ` Maxim Sloyko
2017-01-04 19:46 ` [U-Boot] [PATCH 04/12] aspeed: Add sysreset driver Maxim Sloyko
2017-01-14 17:14   ` Simon Glass
2017-01-04 19:46 ` [U-Boot] [PATCH 05/12] aspeed/ast2500: Device Tree and bindings for some of the clocks Maxim Sloyko
2017-01-04 20:58   ` Tom Rini
2017-01-05  1:18     ` Maxim Sloyko
2017-01-05  3:26       ` Tom Rini
2017-01-05 22:20         ` Maxim Sloyko
2017-01-14 17:13           ` Simon Glass
2017-01-17 23:27             ` Maxim Sloyko
2017-01-21  3:52               ` Simon Glass
2017-01-23 17:52                 ` Maxim Sloyko
2017-01-23 19:51                   ` Simon Glass
2017-01-04 19:46 ` [U-Boot] [PATCH 06/12] aspeed/ast2500: Add Clock Driver Maxim Sloyko
2017-01-14 17:14   ` Simon Glass
2017-01-17 23:18     ` Maxim Sloyko
2017-01-04 19:46 ` [U-Boot] [PATCH 07/12] aspeed/ast2500: Helper function to get access to SCU Maxim Sloyko
2017-01-14 17:14   ` Simon Glass
2017-01-17 22:27     ` Maxim Sloyko
2017-01-04 19:46 ` [U-Boot] [PATCH 08/12] aspeed/ast2500: Add SDRAM MC driver Maxim Sloyko
2017-01-14 17:14   ` Simon Glass
2017-01-18 20:16     ` Maxim Sloyko
2017-01-04 19:46 ` [U-Boot] [PATCH 09/12] aspeed/ast2500: Common board init functions for ast2500 based boards Maxim Sloyko
2017-01-14 17:14   ` Simon Glass
2017-01-17 20:17     ` Maxim Sloyko
2017-01-04 19:46 ` [U-Boot] [PATCH 10/12] aspeed: Common configuration parameters for aspeed boards Maxim Sloyko
2017-01-14 17:14   ` Simon Glass
2017-01-17 20:02     ` Maxim Sloyko
2017-01-04 19:46 ` [U-Boot] [PATCH 11/12] aspeed: Device Tree for ast2500 Eval Board Maxim Sloyko
2017-01-14 17:14   ` Simon Glass
2017-01-17 19:51     ` Maxim Sloyko
2017-01-04 19:46 ` [U-Boot] [PATCH 12/12] aspeed: Configuration for ast2500 eval board Maxim Sloyko
2017-01-14 17:14   ` Simon Glass
2017-01-17 19:46     ` Maxim Sloyko
2017-01-21  3:51       ` Simon Glass
2017-01-04 20:26 ` [U-Boot] [PATCH 00/12] arm: aspeed: Basic support for Aspeed AST2500 part and " Tom Rini
2017-01-04 22:47   ` Maxim Sloyko
2017-01-04 20:58 ` Tom Rini
2017-01-05 22:42 ` [U-Boot] [PATCH v1 0/4] " Maxim Sloyko
2017-01-05 22:42   ` [U-Boot] [PATCH v1 1/4] aspeed: Add drivers common to all Aspeed SoCs Maxim Sloyko
2017-01-05 22:42   ` [U-Boot] [PATCH v1 2/4] aspeed: Add basic ast2500 specific drivers and configuration Maxim Sloyko
2017-01-05 22:42   ` [U-Boot] [PATCH v1 3/4] aspeed: Board init functions and common configs for ast2500 based boards Maxim Sloyko
2017-01-05 22:42   ` [U-Boot] [PATCH v1 4/4] aspeed: Support for ast2500 Eval Board Maxim Sloyko
2017-01-10  1:50   ` [U-Boot] [PATCH v2 0/4] arm: aspeed: Basic support for Aspeed AST2500 part and eval board Maxim Sloyko
2017-01-10  1:50     ` [U-Boot] [PATCH v2 1/4] aspeed: Add drivers common to all Aspeed SoCs Maxim Sloyko
2017-01-11  3:20       ` Tom Rini
2017-01-10  1:50     ` [U-Boot] [PATCH v2 2/4] aspeed: Add basic ast2500 specific drivers and configuration Maxim Sloyko
2017-01-11  3:20       ` Tom Rini
2017-01-10  1:50     ` [U-Boot] [PATCH v2 3/4] aspeed: Board init functions and common configs for ast2500 based boards Maxim Sloyko
2017-01-11  3:20       ` Tom Rini
2017-01-11 23:40         ` Maxim Sloyko
2017-01-10  1:50     ` [U-Boot] [PATCH v2 4/4] aspeed: Support for ast2500 Eval Board Maxim Sloyko
2017-01-11  3:20       ` Tom Rini
2017-01-11 23:45     ` [U-Boot] [PATCH v3 0/4] arm: aspeed: Basic support for Aspeed AST2500 part and eval board Maxim Sloyko
2017-01-11 23:45       ` [U-Boot] [PATCH v3 1/4] aspeed: Add drivers common to all Aspeed SoCs Maxim Sloyko
2017-01-13  0:51         ` Tom Rini
2017-01-11 23:45       ` [U-Boot] [PATCH v3 2/4] aspeed: Add basic ast2500 specific drivers and configuration Maxim Sloyko
2017-01-11 23:45       ` [U-Boot] [PATCH v3 3/4] aspeed: Board init functions and common configs for ast2500 based boards Maxim Sloyko
2017-01-13  0:51         ` Tom Rini
2017-01-11 23:45       ` [U-Boot] [PATCH v3 4/4] aspeed: Support for ast2500 Eval Board Maxim Sloyko
2017-01-13  0:51         ` Tom Rini
2017-01-18 21:44       ` [U-Boot] [PATCH v4 0/4] arm: aspeed: Basic support for Aspeed AST2500 part and eval board Maxim Sloyko
2017-01-18 21:44         ` [U-Boot] [PATCH v4 1/4] aspeed: Add drivers common to all Aspeed SoCs Maxim Sloyko
2017-01-26 14:23           ` Simon Glass
2017-01-26 18:31             ` Maxim Sloyko
2017-01-28 22:44           ` [U-Boot] [U-Boot, v4, " Tom Rini
2017-01-18 21:44         ` [U-Boot] [PATCH v4 2/4] aspeed: Add basic ast2500-specific drivers and configuration Maxim Sloyko
2017-01-26 14:23           ` Simon Glass
2017-01-26 18:02             ` Maxim Sloyko
2017-01-28 22:44           ` [U-Boot] [U-Boot, v4, " Tom Rini
2017-01-18 21:44         ` [U-Boot] [PATCH v4 3/4] aspeed: Board init functions and common configs for ast2500 based boards Maxim Sloyko
2017-01-26 14:23           ` Simon Glass
2017-01-28 22:44           ` [U-Boot] [U-Boot, v4, " Tom Rini
2017-01-18 21:44         ` [U-Boot] [PATCH v4 4/4] aspeed: Support for ast2500 Eval Board Maxim Sloyko
2017-01-26 14:23           ` Simon Glass
2017-01-28 22:44           ` [U-Boot] [U-Boot, v4, " Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPnjgZ1Zpa3O+8mJAQiOWGHudYjKqAbYeyvimZbuY1_c1Bo5uA@mail.gmail.com \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.