From: nick.hawkins@hpe.com
To: verdun@hpe.com
Cc: Nick Hawkins <nick.hawkins@hpe.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org
Subject: [PATCH v3 04/10] clocksource/drivers: Add HPE GXP timer
Date: Thu, 10 Mar 2022 13:52:23 -0600 [thread overview]
Message-ID: <20220310195229.109477-4-nick.hawkins@hpe.com> (raw)
In-Reply-To: <20220310195229.109477-1-nick.hawkins@hpe.com>
From: Nick Hawkins <nick.hawkins@hpe.com>
Add support for the HPE GXP SOC timer. The GXP supports several
different kinds of timers but for the purpose of this driver there
is only support for the General Timer. The timer has a 1us
resolution and is 32 bits.
Signed-off-by: Nick Hawkins <nick.hawkins@hpe.com>
---
drivers/clocksource/Kconfig | 8 ++
drivers/clocksource/Makefile | 1 +
drivers/clocksource/gxp-timer.c | 159 ++++++++++++++++++++++++++++++++
3 files changed, 168 insertions(+)
create mode 100644 drivers/clocksource/gxp-timer.c
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index cfb8ea0df3b1..5916dade7608 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -617,6 +617,14 @@ config CLKSRC_ST_LPC
Enable this option to use the Low Power controller timer
as clocksource.
+config GXP_TIMER
+ bool "GXP timer driver"
+ depends on ARCH_HPE
+ default y
+ help
+ Provides a driver for the timer control found on HPE
+ GXP SOCs. This is required for all GXP SOCs.
+
config ATCPIT100_TIMER
bool "ATCPIT100 timer driver"
depends on NDS32 || COMPILE_TEST
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index fa5f624eadb6..dbfb8c56a8a0 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -89,3 +89,4 @@ obj-$(CONFIG_GX6605S_TIMER) += timer-gx6605s.o
obj-$(CONFIG_HYPERV_TIMER) += hyperv_timer.o
obj-$(CONFIG_MICROCHIP_PIT64B) += timer-microchip-pit64b.o
obj-$(CONFIG_MSC313E_TIMER) += timer-msc313e.o
+obj-$(CONFIG_GXP_TIMER) += gxp-timer.o
diff --git a/drivers/clocksource/gxp-timer.c b/drivers/clocksource/gxp-timer.c
new file mode 100644
index 000000000000..a24cd1cc5c04
--- /dev/null
+++ b/drivers/clocksource/gxp-timer.c
@@ -0,0 +1,159 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2022 Hewlett-Packard Enterprise Development Company, L.P.*/
+
+#include <linux/bitops.h>
+#include <linux/clockchips.h>
+#include <linux/clocksource.h>
+#include <linux/interrupt.h>
+#include <linux/irqreturn.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/of_platform.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/sched_clock.h>
+
+#include <asm/irq.h>
+
+#define TIMER0_FREQ 1000000
+
+/*TCS Stands for Timer Control/Status: these are masks to be used in*/
+/* the Timer Count Registers */
+#define MASK_TCS_ENABLE 0x01
+#define MASK_TCS_PERIOD 0x02
+#define MASK_TCS_RELOAD 0x04
+#define MASK_TCS_TC 0x80
+
+struct gxp_timer {
+ void __iomem *counter;
+ void __iomem *control;
+ struct clock_event_device evt;
+};
+
+static void __iomem *system_clock __read_mostly;
+
+static inline struct gxp_timer *to_gxp_timer(struct clock_event_device *evt_dev)
+{
+ return container_of(evt_dev, struct gxp_timer, evt);
+}
+
+static u64 notrace gxp_sched_read(void)
+{
+ return readl_relaxed(system_clock);
+}
+
+static int gxp_time_set_next_event(unsigned long event,
+ struct clock_event_device *evt_dev)
+{
+ struct gxp_timer *timer = to_gxp_timer(evt_dev);
+ /* Stop counting and disable interrupt before updating */
+ writeb_relaxed(MASK_TCS_TC, timer->control);
+ writel_relaxed(event, timer->counter);
+ writeb_relaxed(MASK_TCS_TC | MASK_TCS_ENABLE, timer->control);
+
+ return 0;
+}
+
+static irqreturn_t gxp_time_interrupt(int irq, void *dev_id)
+{
+ struct gxp_timer *timer = dev_id;
+ void (*event_handler)(struct clock_event_device *timer);
+
+ if (!(readb_relaxed(timer->control) & MASK_TCS_TC))
+ return IRQ_NONE;
+
+ writeb_relaxed(MASK_TCS_TC, timer->control);
+
+ event_handler = READ_ONCE(timer->evt.event_handler);
+ event_handler(&timer->evt);
+
+ return IRQ_HANDLED;
+}
+
+static int __init gxp_timer_init(struct device_node *node)
+{
+ void __iomem *base_counter;
+ void __iomem *base_control;
+ u32 freq;
+ int ret, irq;
+ struct gxp_timer *gxp_timer;
+
+ base_counter = of_iomap(node, 0);
+ if (!base_counter) {
+ pr_err("Can't remap counter registers");
+ ret = -ENXIO;
+ return ret;
+ }
+
+ base_control = of_iomap(node, 1);
+ if (!base_control) {
+ pr_err("Can't remap control registers");
+ ret = -ENXIO;
+ goto err_iounmap;
+ }
+
+ system_clock = of_iomap(node, 2);
+ if (!system_clock) {
+ pr_err("Can't remap control registers");
+ ret = -ENXIO;
+ goto err_iounmap;
+ }
+
+ if (of_property_read_u32(node, "clock-frequency", &freq)) {
+ pr_err("Can't read clock-frequency\n");
+ ret = -EIO;
+ goto err_iounmap;
+ }
+
+ sched_clock_register(gxp_sched_read, 32, freq);
+ clocksource_mmio_init(system_clock, node->name, freq,
+ 300, 32, clocksource_mmio_readl_up);
+
+ irq = irq_of_parse_and_map(node, 0);
+ if (irq <= 0) {
+ ret = -EINVAL;
+ pr_err("GXP Timer Can't parse IRQ %d", irq);
+ goto err_iounmap;
+ }
+
+ gxp_timer = kzalloc(sizeof(*gxp_timer), GFP_KERNEL);
+ if (!gxp_timer) {
+ ret = -ENOMEM;
+ goto err_iounmap;
+ }
+
+ gxp_timer->counter = base_counter;
+ gxp_timer->control = base_control;
+ gxp_timer->evt.name = node->name;
+ gxp_timer->evt.rating = 300;
+ gxp_timer->evt.features = CLOCK_EVT_FEAT_ONESHOT;
+ gxp_timer->evt.set_next_event = gxp_time_set_next_event;
+ gxp_timer->evt.cpumask = cpumask_of(0);
+
+ if (request_irq(irq, gxp_time_interrupt, IRQF_TIMER | IRQF_SHARED,
+ node->name, gxp_timer)) {
+ ret = -EIO;
+ pr_err("%s: request_irq() failed\n", "GXP Timer Tick");
+ goto err_timer_free;
+ }
+
+ clockevents_config_and_register(&gxp_timer->evt, TIMER0_FREQ,
+ 0xf, 0xffffffff);
+
+ pr_info("gxp: system timer (irq = %d)\n", irq);
+ return 0;
+
+
+err_timer_free:
+ kfree(gxp_timer);
+
+err_iounmap:
+ iounmap(system_clock);
+ iounmap(base_control);
+ iounmap(base_counter);
+ return ret;
+}
+
+TIMER_OF_DECLARE(gxp, "hpe,gxp-timer", gxp_timer_init);
--
2.17.1
next prev parent reply other threads:[~2022-03-10 19:50 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-10 19:52 [PATCH v3 01/10] arch: arm: mach-hpe: Introduce the HPE GXP architecture nick.hawkins
2022-03-10 19:52 ` [PATCH v3 02/10] arch: arm: configs: multi_v7_defconfig nick.hawkins
2022-03-10 19:52 ` [PATCH v3 03/10] drivers: wdt: Introduce HPE GXP SoC Watchdog nick.hawkins
2022-04-04 14:28 ` Guenter Roeck
2022-04-04 16:25 ` Hawkins, Nick
2022-04-04 16:41 ` Guenter Roeck
2022-03-10 19:52 ` nick.hawkins [this message]
2022-04-06 11:13 ` [PATCH v3 04/10] clocksource/drivers: Add HPE GXP timer Daniel Lezcano
2022-04-06 22:02 ` Hawkins, Nick
2022-03-10 19:52 ` [PATCH v3 05/10] dt-bindings: timer: Add HPE GXP Timer Binding nick.hawkins
2022-03-11 9:32 ` Krzysztof Kozlowski
2022-03-11 15:40 ` Rob Herring
2022-03-11 16:22 ` Hawkins, Nick
2022-03-11 17:13 ` Krzysztof Kozlowski
2022-03-10 19:52 ` [PATCH v3 06/10] dt-bindings: watchdog: Add HPE GXP Watchdog timer binding nick.hawkins
2022-03-11 9:34 ` Krzysztof Kozlowski
2022-03-10 19:52 ` [PATCH v3 07/10] dt-bindings: arm: Add HPE GXP Binding nick.hawkins
2022-03-11 10:20 ` Krzysztof Kozlowski
2022-03-10 19:52 ` [PATCH v3 08/10] dt-bindings: arm: Add HPE GXP CPU Init nick.hawkins
2022-03-11 10:22 ` Krzysztof Kozlowski
2022-03-16 21:33 ` Hawkins, Nick
2022-03-10 19:52 ` [PATCH v3 09/10] arch: arm: boot: dts: Introduce HPE GXP Device tree nick.hawkins
2022-03-11 8:17 ` Arnd Bergmann
2022-03-11 10:29 ` Krzysztof Kozlowski
2022-03-16 15:41 ` Hawkins, Nick
2022-03-16 15:50 ` Krzysztof Kozlowski
2022-03-16 20:10 ` Hawkins, Nick
2022-03-17 8:36 ` Krzysztof Kozlowski
2022-03-29 19:38 ` Hawkins, Nick
2022-03-29 21:13 ` Arnd Bergmann
2022-03-29 21:45 ` Hawkins, Nick
2022-03-30 22:27 ` Hawkins, Nick
2022-03-31 9:30 ` Arnd Bergmann
2022-03-31 21:09 ` Hawkins, Nick
2022-03-31 21:52 ` Arnd Bergmann
2022-04-01 16:05 ` Hawkins, Nick
2022-04-01 16:30 ` Arnd Bergmann
2022-04-04 20:22 ` Hawkins, Nick
2022-04-04 22:02 ` Arnd Bergmann
2022-04-05 21:21 ` Hawkins, Nick
2022-04-06 7:24 ` Arnd Bergmann
2022-04-13 16:48 ` Hawkins, Nick
2022-04-13 17:42 ` Arnd Bergmann
2022-03-10 19:52 ` [PATCH v3 10/10] maintainers: Introduce HPE GXP Architecture nick.hawkins
2022-03-11 10:33 ` Joe Perches
2022-03-11 7:21 ` [PATCH v3 01/10] arch: arm: mach-hpe: Introduce the HPE GXP architecture kernel test robot
2022-03-11 8:06 ` Arnd Bergmann
2022-03-11 12:40 ` kernel test robot
2022-03-12 13:27 ` kernel test robot
2022-03-12 15:14 ` Arnd Bergmann
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=20220310195229.109477-4-nick.hawkins@hpe.com \
--to=nick.hawkins@hpe.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=verdun@hpe.com \
/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
all inboxes | Powered by JetHome®