Merge branch '2020-06-15-misc-bugfixes'
[oweals/u-boot.git] / drivers / timer / omap-timer.c
index 7422e0a653059565d62359833f0dbad6e6c67679..700c349f371631e6a38c47b6f3f3a97cee631a16 100644 (file)
@@ -1,9 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * TI OMAP timer driver
  *
  * Copyright (C) 2015, Texas Instruments, Incorporated
- *
- * SPDX-License-Identifier: GPL-2.0+
  */
 
 #include <common.h>
@@ -12,8 +11,7 @@
 #include <timer.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
-
-DECLARE_GLOBAL_DATA_PTR;
+#include <linux/bitops.h>
 
 /* Timer register bits */
 #define TCLR_START                     BIT(0)  /* Start=1 */
@@ -54,7 +52,7 @@ static int omap_timer_get_count(struct udevice *dev, u64 *count)
 {
        struct omap_timer_priv *priv = dev_get_priv(dev);
 
-       *count = readl(&priv->regs->tcrr);
+       *count = timer_conv_64(readl(&priv->regs->tcrr));
 
        return 0;
 }
@@ -64,10 +62,12 @@ 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;
+       if (!uc_priv->clock_rate)
+               uc_priv->clock_rate = TIMER_CLOCK;
 
        /* start the counter ticking up, reload value on overflow */
        writel(0, &priv->regs->tldr);
+       writel(0, &priv->regs->tcrr);
        /* enable timer */
        writel((CONFIG_SYS_PTV << 2) | TCLR_PRE_EN | TCLR_AUTO_RELOAD |
               TCLR_START, &priv->regs->tclr);
@@ -79,7 +79,7 @@ static int omap_timer_ofdata_to_platdata(struct udevice *dev)
 {
        struct omap_timer_priv *priv = dev_get_priv(dev);
 
-       priv->regs = map_physmem(dev_get_addr(dev),
+       priv->regs = map_physmem(devfdt_get_addr(dev),
                                 sizeof(struct omap_gptimer_regs), MAP_NOCACHE);
 
        return 0;
@@ -105,5 +105,4 @@ U_BOOT_DRIVER(omap_timer) = {
        .priv_auto_alloc_size = sizeof(struct omap_timer_priv),
        .probe = omap_timer_probe,
        .ops    = &omap_timer_ops,
-       .flags = DM_FLAG_PRE_RELOC,
 };