Signed-off-by: Antony Pavlov <[email protected]>
---
 drivers/clocksource/Makefile        |  1 +
 drivers/clocksource/timer-sc6531e.c | 70 +++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index eceaa990d43..863a7e931cf 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -26,3 +26,4 @@ obj-$(CONFIG_CLINT_TIMER) += timer-clint.o
 obj-$(CONFIG_RISCV_TIMER) += timer-riscv.o
 obj-$(CONFIG_ARMV7M_SYSTICK) += armv7m_systick.o
 obj-$(CONFIG_CLKSRC_STM32) += timer-stm32.o
+obj-$(CONFIG_ARCH_SC6531E) += timer-sc6531e.o
diff --git a/drivers/clocksource/timer-sc6531e.c 
b/drivers/clocksource/timer-sc6531e.c
new file mode 100644
index 00000000000..c5f095f1a2e
--- /dev/null
+++ b/drivers/clocksource/timer-sc6531e.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 Antony Pavlov <[email protected]>
+ *
+ * This file is part of barebox.
+ */
+
+#include <common.h>
+#include <io.h>
+#include <init.h>
+#include <clock.h>
+#include <linux/err.h>
+
+#include <debug_ll.h>
+
+#define SC6531E_TIMER_CLOCK 1000
+
+#define SYST_VALUE_SHDW 0x0c
+
+static void __iomem *timer_base;
+
+static uint64_t sc6531e_cs_read(void)
+{
+       return (uint64_t)readl(timer_base + SYST_VALUE_SHDW);
+}
+
+static struct clocksource sc6531e_cs = {
+       .read   = sc6531e_cs_read,
+       .mask   = CLOCKSOURCE_MASK(32),
+       .priority = 60,
+};
+
+static int sc6531e_timer_probe(struct device *dev)
+{
+       struct resource *iores;
+
+       /* use only one timer */
+       if (timer_base)
+               return -EBUSY;
+
+       iores = dev_request_mem_resource(dev, 0);
+       if (IS_ERR(iores)) {
+               dev_err(dev, "could not get memory region\n");
+               return PTR_ERR(iores);
+       }
+
+       timer_base = IOMEM(iores->start);
+       clocks_calc_mult_shift(&sc6531e_cs.mult, &sc6531e_cs.shift,
+               SC6531E_TIMER_CLOCK, NSEC_PER_SEC, 1);
+
+       init_clock(&sc6531e_cs);
+
+       return 0;
+}
+
+static __maybe_unused struct of_device_id sc6531e_timer_dt_ids[] = {
+       {
+               .compatible = "sc6531e-timer",
+       }, {
+               /* sentinel */
+       }
+};
+
+static struct driver sc6531e_timer_driver = {
+       .probe  = sc6531e_timer_probe,
+       .name   = "sc6531e-timer",
+       .of_compatible = DRV_OF_COMPAT(sc6531e_timer_dt_ids),
+};
+
+coredevice_platform_driver(sc6531e_timer_driver);
-- 
2.39.0


Reply via email to