From: Alexey Charkov <alchark@gmail.com>
To: Krzysztof Kozlowski <krzk@kernel.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
Rob Herring <robh@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Wim Van Sebroeck <wim@linux-watchdog.org>,
Guenter Roeck <linux@roeck-us.net>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
linux-watchdog@vger.kernel.org,
Alexey Charkov <alchark@gmail.com>
Subject: [PATCH v4 2/4] clocksource/drivers/timer-vt8500: Add defines for magic constants
Date: Wed, 21 May 2025 00:01:42 +0400 [thread overview]
Message-ID: <20250521-vt8500-timer-updates-v4-2-2d4306a16ae4@gmail.com> (raw)
In-Reply-To: <20250521-vt8500-timer-updates-v4-0-2d4306a16ae4@gmail.com>
Add defines for all known registers and their bits to make the code more
self-explanatory. While at that, replace _VAL suffixes with more
intuitive _REG suffixes on register offsets.
No functional changes.
Signed-off-by: Alexey Charkov <alchark@gmail.com>
---
drivers/clocksource/timer-vt8500.c | 65 ++++++++++++++++++++++++--------------
1 file changed, 42 insertions(+), 23 deletions(-)
diff --git a/drivers/clocksource/timer-vt8500.c b/drivers/clocksource/timer-vt8500.c
index a469b1b5f97233202bf01298b9f612e07026c20c..9f28f30dcaf83ab4e9c89952175b0d4c75bd6b40 100644
--- a/drivers/clocksource/timer-vt8500.c
+++ b/drivers/clocksource/timer-vt8500.c
@@ -24,15 +24,31 @@
#define VT8500_TIMER_OFFSET 0x0100
#define VT8500_TIMER_HZ 3000000
-#define TIMER_MATCH_VAL 0x0000
-#define TIMER_COUNT_VAL 0x0010
-#define TIMER_STATUS_VAL 0x0014
-#define TIMER_IER_VAL 0x001c /* interrupt enable */
-#define TIMER_CTRL_VAL 0x0020
-#define TIMER_AS_VAL 0x0024 /* access status */
-#define TIMER_COUNT_R_ACTIVE (1 << 5) /* not ready for read */
-#define TIMER_COUNT_W_ACTIVE (1 << 4) /* not ready for write */
-#define TIMER_MATCH_W_ACTIVE (1 << 0) /* not ready for write */
+
+#define TIMER_MATCH_REG(x) (4 * (x))
+#define TIMER_COUNT_REG 0x0010 /* clocksource counter */
+
+#define TIMER_STATUS_REG 0x0014
+#define TIMER_STATUS_MATCH(x) BIT((x))
+#define TIMER_STATUS_CLEARALL (TIMER_STATUS_MATCH(0) | \
+ TIMER_STATUS_MATCH(1) | \
+ TIMER_STATUS_MATCH(2) | \
+ TIMER_STATUS_MATCH(3))
+
+#define TIMER_WATCHDOG_EN_REG 0x0018
+#define TIMER_WD_EN BIT(0)
+
+#define TIMER_INT_EN_REG 0x001c /* interrupt enable */
+#define TIMER_INT_EN_MATCH(x) BIT((x))
+
+#define TIMER_CTRL_REG 0x0020
+#define TIMER_CTRL_ENABLE BIT(0) /* enable clocksource counter */
+#define TIMER_CTRL_RD_REQ BIT(1) /* request counter read */
+
+#define TIMER_ACC_STS_REG 0x0024 /* access status */
+#define TIMER_ACC_WR_MATCH(x) BIT((x)) /* writing Match (x) value */
+#define TIMER_ACC_WR_COUNTER BIT(4) /* writing clocksource counter */
+#define TIMER_ACC_RD_COUNTER BIT(5) /* reading clocksource counter */
#define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
@@ -43,11 +59,12 @@ static void __iomem *regbase;
static u64 vt8500_timer_read(struct clocksource *cs)
{
int loops = msecs_to_loops(10);
- writel(3, regbase + TIMER_CTRL_VAL);
- while ((readl((regbase + TIMER_AS_VAL)) & TIMER_COUNT_R_ACTIVE)
- && --loops)
+
+ writel(TIMER_CTRL_ENABLE | TIMER_CTRL_RD_REQ, regbase + TIMER_CTRL_REG);
+ while (readl(regbase + TIMER_ACC_STS_REG) & TIMER_ACC_RD_COUNTER
+ && --loops)
cpu_relax();
- return readl(regbase + TIMER_COUNT_VAL);
+ return readl(regbase + TIMER_COUNT_REG);
}
static struct clocksource clocksource = {
@@ -63,23 +80,25 @@ static int vt8500_timer_set_next_event(unsigned long cycles,
{
int loops = msecs_to_loops(10);
u64 alarm = clocksource.read(&clocksource) + cycles;
- while ((readl(regbase + TIMER_AS_VAL) & TIMER_MATCH_W_ACTIVE)
- && --loops)
+
+ while (readl(regbase + TIMER_ACC_STS_REG) & TIMER_ACC_WR_MATCH(0)
+ && --loops)
cpu_relax();
- writel((unsigned long)alarm, regbase + TIMER_MATCH_VAL);
+ writel((unsigned long)alarm, regbase + TIMER_MATCH_REG(0));
if ((signed)(alarm - clocksource.read(&clocksource)) <= MIN_OSCR_DELTA)
return -ETIME;
- writel(1, regbase + TIMER_IER_VAL);
+ writel(TIMER_INT_EN_MATCH(0), regbase + TIMER_INT_EN_REG);
return 0;
}
static int vt8500_shutdown(struct clock_event_device *evt)
{
- writel(readl(regbase + TIMER_CTRL_VAL) | 1, regbase + TIMER_CTRL_VAL);
- writel(0, regbase + TIMER_IER_VAL);
+ writel(readl(regbase + TIMER_CTRL_REG) | TIMER_CTRL_ENABLE,
+ regbase + TIMER_CTRL_REG);
+ writel(0, regbase + TIMER_INT_EN_REG);
return 0;
}
@@ -95,7 +114,7 @@ static struct clock_event_device clockevent = {
static irqreturn_t vt8500_timer_interrupt(int irq, void *dev_id)
{
struct clock_event_device *evt = dev_id;
- writel(0xf, regbase + TIMER_STATUS_VAL);
+ writel(TIMER_STATUS_CLEARALL, regbase + TIMER_STATUS_REG);
evt->event_handler(evt);
return IRQ_HANDLED;
@@ -119,9 +138,9 @@ static int __init vt8500_timer_init(struct device_node *np)
return -EINVAL;
}
- writel(1, regbase + TIMER_CTRL_VAL);
- writel(0xf, regbase + TIMER_STATUS_VAL);
- writel(~0, regbase + TIMER_MATCH_VAL);
+ writel(TIMER_CTRL_ENABLE, regbase + TIMER_CTRL_REG);
+ writel(TIMER_STATUS_CLEARALL, regbase + TIMER_STATUS_REG);
+ writel(~0, regbase + TIMER_MATCH_REG(0));
ret = clocksource_register_hz(&clocksource, VT8500_TIMER_HZ);
if (ret) {
--
2.49.0
next prev parent reply other threads:[~2025-05-20 20:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-20 20:01 [PATCH v4 0/4] clocksource/drivers/timer-vt8500: clean up and add watchdog function Alexey Charkov
2025-05-20 20:01 ` [PATCH v4 1/4] dt-bindings: timer: via,vt8500-timer: Convert to YAML Alexey Charkov
2025-05-20 20:01 ` Alexey Charkov [this message]
2025-05-20 20:01 ` [PATCH v4 3/4] clocksource/drivers/timer-vt8500: Prepare for watchdog functionality Alexey Charkov
2025-05-20 20:01 ` [PATCH v4 4/4] watchdog: Add support for VIA/WonderMedia SoC " Alexey Charkov
2025-05-20 23:15 ` Guenter Roeck
2025-05-21 6:20 ` Alexey Charkov
2025-05-21 13:33 ` Guenter Roeck
2025-05-21 14:15 ` Alexey Charkov
2025-05-21 20:03 ` Guenter Roeck
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=20250521-vt8500-timer-updates-v4-2-2d4306a16ae4@gmail.com \
--to=alchark@gmail.com \
--cc=conor+dt@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=robh@kernel.org \
--cc=tglx@linutronix.de \
--cc=wim@linux-watchdog.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;
as well as URLs for NNTP newsgroup(s).