]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
timer: Return count from timer_ops.get_count
authorSean Anderson <seanga2@gmail.com>
Wed, 7 Oct 2020 18:37:44 +0000 (14:37 -0400)
committerTom Rini <trini@konsulko.com>
Thu, 22 Oct 2020 13:54:53 +0000 (09:54 -0400)
No timer drivers return an error from get_count. Instead of possibly
returning an error, just return the count directly.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
24 files changed:
arch/riscv/lib/andes_plmt.c
arch/riscv/lib/sifive_clint.c
drivers/timer/ag101p_timer.c
drivers/timer/altera_timer.c
drivers/timer/arc_timer.c
drivers/timer/ast_timer.c
drivers/timer/atcpit100_timer.c
drivers/timer/atmel_pit_timer.c
drivers/timer/cadence-ttc.c
drivers/timer/dw-apb-timer.c
drivers/timer/mchp-pit64b-timer.c
drivers/timer/mpc83xx_timer.c
drivers/timer/mtk_timer.c
drivers/timer/nomadik-mtu-timer.c
drivers/timer/omap-timer.c
drivers/timer/ostm_timer.c
drivers/timer/riscv_timer.c
drivers/timer/rockchip_timer.c
drivers/timer/sandbox_timer.c
drivers/timer/sti-timer.c
drivers/timer/stm32_timer.c
drivers/timer/timer-uclass.c
drivers/timer/tsc_timer.c
include/timer.h

index a28c14c1ebf2c17735c122efe1de2d91840f1c68..cec86718c7f73566e032c8e59d14d983b3c826c3 100644 (file)
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base))
 
-static int andes_plmt_get_count(struct udevice *dev, u64 *count)
+static u64 andes_plmt_get_count(struct udevice *dev)
 {
-       *count = readq((void __iomem *)MTIME_REG(dev->priv));
-
-       return 0;
+       return readq((void __iomem *)MTIME_REG(dev->priv));
 }
 
 static const struct timer_ops andes_plmt_ops = {
index c9704c596fa6707ceef1186b8e6a55d8f50ce806..a5572cb82551a6d88f99d95cffdf6c89c874cee9 100644 (file)
@@ -62,11 +62,9 @@ int riscv_get_ipi(int hart, int *pending)
        return 0;
 }
 
-static int sifive_clint_get_count(struct udevice *dev, u64 *count)
+static u64 sifive_clint_get_count(struct udevice *dev)
 {
-       *count = readq((void __iomem *)MTIME_REG(dev->priv));
-
-       return 0;
+       return readq((void __iomem *)MTIME_REG(dev->priv));
 }
 
 static const struct timer_ops sifive_clint_ops = {
index c011906b938dc6317b6dc945c2a108b862b0877a..23ad5b2b67abe821de336e1615bb7e5f1d9547df 100644 (file)
@@ -62,14 +62,13 @@ struct atftmr_timer_platdata {
        struct atftmr_timer_regs *regs;
 };
 
-static int atftmr_timer_get_count(struct udevice *dev, u64 *count)
+static u64 atftmr_timer_get_count(struct udevice *dev)
 {
        struct atftmr_timer_platdata *plat = dev->platdata;
        struct atftmr_timer_regs *const regs = plat->regs;
        u32 val;
        val = readl(&regs->t3_counter);
-       *count = timer_conv_64(val);
-       return 0;
+       return timer_conv_64(val);
 }
 
 static int atftmr_timer_probe(struct udevice *dev)
index 6cb2923e0b651047de53d4668b149d015180861c..ccc164ee17629260f835d8091e060f0739f76766 100644 (file)
@@ -32,7 +32,7 @@ struct altera_timer_platdata {
        struct altera_timer_regs *regs;
 };
 
-static int altera_timer_get_count(struct udevice *dev, u64 *count)
+static u64 altera_timer_get_count(struct udevice *dev)
 {
        struct altera_timer_platdata *plat = dev->platdata;
        struct altera_timer_regs *const regs = plat->regs;
@@ -44,9 +44,7 @@ static int altera_timer_get_count(struct udevice *dev, u64 *count)
        /* Read timer value */
        val = readl(&regs->snapl) & 0xffff;
        val |= (readl(&regs->snaph) & 0xffff) << 16;
-       *count = timer_conv_64(~val);
-
-       return 0;
+       return timer_conv_64(~val);
 }
 
 static int altera_timer_probe(struct udevice *dev)
index 8c574ec5af1d8a46e02b50978b2f43f1f54b4b8b..2dea9f40cba8e9814a66a373a20461d252173e85 100644 (file)
@@ -26,7 +26,7 @@ struct arc_timer_priv {
                uint timer_id;
 };
 
-static int arc_timer_get_count(struct udevice *dev, u64 *count)
+static u64 arc_timer_get_count(struct udevice *dev)
 {
        u32 val = 0;
        struct arc_timer_priv *priv = dev_get_priv(dev);
@@ -39,9 +39,7 @@ static int arc_timer_get_count(struct udevice *dev, u64 *count)
                val = read_aux_reg(ARC_AUX_TIMER1_CNT);
                break;
        }
-       *count = timer_conv_64(val);
-
-       return 0;
+       return timer_conv_64(val);
 }
 
 static int arc_timer_probe(struct udevice *dev)
index e3132497404de40e5517920490d19e420e7624ea..35369a4087f56858350623954877305f056a6b06 100644 (file)
@@ -51,13 +51,11 @@ static int ast_timer_probe(struct udevice *dev)
        return 0;
 }
 
-static int ast_timer_get_count(struct udevice *dev, u64 *count)
+static u64 ast_timer_get_count(struct udevice *dev)
 {
        struct ast_timer_priv *priv = dev_get_priv(dev);
 
-       *count = AST_TMC_RELOAD_VAL - readl(&priv->tmc->status);
-
-       return 0;
+       return AST_TMC_RELOAD_VAL - readl(&priv->tmc->status);
 }
 
 static int ast_timer_ofdata_to_platdata(struct udevice *dev)
index 5d4ae68509270288be0c413db7aa08d0ba78e967..fcb8a45358142eb1461f31c629919a96f2dbde5c 100644 (file)
@@ -68,13 +68,12 @@ struct atcpit_timer_platdata {
        u32 *regs;
 };
 
-static int atcpit_timer_get_count(struct udevice *dev, u64 *count)
+static u64 atcpit_timer_get_count(struct udevice *dev)
 {
        struct atcpit_timer_platdata *plat = dev_get_platdata(dev);
        u32 val;
        val = ~(REG32_TMR(CH_CNT(1))+0xffffffff);
-       *count = timer_conv_64(val);
-       return 0;
+       return timer_conv_64(val);
 }
 
 static int atcpit_timer_probe(struct udevice *dev)
index 843d670b5e22921c86e30795f0c6f194c3b78d41..9f0ad1d703f88d8d7d6ebba15734b1ac60fe6d55 100644 (file)
@@ -25,15 +25,13 @@ struct atmel_pit_platdata {
        struct atmel_pit_regs *regs;
 };
 
-static int atmel_pit_get_count(struct udevice *dev, u64 *count)
+static u64 atmel_pit_get_count(struct udevice *dev)
 {
        struct atmel_pit_platdata *plat = dev_get_platdata(dev);
        struct atmel_pit_regs *const regs = plat->regs;
        u32 val = readl(&regs->value_image);
 
-       *count = timer_conv_64(val);
-
-       return 0;
+       return timer_conv_64(val);
 }
 
 static int atmel_pit_probe(struct udevice *dev)
index e6b6dfe3765c3bec2c96a2662556fe221bb3e550..bebb2c2e904d44752a21650d94e5aa0b6fe2fc77 100644 (file)
@@ -57,13 +57,11 @@ ulong timer_get_boot_us(void)
 }
 #endif
 
-static int cadence_ttc_get_count(struct udevice *dev, u64 *count)
+static u64 cadence_ttc_get_count(struct udevice *dev)
 {
        struct cadence_ttc_priv *priv = dev_get_priv(dev);
 
-       *count = readl(&priv->regs->counter_val1);
-
-       return 0;
+       return readl(&priv->regs->counter_val1);
 }
 
 static int cadence_ttc_probe(struct udevice *dev)
index 35271b20c891e9585cf95bb16ca5e42177a0435b..68bc258131be5e1d8dfc0100a2b774e22a3467f8 100644 (file)
@@ -25,7 +25,7 @@ struct dw_apb_timer_priv {
        struct reset_ctl_bulk resets;
 };
 
-static int dw_apb_timer_get_count(struct udevice *dev, u64 *count)
+static u64 dw_apb_timer_get_count(struct udevice *dev)
 {
        struct dw_apb_timer_priv *priv = dev_get_priv(dev);
 
@@ -34,9 +34,7 @@ static int dw_apb_timer_get_count(struct udevice *dev, u64 *count)
         * requires the count to be incrementing. Invert the
         * result.
         */
-       *count = timer_conv_64(~readl(priv->regs + DW_APB_CURR_VAL));
-
-       return 0;
+       return timer_conv_64(~readl(priv->regs + DW_APB_CURR_VAL));
 }
 
 static int dw_apb_timer_probe(struct udevice *dev)
index ead8c9b84ad55a078c64bea6a4c5d29d30cc5078..ad962098b3d017bd09f395805cfffbfe3ca33539 100644 (file)
@@ -27,16 +27,14 @@ struct mchp_pit64b_priv {
        void __iomem *base;
 };
 
-static int mchp_pit64b_get_count(struct udevice *dev, u64 *count)
+static u64 mchp_pit64b_get_count(struct udevice *dev)
 {
        struct mchp_pit64b_priv *priv = dev_get_priv(dev);
 
        u32 lsb = readl(priv->base + MCHP_PIT64B_TLSBR);
        u32 msb = readl(priv->base + MCHP_PIT64B_TMSBR);
 
-       *count = ((u64)msb << 32) | lsb;
-
-       return 0;
+       return ((u64)msb << 32) | lsb;
 }
 
 static int mchp_pit64b_probe(struct udevice *dev)
index ad8bb28e8b39d7989df7b4f4ccb5b9bb7ad9faae..ba7704225a367fb25b331496d12e1caa63c15eba 100644 (file)
@@ -187,7 +187,7 @@ void wait_ticks(ulong ticks)
                WATCHDOG_RESET();
 }
 
-static int mpc83xx_timer_get_count(struct udevice *dev, u64 *count)
+static u64 mpc83xx_timer_get_count(struct udevice *dev)
 {
        u32 tbu, tbl;
 
@@ -201,9 +201,7 @@ static int mpc83xx_timer_get_count(struct udevice *dev, u64 *count)
                tbl = mftb();
        } while (tbu != mftbu());
 
-       *count = (tbu * 0x10000ULL) + tbl;
-
-       return 0;
+       return (tbu * 0x10000ULL) + tbl;
 }
 
 static int mpc83xx_timer_probe(struct udevice *dev)
index 69ed521811d2a777d4eae9860b3442b54213d8cd..74e9ea34ffa3fc1cad09f78da8bdd7ff2581b796 100644 (file)
@@ -27,14 +27,12 @@ struct mtk_timer_priv {
        void __iomem *base;
 };
 
-static int mtk_timer_get_count(struct udevice *dev, u64 *count)
+static u64 mtk_timer_get_count(struct udevice *dev)
 {
        struct mtk_timer_priv *priv = dev_get_priv(dev);
        u32 val = readl(priv->base + MTK_GPT4_CNT);
 
-       *count = timer_conv_64(val);
-
-       return 0;
+       return timer_conv_64(val);
 }
 
 static int mtk_timer_probe(struct udevice *dev)
index 7ff921385a3305144a1bdf5b3bc3ec60963ff38e..d7f7ca4effd2b8a55a4a34d0789e630983f513e5 100644 (file)
@@ -54,14 +54,12 @@ struct nomadik_mtu_priv {
        struct nomadik_mtu_timer_regs *timer;
 };
 
-static int nomadik_mtu_get_count(struct udevice *dev, u64 *count)
+static u64 nomadik_mtu_get_count(struct udevice *dev)
 {
        struct nomadik_mtu_priv *priv = dev_get_priv(dev);
 
        /* Decrementing counter: invert the value */
-       *count = timer_conv_64(~readl(&priv->timer->cv));
-
-       return 0;
+       return timer_conv_64(~readl(&priv->timer->cv));
 }
 
 static int nomadik_mtu_probe(struct udevice *dev)
index cf3d27b96bc2373e88317c64cf710c9414157904..4eecb3e64d26681d6d1fb85402a04c55203fd840 100644 (file)
@@ -48,13 +48,11 @@ struct omap_timer_priv {
        struct omap_gptimer_regs *regs;
 };
 
-static int omap_timer_get_count(struct udevice *dev, u64 *count)
+static u64 omap_timer_get_count(struct udevice *dev)
 {
        struct omap_timer_priv *priv = dev_get_priv(dev);
 
-       *count = timer_conv_64(readl(&priv->regs->tcrr));
-
-       return 0;
+       return timer_conv_64(readl(&priv->regs->tcrr));
 }
 
 static int omap_timer_probe(struct udevice *dev)
index bea97159ebe748d80922d16abd118663eb4c64b1..bb0636a0719eb3a8e2e3a59f60cba66ae3e8aa6c 100644 (file)
@@ -27,13 +27,11 @@ struct ostm_priv {
        fdt_addr_t      regs;
 };
 
-static int ostm_get_count(struct udevice *dev, u64 *count)
+static u64 ostm_get_count(struct udevice *dev)
 {
        struct ostm_priv *priv = dev_get_priv(dev);
 
-       *count = timer_conv_64(readl(priv->regs + OSTM_CNT));
-
-       return 0;
+       return timer_conv_64(readl(priv->regs + OSTM_CNT));
 }
 
 static int ostm_probe(struct udevice *dev)
index 449fcfcfd5964c4c201f56bc3f861084c14f3dfb..21ae1840571a23d29d12b494d89f5b8352b190a1 100644 (file)
 #include <timer.h>
 #include <asm/csr.h>
 
-static int riscv_timer_get_count(struct udevice *dev, u64 *count)
+static u64 riscv_timer_get_count(struct udevice *dev)
 {
-       if (IS_ENABLED(CONFIG_64BIT)) {
-               *count = csr_read(CSR_TIME);
-       } else {
-               u32 hi, lo;
+       __maybe_unused u32 hi, lo;
 
-               do {
-                       hi = csr_read(CSR_TIMEH);
-                       lo = csr_read(CSR_TIME);
-               } while (hi != csr_read(CSR_TIMEH));
+       if (IS_ENABLED(CONFIG_64BIT))
+               return csr_read(CSR_TIME);
 
-               *count = ((u64)hi << 32) | lo;
-       }
+       do {
+               hi = csr_read(CSR_TIMEH);
+               lo = csr_read(CSR_TIME);
+       } while (hi != csr_read(CSR_TIMEH));
 
-       return 0;
+       return ((u64)hi << 32) | lo;
 }
 
 static int riscv_timer_probe(struct udevice *dev)
index 7a5a48425277d47078e80b18b34cfd92647be2bf..53cdf09810d3ad397ecd1d1cd78537f50b6b7baf 100644 (file)
@@ -88,14 +88,13 @@ ulong timer_get_boot_us(void)
 }
 #endif
 
-static int rockchip_timer_get_count(struct udevice *dev, u64 *count)
+static u64 rockchip_timer_get_count(struct udevice *dev)
 {
        struct rockchip_timer_priv *priv = dev_get_priv(dev);
        uint64_t cntr = rockchip_timer_get_curr_value(priv->timer);
 
        /* timers are down-counting */
-       *count = ~0ull - cntr;
-       return 0;
+       return ~0ull - cntr;
 }
 
 static int rockchip_clk_ofdata_to_platdata(struct udevice *dev)
index 6a503c2f15359714cecd993efe64d5dd48c10f5f..135c0f38a4d69ccdfd8218158314ec73e16d9717 100644 (file)
@@ -29,11 +29,9 @@ unsigned long notrace timer_early_get_rate(void)
        return SANDBOX_TIMER_RATE;
 }
 
-static notrace int sandbox_timer_get_count(struct udevice *dev, u64 *count)
+static notrace u64 sandbox_timer_get_count(struct udevice *dev)
 {
-       *count = timer_early_get_count();
-
-       return 0;
+       return timer_early_get_count();
 }
 
 static int sandbox_timer_probe(struct udevice *dev)
index ff42056abdd1aa2f5abd2a9438272d820bad7ab3..e6843ebb3371b4012772255cc685614f2ca60cb2 100644 (file)
@@ -17,7 +17,7 @@ struct sti_timer_priv {
        struct globaltimer *global_timer;
 };
 
-static int sti_timer_get_count(struct udevice *dev, u64 *count)
+static u64 sti_timer_get_count(struct udevice *dev)
 {
        struct sti_timer_priv *priv = dev_get_priv(dev);
        struct globaltimer *global_timer = priv->global_timer;
@@ -34,9 +34,7 @@ static int sti_timer_get_count(struct udevice *dev, u64 *count)
                        old = high;
        }
        timer = high;
-       *count = (u64)((timer << 32) | low);
-
-       return 0;
+       return (u64)((timer << 32) | low);
 }
 
 static int sti_timer_probe(struct udevice *dev)
index c57fa3f557044a2823997ce0750887baeeef0d0b..f517d5e61f2149c30019ca755322e3479e62ff12 100644 (file)
@@ -52,14 +52,12 @@ struct stm32_timer_priv {
        struct stm32_timer_regs *base;
 };
 
-static int stm32_timer_get_count(struct udevice *dev, u64 *count)
+static u64 stm32_timer_get_count(struct udevice *dev)
 {
        struct stm32_timer_priv *priv = dev_get_priv(dev);
        struct stm32_timer_regs *regs = priv->base;
 
-       *count = readl(&regs->cnt);
-
-       return 0;
+       return readl(&regs->cnt);
 }
 
 static int stm32_timer_probe(struct udevice *dev)
index f8a092b8cb1a3aabe1c69dc47de63e77f37913cc..62d0e860e80c527aa9d982fe3cb44be1c4bf7cef 100644 (file)
@@ -34,7 +34,8 @@ int notrace timer_get_count(struct udevice *dev, u64 *count)
        if (!ops->get_count)
                return -ENOSYS;
 
-       return ops->get_count(dev, count);
+       *count = ops->get_count(dev);
+       return 0;
 }
 
 unsigned long notrace timer_get_rate(struct udevice *dev)
index 93c959ff44452c8e4bc5f834e5e7d9962e9a2382..abc0a1da05e985f5cbe0f30531f46f910f197e2a 100644 (file)
@@ -386,13 +386,11 @@ void __udelay(unsigned long usec)
 #endif
 }
 
-static int tsc_timer_get_count(struct udevice *dev, u64 *count)
+static u64 tsc_timer_get_count(struct udevice *dev)
 {
        u64 now_tick = rdtsc();
 
-       *count = now_tick - gd->arch.tsc_base;
-
-       return 0;
+       return now_tick - gd->arch.tsc_base;
 }
 
 static void tsc_timer_ensure_setup(bool early)
index aa9d870619d10eb5341967225ef37ae96ea28ab8..a044cb034ed0c4c343a1af40f637a2d2a7b01691 100644 (file)
@@ -67,11 +67,14 @@ struct timer_ops {
         *
         * @dev: The timer device
         *
-        * @count: pointer that returns the current 64-bit timer count
+        * This function may be called at any time after the driver is probed.
+        * All necessary initialization must be completed by the time probe()
+        * returns. The count returned by this functions should be monotonic.
+        * This function must succeed.
         *
-        * Return: 0 if OK, -ve on error
+        * Return: The current 64-bit timer count
         */
-       int (*get_count)(struct udevice *dev, u64 *count);
+       u64 (*get_count)(struct udevice *dev);
 };
 
 /**