From: Maxime Ripard <maxime.ripard@free-electrons.com>
To: linux-arm-kernel@lists.infradead.org
Cc: kevin@allwinnertech.com, sunny@allwinnertech.com,
shuge@allwinnertech.com, John Stultz <john.stultz@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org
Subject: [PATCH 02/10] clocksource: sunxi: Cleanup the timer code
Date: Tue, 26 Mar 2013 10:13:09 +0100 [thread overview]
Message-ID: <1364289198-11589-3-git-send-email-maxime.ripard@free-electrons.com> (raw)
In-Reply-To: <1364289198-11589-1-git-send-email-maxime.ripard@free-electrons.com>
The timer code was not exact to some aspects, since most of this code
was written wihout any datasheet. Make the needed corrections to match
the datasheet.
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
drivers/clocksource/sunxi_timer.c | 48 ++++++++++++++++++-------------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/drivers/clocksource/sunxi_timer.c b/drivers/clocksource/sunxi_timer.c
index 0ce85e2..7a3ea23 100644
--- a/drivers/clocksource/sunxi_timer.c
+++ b/drivers/clocksource/sunxi_timer.c
@@ -25,15 +25,15 @@
#include <linux/sunxi_timer.h>
#include <linux/clk/sunxi.h>
-#define TIMER_CTL_REG 0x00
-#define TIMER_CTL_ENABLE (1 << 0)
+#define TIMER_IRQ_EN_REG 0x00
+#define TIMER_IRQ_EN(val) (1 << val)
#define TIMER_IRQ_ST_REG 0x04
-#define TIMER0_CTL_REG 0x10
-#define TIMER0_CTL_ENABLE (1 << 0)
-#define TIMER0_CTL_AUTORELOAD (1 << 1)
-#define TIMER0_CTL_ONESHOT (1 << 7)
-#define TIMER0_INTVAL_REG 0x14
-#define TIMER0_CNTVAL_REG 0x18
+#define TIMER_CTL_REG(val) (0x10 * val + 0x10)
+#define TIMER_CTL_ENABLE (1 << 0)
+#define TIMER_CTL_AUTORELOAD (1 << 1)
+#define TIMER_CTL_ONESHOT (1 << 7)
+#define TIMER_INTVAL_REG(val) (0x10 * val + 0x14)
+#define TIMER_CNTVAL_REG(val) (0x10 * val + 0x18)
#define TIMER_SCAL 16
@@ -42,21 +42,21 @@ static void __iomem *timer_base;
static void sunxi_clkevt_mode(enum clock_event_mode mode,
struct clock_event_device *clk)
{
- u32 u = readl(timer_base + TIMER0_CTL_REG);
+ u32 u = readl(timer_base + TIMER_CTL_REG(0));
switch (mode) {
case CLOCK_EVT_MODE_PERIODIC:
- u &= ~(TIMER0_CTL_ONESHOT);
- writel(u | TIMER0_CTL_ENABLE, timer_base + TIMER0_CTL_REG);
+ u &= ~(TIMER_CTL_ONESHOT);
+ writel(u | TIMER_CTL_ENABLE, timer_base + TIMER_CTL_REG(0));
break;
case CLOCK_EVT_MODE_ONESHOT:
- writel(u | TIMER0_CTL_ONESHOT, timer_base + TIMER0_CTL_REG);
+ writel(u | TIMER_CTL_ONESHOT, timer_base + TIMER_CTL_REG(0));
break;
case CLOCK_EVT_MODE_UNUSED:
case CLOCK_EVT_MODE_SHUTDOWN:
default:
- writel(u & ~(TIMER0_CTL_ENABLE), timer_base + TIMER0_CTL_REG);
+ writel(u & ~(TIMER_CTL_ENABLE), timer_base + TIMER_CTL_REG(0));
break;
}
}
@@ -64,10 +64,10 @@ static void sunxi_clkevt_mode(enum clock_event_mode mode,
static int sunxi_clkevt_next_event(unsigned long evt,
struct clock_event_device *unused)
{
- u32 u = readl(timer_base + TIMER0_CTL_REG);
- writel(evt, timer_base + TIMER0_CNTVAL_REG);
- writel(u | TIMER0_CTL_ENABLE | TIMER0_CTL_AUTORELOAD,
- timer_base + TIMER0_CTL_REG);
+ u32 u = readl(timer_base + TIMER_CTL_REG(0));
+ writel(evt, timer_base + TIMER_CNTVAL_REG(0));
+ writel(u | TIMER_CTL_ENABLE | TIMER_CTL_AUTORELOAD,
+ timer_base + TIMER_CTL_REG(0));
return 0;
}
@@ -132,26 +132,26 @@ void __init sunxi_timer_init(void)
rate = clk_get_rate(clk);
writel(rate / (TIMER_SCAL * HZ),
- timer_base + TIMER0_INTVAL_REG);
+ timer_base + TIMER_INTVAL_REG(0));
/* set clock source to HOSC, 16 pre-division */
- val = readl(timer_base + TIMER0_CTL_REG);
+ val = readl(timer_base + TIMER_CTL_REG(0));
val &= ~(0x07 << 4);
val &= ~(0x03 << 2);
val |= (4 << 4) | (1 << 2);
- writel(val, timer_base + TIMER0_CTL_REG);
+ writel(val, timer_base + TIMER_CTL_REG(0));
/* set mode to auto reload */
- val = readl(timer_base + TIMER0_CTL_REG);
- writel(val | TIMER0_CTL_AUTORELOAD, timer_base + TIMER0_CTL_REG);
+ val = readl(timer_base + TIMER_CTL_REG(0));
+ writel(val | TIMER_CTL_AUTORELOAD, timer_base + TIMER_CTL_REG(0));
ret = setup_irq(irq, &sunxi_timer_irq);
if (ret)
pr_warn("failed to setup irq %d\n", irq);
/* Enable timer0 interrupt */
- val = readl(timer_base + TIMER_CTL_REG);
- writel(val | TIMER_CTL_ENABLE, timer_base + TIMER_CTL_REG);
+ val = readl(timer_base + TIMER_IRQ_EN_REG);
+ writel(val | TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_EN_REG);
sunxi_clockevent.cpumask = cpumask_of(0);
--
1.7.10.4
next prev parent reply other threads:[~2013-03-26 9:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1364289198-11589-1-git-send-email-maxime.ripard@free-electrons.com>
2013-03-26 9:13 ` [PATCH 01/10] ARM: sunxi: dt: Reorganize the dtsi Maxime Ripard
2013-03-26 9:13 ` Maxime Ripard [this message]
2013-03-26 9:13 ` [PATCH 03/10] clocksource: sunxi: make use of CLKSRC_OF Maxime Ripard
2013-03-26 9:13 ` [PATCH 04/10] clocksource: sunxi: Rename sunxi to sun4i Maxime Ripard
2013-03-26 9:13 ` [PATCH 05/10] ARM: sunxi: dt: Update timer compatible string Maxime Ripard
2013-03-26 9:13 ` [PATCH 06/10] irqchip: sunxi: Make use of the IRQCHIP_DECLARE macro Maxime Ripard
2013-03-26 9:13 ` [PATCH 07/10] irqchip: sunxi: Rename sunxi to sun4i Maxime Ripard
2013-03-26 9:13 ` [PATCH 08/10] ARM: sunxi: dt: Update interrupt controller compatible string Maxime Ripard
2013-03-26 9:13 ` [PATCH 09/10] ARM: sunxi: Rework the restart code Maxime Ripard
2013-03-26 9:13 ` [PATCH 10/10] ARM: sunxi: dt: Update watchdog compatible string Maxime Ripard
[not found] <1364218233-29636-1-git-send-email-maxime.ripard@free-electrons.com>
2013-03-25 13:30 ` [PATCH 02/10] clocksource: sunxi: Cleanup the timer code Maxime Ripard
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=1364289198-11589-3-git-send-email-maxime.ripard@free-electrons.com \
--to=maxime.ripard@free-electrons.com \
--cc=john.stultz@linaro.org \
--cc=kevin@allwinnertech.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shuge@allwinnertech.com \
--cc=sunny@allwinnertech.com \
--cc=tglx@linutronix.de \
/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®