[U-Boot] [PATCH 04/19] drivers: timer: omap_timer: add timer driver for omap devices based on dm

Bin Meng bmeng.cn at gmail.com
Sat Nov 28 12:52:53 CET 2015


Hi Mugunthan,

On Fri, Nov 27, 2015 at 4:31 PM, Mugunthan V N <mugunthanvnm at ti.com> wrote:
> Adding a timer driver for omap devices based on driver model
> and device tree.
>
> Signed-off-by: Mugunthan V N <mugunthanvnm at ti.com>
> ---
>  drivers/timer/Kconfig      |   6 +++
>  drivers/timer/Makefile     |   1 +
>  drivers/timer/omap-timer.c | 108 +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 115 insertions(+)
>  create mode 100644 drivers/timer/omap-timer.c
>
> diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig
> index 601e493..98ba012 100644
> --- a/drivers/timer/Kconfig
> +++ b/drivers/timer/Kconfig
> @@ -23,4 +23,10 @@ config SANDBOX_TIMER
>           Select this to enable an emulated timer for sandbox. It gets
>           time from host os.
>
> +config OMAP_TIMER
> +       bool "Omap Timer support"

nits: Timer -> timer. Please see dm/master branch which has a commit
to fix all these nits in the existing timer drivers.

> +       depends on TIMER
> +       help
> +         Select this to enable an timer for Omap devices.
> +
>  endmenu
> diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile
> index 300946e..2eb9cfc 100644
> --- a/drivers/timer/Makefile
> +++ b/drivers/timer/Makefile
> @@ -7,3 +7,4 @@
>  obj-$(CONFIG_TIMER)            += timer-uclass.o
>  obj-$(CONFIG_ALTERA_TIMER)     += altera_timer.o
>  obj-$(CONFIG_SANDBOX_TIMER)    += sandbox_timer.o
> +obj-$(CONFIG_OMAP_TIMER)       += omap-timer.o
> diff --git a/drivers/timer/omap-timer.c b/drivers/timer/omap-timer.c
> new file mode 100644
> index 0000000..2532e74
> --- /dev/null
> +++ b/drivers/timer/omap-timer.c
> @@ -0,0 +1,108 @@
> +/*
> + * TI OMAP Timer driver

nits: Timer -> timer

> + *
> + * Copyright (C) 2015, Texas Instruments, Incorporated
> + *
> + * 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/clock.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +/* Timer register bits */
> +#define TCLR_START                     BIT(0)  /* Start=1 */
> +#define TCLR_AUTO_RELOAD               BIT(1)  /* Auto reload */
> +#define TCLR_PRE_EN                    BIT(5)  /* Pre-scaler enable */
> +#define TCLR_PTV_SHIFT                 (2)     /* Pre-scaler shift value */
> +
> +#define TIMER_CLOCK             (V_SCLK / (2 << CONFIG_SYS_PTV))
> +
> +struct omap_gptimer_regs {
> +       unsigned int tidr;              /* offset 0x00 */
> +       unsigned char res1[12];
> +       unsigned int tiocp_cfg;         /* offset 0x10 */
> +       unsigned char res2[12];
> +       unsigned int tier;              /* offset 0x20 */
> +       unsigned int tistatr;           /* offset 0x24 */
> +       unsigned int tistat;            /* offset 0x28 */
> +       unsigned int tisr;              /* offset 0x2c */
> +       unsigned int tcicr;             /* offset 0x30 */
> +       unsigned int twer;              /* offset 0x34 */
> +       unsigned int tclr;              /* offset 0x38 */
> +       unsigned int tcrr;              /* offset 0x3c */
> +       unsigned int tldr;              /* offset 0x40 */
> +       unsigned int ttgr;              /* offset 0x44 */
> +       unsigned int twpc;              /* offset 0x48 */
> +       unsigned int tmar;              /* offset 0x4c */
> +       unsigned int tcar1;             /* offset 0x50 */
> +       unsigned int tscir;             /* offset 0x54 */
> +       unsigned int tcar2;             /* offset 0x58 */
> +};
> +
> +/* Omap Timer Priv */
> +struct omap_timer_priv {
> +       struct omap_gptimer_regs *regs;
> +};
> +
> +static int omap_timer_get_count(struct udevice *dev, unsigned long *count)

Please rebase your series on top of dm/master, where this API
parameter 'count' has been changed to u64.

> +{
> +       struct omap_timer_priv *priv = dev_get_priv(dev);
> +
> +       *count = readl(&priv->regs->tcrr);
> +
> +       return 0;
> +}
> +
> +static int omap_timer_probe(struct udevice *dev)
> +{
> +       struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
> +       struct omap_timer_priv *priv = dev_get_priv(dev);
> +
> +       uc_priv->clock_rate = TIMER_CLOCK;
> +
> +       /* start the counter ticking up, reload value on overflow */
> +       writel(0, &priv->regs->tldr);
> +       /* enable timer */
> +       writel((CONFIG_SYS_PTV << 2) | TCLR_PRE_EN | TCLR_AUTO_RELOAD |
> +              TCLR_START, &priv->regs->tclr);
> +
> +       return 0;
> +}
> +
> +static int omap_timer_ofdata_to_platdata(struct udevice *dev)
> +{
> +       struct omap_timer_priv *priv = dev_get_priv(dev);
> +
> +       priv->regs = (struct omap_gptimer_regs *)dev_get_addr(dev);
> +
> +       return 0;
> +}
> +
> +
> +static const struct timer_ops omap_timer_ops = {
> +       .get_count = omap_timer_get_count,
> +};
> +
> +static const struct udevice_id omap_timer_ids[] = {
> +       { .compatible = "ti,am335x-timer" },
> +       { .compatible = "ti,am4372-timer" },
> +       { .compatible = "ti,omap5430-timer" },
> +       {}
> +};
> +
> +U_BOOT_DRIVER(omap_timer) = {
> +       .name   = "omap_timer",
> +       .id     = UCLASS_TIMER,
> +       .of_match = omap_timer_ids,
> +       .ofdata_to_platdata = omap_timer_ofdata_to_platdata,
> +       .priv_auto_alloc_size = sizeof(struct omap_timer_priv),
> +       .probe = omap_timer_probe,
> +       .ops    = &omap_timer_ops,
> +       .flags = DM_FLAG_PRE_RELOC,
> +};
> --

Regards,
Bin


More information about the U-Boot mailing list