]> git.baikalelectronics.ru Git - uboot.git/commitdiff
timer: sti: convert sti-timer to arm a9 global timer
authorWilliam Zhang <william.zhang@broadcom.com>
Wed, 24 Aug 2022 04:44:32 +0000 (21:44 -0700)
committerTom Rini <trini@konsulko.com>
Mon, 31 Oct 2022 12:55:59 +0000 (08:55 -0400)
STI timer is actually ARM Cortex A9 global timer. Convert the driver to
use generic global timer name and make it consistent with Linux kernel
global timer driver. This also allows any A9 based device to use this
driver.

Signed-off-by: William Zhang <william.zhang@broadcom.com>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com>
MAINTAINERS
drivers/timer/Kconfig
drivers/timer/Makefile
drivers/timer/arm_global_timer.c [new file with mode: 0644]
drivers/timer/sti-timer.c [deleted file]

index 03fc6c5c283d6f937557cbb8e6d76cad9400d58c..1cf99c13934efc40c73ff2579e07b5f2cf00cad1 100644 (file)
@@ -510,7 +510,7 @@ F:  drivers/mmc/sti_sdhci.c
 F:     drivers/reset/sti-reset.c
 F:     drivers/serial/serial_sti_asc.c
 F:     drivers/sysreset/sysreset_sti.c
-F:     drivers/timer/sti-timer.c
+F:     drivers/timer/arm_global_timer.c
 F:     drivers/usb/host/dwc3-sti-glue.c
 F:     include/dwc3-sti-glue.h
 F:     include/dt-bindings/clock/stih407-clks.h
index fd8745ffc2e0ef53382c1b49199bbfa8120879a3..3b2fa2489b3561644320cef7f08356350d88cf1c 100644 (file)
@@ -230,12 +230,14 @@ config SANDBOX_TIMER
          Select this to enable an emulated timer for sandbox. It gets
          time from host os.
 
-config STI_TIMER
-       bool "STi timer support"
+config ARM_GLOBAL_TIMER
+       bool "ARM Cortex A9 global timer support"
        depends on TIMER
+       depends on ARM
        default y if ARCH_STI
        help
-         Select this to enable a timer for STi devices.
+         Select this to enable global timer found on ARM Cortex A9
+         based devices.
 
 config STM32_TIMER
        bool "STM32 timer support"
index 7bfb7749e97939db49dc4cfbb8d96cb106e2f251..bc8b2c0bd04dd009438390995312c9369d8930bf 100644 (file)
@@ -24,7 +24,7 @@ obj-$(CONFIG_RISCV_TIMER) += riscv_timer.o
 obj-$(CONFIG_ROCKCHIP_TIMER) += rockchip_timer.o
 obj-$(CONFIG_SANDBOX_TIMER)    += sandbox_timer.o
 obj-$(CONFIG_$(SPL_)SIFIVE_CLINT) += sifive_clint_timer.o
-obj-$(CONFIG_STI_TIMER)                += sti-timer.o
+obj-$(CONFIG_ARM_GLOBAL_TIMER) += arm_global_timer.o
 obj-$(CONFIG_STM32_TIMER)      += stm32_timer.o
 obj-$(CONFIG_X86_TSC_TIMER)    += tsc_timer.o
 obj-$(CONFIG_MTK_TIMER)                += mtk_timer.o
diff --git a/drivers/timer/arm_global_timer.c b/drivers/timer/arm_global_timer.c
new file mode 100644 (file)
index 0000000..065f10b
--- /dev/null
@@ -0,0 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
+ * Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics.
+ *
+ * ARM Cortext A9 global timer driver
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <clk.h>
+#include <timer.h>
+#include <linux/err.h>
+
+#include <asm/io.h>
+#include <asm/arch-armv7/globaltimer.h>
+
+struct arm_global_timer_priv {
+       struct globaltimer *global_timer;
+};
+
+static u64 arm_global_timer_get_count(struct udevice *dev)
+{
+       struct arm_global_timer_priv *priv = dev_get_priv(dev);
+       struct globaltimer *global_timer = priv->global_timer;
+       u32 low, high;
+       u64 timer;
+       u32 old = readl(&global_timer->cnt_h);
+
+       while (1) {
+               low = readl(&global_timer->cnt_l);
+               high = readl(&global_timer->cnt_h);
+               if (old == high)
+                       break;
+               else
+                       old = high;
+       }
+       timer = high;
+       return (u64)((timer << 32) | low);
+}
+
+static int arm_global_timer_probe(struct udevice *dev)
+{
+       struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+       struct arm_global_timer_priv *priv = dev_get_priv(dev);
+       struct clk clk;
+       int err;
+       ulong ret;
+
+       /* get arm global timer base address */
+       priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
+       if (!priv->global_timer)
+               return -ENOENT;
+
+       err = clk_get_by_index(dev, 0, &clk);
+       if (!err) {
+               ret = clk_get_rate(&clk);
+               if (IS_ERR_VALUE(ret))
+                       return ret;
+               uc_priv->clock_rate = ret;
+       } else {
+               uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
+       }
+
+       /* init timer */
+       writel(0x01, &priv->global_timer->ctl);
+
+       return 0;
+}
+
+static const struct timer_ops arm_global_timer_ops = {
+       .get_count = arm_global_timer_get_count,
+};
+
+static const struct udevice_id arm_global_timer_ids[] = {
+       { .compatible = "arm,cortex-a9-global-timer" },
+       {}
+};
+
+U_BOOT_DRIVER(arm_global_timer) = {
+       .name = "arm_global_timer",
+       .id = UCLASS_TIMER,
+       .of_match = arm_global_timer_ids,
+       .priv_auto      = sizeof(struct arm_global_timer_priv),
+       .probe = arm_global_timer_probe,
+       .ops = &arm_global_timer_ops,
+};
diff --git a/drivers/timer/sti-timer.c b/drivers/timer/sti-timer.c
deleted file mode 100644 (file)
index 87444a0..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
- * Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics.
- */
-
-#include <common.h>
-#include <dm.h>
-#include <clk.h>
-#include <timer.h>
-#include <linux/err.h>
-
-#include <asm/io.h>
-#include <asm/arch-armv7/globaltimer.h>
-
-struct sti_timer_priv {
-       struct globaltimer *global_timer;
-};
-
-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;
-       u32 low, high;
-       u64 timer;
-       u32 old = readl(&global_timer->cnt_h);
-
-       while (1) {
-               low = readl(&global_timer->cnt_l);
-               high = readl(&global_timer->cnt_h);
-               if (old == high)
-                       break;
-               else
-                       old = high;
-       }
-       timer = high;
-       return (u64)((timer << 32) | low);
-}
-
-static int sti_timer_probe(struct udevice *dev)
-{
-       struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
-       struct sti_timer_priv *priv = dev_get_priv(dev);
-       struct clk clk;
-       int err;
-       ulong ret;
-
-       /* get arm global timer base address */
-       priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
-       if (!priv->global_timer)
-               return -ENOENT;
-
-       err = clk_get_by_index(dev, 0, &clk);
-       if (!err) {
-               ret = clk_get_rate(&clk);
-               if (IS_ERR_VALUE(ret))
-                       return ret;
-               uc_priv->clock_rate = ret;
-       } else {
-               uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
-       }
-
-       /* init timer */
-       writel(0x01, &priv->global_timer->ctl);
-
-       return 0;
-}
-
-static const struct timer_ops sti_timer_ops = {
-       .get_count = sti_timer_get_count,
-};
-
-static const struct udevice_id sti_timer_ids[] = {
-       { .compatible = "arm,cortex-a9-global-timer" },
-       {}
-};
-
-U_BOOT_DRIVER(sti_timer) = {
-       .name = "sti_timer",
-       .id = UCLASS_TIMER,
-       .of_match = sti_timer_ids,
-       .priv_auto      = sizeof(struct sti_timer_priv),
-       .probe = sti_timer_probe,
-       .ops = &sti_timer_ops,
-};