mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [RFC 1/4] clocksource: add sc6531e driver
Date: Sat, 10 Jun 2023 13:32:17 +0300	[thread overview]
Message-ID: <20230610103220.566369-2-antonynpavlov@gmail.com> (raw)
In-Reply-To: <20230610103220.566369-1-antonynpavlov@gmail.com>

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 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 <antonynpavlov@gmail.com>
+ *
+ * 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	other threads:[~2023-06-10 10:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-10 10:32 [RFC 0/4] Run barebox on sc6531e-based feature phone Antony Pavlov
2023-06-10 10:32 ` Antony Pavlov [this message]
2023-06-10 10:32 ` [RFC 2/4] ARM: add sc6531e and F+ Ezzy 4 phone support Antony Pavlov
2023-06-10 10:32 ` [RFC 3/4] sc6531e: add debug_ll support Antony Pavlov
2023-06-10 10:32 ` [RFC 4/4] Documentation: add sc6531e instructions Antony Pavlov
2023-07-04 12:03 ` [RFC 0/4] Run barebox on sc6531e-based feature phone Sascha Hauer
2023-07-05  9:37   ` Antony Pavlov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230610103220.566369-2-antonynpavlov@gmail.com \
    --to=antonynpavlov@gmail.com \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox