From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH v2 04/10] ARM: davinci: add clocksource
Date: Sun, 16 Mar 2014 17:48:15 +0400 [thread overview]
Message-ID: <1394977701-5889-5-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1394977701-5889-1-git-send-email-antonynpavlov@gmail.com>
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
arch/arm/mach-davinci/include/mach/time.h | 2 +
arch/arm/mach-davinci/time.c | 114 ++++++++++++++++++++++++++++++
2 files changed, 116 insertions(+)
diff --git a/arch/arm/mach-davinci/include/mach/time.h b/arch/arm/mach-davinci/include/mach/time.h
index 741e90c..34781b6 100644
--- a/arch/arm/mach-davinci/include/mach/time.h
+++ b/arch/arm/mach-davinci/include/mach/time.h
@@ -13,6 +13,8 @@
#include <mach/hardware.h>
+#define DAVINCI_TIMER0_BASE (IO_PHYS + 0x21400)
+#define DAVINCI_TIMER1_BASE (IO_PHYS + 0x21800)
#define DAVINCI_WDOG_BASE (IO_PHYS + 0x21C00)
#endif /* __ARCH_ARM_MACH_DAVINCI_TIME_H */
diff --git a/arch/arm/mach-davinci/time.c b/arch/arm/mach-davinci/time.c
index 1e00719..60f0d19 100644
--- a/arch/arm/mach-davinci/time.c
+++ b/arch/arm/mach-davinci/time.c
@@ -11,6 +11,8 @@
#include <common.h>
#include <io.h>
+#include <init.h>
+#include <clock.h>
#include <mach/time.h>
@@ -49,6 +51,118 @@
#define WDTCR_WDKEY_SEQ0 0xa5c6
#define WDTCR_WDKEY_SEQ1 0xda7e
+#define DAVINCI_TIMER_CLOCK 24000000
+
+struct timer_s {
+ void __iomem *base;
+ unsigned long tim_off;
+ unsigned long prd_off;
+ unsigned long enamode_shift;
+};
+
+static struct timer_s timers[] = {
+ {
+ .base = IOMEM(DAVINCI_TIMER0_BASE),
+ .enamode_shift = 6,
+ .tim_off = TIM12,
+ .prd_off = PRD12,
+ },
+ {
+ .base = IOMEM(DAVINCI_TIMER0_BASE),
+ .enamode_shift = 22,
+ .tim_off = TIM34,
+ .prd_off = PRD34,
+ },
+ {
+ .base = IOMEM(DAVINCI_TIMER1_BASE),
+ .enamode_shift = 6,
+ .tim_off = TIM12,
+ .prd_off = PRD12,
+ },
+ {
+ .base = IOMEM(DAVINCI_TIMER1_BASE),
+ .enamode_shift = 22,
+ .tim_off = TIM34,
+ .prd_off = PRD34,
+ },
+};
+
+static struct timer_s *t = &timers[0];
+
+static uint64_t davinci_cs_read(void)
+{
+ return (uint64_t)__raw_readl(t->base + t->tim_off);
+}
+
+static struct clocksource davinci_cs = {
+ .read = davinci_cs_read,
+ .mask = CLOCKSOURCE_MASK(32),
+};
+
+static int timer32_config(struct timer_s *t)
+{
+ u32 tcr;
+
+ tcr = __raw_readl(t->base + TCR);
+
+ /* disable timer */
+ tcr &= ~(TCR_ENAMODE_MASK << t->enamode_shift);
+ __raw_writel(tcr, t->base + TCR);
+
+ /* reset counter to zero, set new period */
+ __raw_writel(0, t->base + t->tim_off);
+ __raw_writel(0xffffffff, t->base + t->prd_off);
+
+ /* Set enable mode for periodic timer */
+ tcr |= TCR_ENAMODE_PERIODIC << t->enamode_shift;
+
+ __raw_writel(tcr, t->base + TCR);
+
+ return 0;
+}
+
+/* Global init of 64-bit timer as a whole */
+static void __init timer_init(void __iomem *base)
+{
+ u32 tgcr;
+
+ /* Disabled, Internal clock source */
+ __raw_writel(0, base + TCR);
+
+ /* reset both timers, no pre-scaler for timer34 */
+ tgcr = 0;
+ __raw_writel(tgcr, base + TGCR);
+
+ /* Set both timers to unchained 32-bit */
+ tgcr = TGCR_TIMMODE_32BIT_UNCHAINED << TGCR_TIMMODE_SHIFT;
+ __raw_writel(tgcr, base + TGCR);
+
+ /* Unreset timers */
+ tgcr |= (TGCR_UNRESET << TGCR_TIM12RS_SHIFT) |
+ (TGCR_UNRESET << TGCR_TIM34RS_SHIFT);
+ __raw_writel(tgcr, base + TGCR);
+
+ /* Init both counters to zero */
+ __raw_writel(0, base + TIM12);
+ __raw_writel(0, base + TIM34);
+}
+
+static int clocksource_init(void)
+{
+ clocks_calc_mult_shift(&davinci_cs.mult, &davinci_cs.shift,
+ DAVINCI_TIMER_CLOCK, NSEC_PER_SEC, 10);
+
+ init_clock(&davinci_cs);
+
+ timer_init(IOMEM(DAVINCI_TIMER0_BASE));
+ timer_init(IOMEM(DAVINCI_TIMER1_BASE));
+
+ timer32_config(t);
+
+ return 0;
+}
+core_initcall(clocksource_init);
+
/* reset board using watchdog timer */
void __noreturn reset_cpu(ulong addr)
{
--
1.9.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2014-03-16 13:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-16 13:48 [PATCH v2 00/10] ARM: initial support for TI DaVinci SoCs and virt2real board Antony Pavlov
2014-03-16 13:48 ` [PATCH v2 01/10] import _AC and UL macros from linux kernel Antony Pavlov
2014-03-16 13:48 ` [PATCH v2 02/10] ARM: initial support for TI DaVinci SoCs Antony Pavlov
2014-03-16 13:48 ` [PATCH v2 03/10] ARM: davinci: add DEBUG_LL support Antony Pavlov
2014-03-16 13:48 ` Antony Pavlov [this message]
2014-03-16 13:48 ` [PATCH v2 05/10] gpio: add driver for TI DaVinci SoCs Antony Pavlov
2014-03-16 13:48 ` [PATCH v2 06/10] ARM: dts: Add TI TMS320DM365 devicetree file Antony Pavlov
2014-03-18 16:54 ` Sascha Hauer
2014-03-16 13:48 ` [PATCH v2 07/10] ARM: davinci: add documentation Antony Pavlov
2014-03-16 13:48 ` [PATCH v2 08/10] ARM: davinci: add virt2real board support Antony Pavlov
2014-03-18 16:56 ` Sascha Hauer
2014-03-16 13:48 ` [PATCH v2 09/10] ARM: virt2real: add documentation Antony Pavlov
2014-03-16 13:48 ` [PATCH v2 10/10] ARM: davinci: add virt2real_defconfig 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=1394977701-5889-5-git-send-email-antonynpavlov@gmail.com \
--to=antonynpavlov@gmail.com \
--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