2005-11-10 07:26:51 -07:00
|
|
|
/*
|
2011-03-29 15:54:50 -07:00
|
|
|
* linux/arch/arm/mach-omap2/timer.c
|
2005-11-10 07:26:51 -07:00
|
|
|
*
|
|
|
|
* OMAP2 GP timer support.
|
|
|
|
*
|
OMAP2/3 GPTIMER: allow system tick GPTIMER to be changed in board-*.c files
Add a function omap2_gp_clockevent_set_gptimer() for board-*.c files
to use in .init_irq functions to configure the system tick GPTIMER.
Practical choices at this point are GPTIMER1 or GPTIMER12. Both of
these timers are in the WKUP powerdomain, and so are unaffected by
chip power management. GPTIMER1 can use sys_clk as a source, for
applications where a high-resolution timer is more important than
power management. GPTIMER12 has the special property that it has the
secure 32kHz oscillator as its source clock, which may be less prone
to glitches than the off-chip 32kHz oscillator. But on HS devices, it
may not be available for Linux use.
It appears that most boards are fine with GPTIMER1, but BeagleBoard
should use GPTIMER12 when using a 32KiHz timer source, due to hardware bugs
in revisions B4 and below. Modify board-omap3beagle.c to use GPTIMER12.
This patch originally used a Kbuild config option to select the GPTIMER,
but was changed to allow this to be specified in board-*.c files, per
Tony's request.
Kalle Vallo <kalle.valo@nokia.com> found a bug in an earlier version of
this patch - thanks Kalle.
Tested on Beagle rev B4 ES2.1, with and without CONFIG_OMAP_32K_TIMER, and
3430SDP.
Signed-off-by: Paul Walmsley <paul@pwsan.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Cc: Kalle Valo <kalle.valo@nokia.com>
2009-04-23 20:11:10 -07:00
|
|
|
* Copyright (C) 2009 Nokia Corporation
|
|
|
|
*
|
2007-11-13 00:24:02 -07:00
|
|
|
* Update to use new clocksource/clockevent layers
|
|
|
|
* Author: Kevin Hilman, MontaVista Software, Inc. <source@mvista.com>
|
|
|
|
* Copyright (C) 2007 MontaVista Software, Inc.
|
|
|
|
*
|
|
|
|
* Original driver:
|
2005-11-10 07:26:51 -07:00
|
|
|
* Copyright (C) 2005 Nokia Corporation
|
|
|
|
* Author: Paul Mundt <paul.mundt@nokia.com>
|
2007-10-19 14:21:04 -07:00
|
|
|
* Juha Yrjölä <juha.yrjola@nokia.com>
|
2006-06-26 16:16:12 -07:00
|
|
|
* OMAP Dual-mode timer framework support by Timo Teras
|
2005-11-10 07:26:51 -07:00
|
|
|
*
|
|
|
|
* Some parts based off of TI's 24xx code:
|
|
|
|
*
|
2009-05-28 14:16:04 -07:00
|
|
|
* Copyright (C) 2004-2009 Texas Instruments, Inc.
|
2005-11-10 07:26:51 -07:00
|
|
|
*
|
|
|
|
* Roughly modelled after the OMAP1 MPU timer code.
|
2009-05-28 14:16:04 -07:00
|
|
|
* Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
|
2005-11-10 07:26:51 -07:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*/
|
2006-01-07 09:15:52 -07:00
|
|
|
#include <linux/clk.h>
|
2007-11-13 00:24:02 -07:00
|
|
|
#include <linux/clocksource.h>
|
2011-09-20 04:30:24 -07:00
|
|
|
|
2012-08-31 10:59:07 -07:00
|
|
|
#include "soc.h"
|
2012-08-27 17:43:01 -07:00
|
|
|
#include "common.h"
|
2015-01-05 16:45:45 -07:00
|
|
|
#include "control.h"
|
2013-10-10 00:43:48 -07:00
|
|
|
#include "omap-secure.h"
|
2005-11-10 07:26:51 -07:00
|
|
|
|
2012-08-13 01:54:24 -07:00
|
|
|
#define REALTIME_COUNTER_BASE 0x48243200
|
|
|
|
#define INCREMENTER_NUMERATOR_OFFSET 0x10
|
|
|
|
#define INCREMENTER_DENUMERATOR_RELOAD_OFFSET 0x14
|
|
|
|
#define NUMERATOR_DENUMERATOR_MASK 0xfffff000
|
|
|
|
|
2013-10-10 00:43:48 -07:00
|
|
|
static unsigned long arch_timer_freq;
|
|
|
|
|
|
|
|
void set_cntfreq(void)
|
|
|
|
{
|
|
|
|
omap_smc1(OMAP5_DRA7_MON_SET_CNTFRQ_INDEX, arch_timer_freq);
|
|
|
|
}
|
OMAP2/3 GPTIMER: allow system tick GPTIMER to be changed in board-*.c files
Add a function omap2_gp_clockevent_set_gptimer() for board-*.c files
to use in .init_irq functions to configure the system tick GPTIMER.
Practical choices at this point are GPTIMER1 or GPTIMER12. Both of
these timers are in the WKUP powerdomain, and so are unaffected by
chip power management. GPTIMER1 can use sys_clk as a source, for
applications where a high-resolution timer is more important than
power management. GPTIMER12 has the special property that it has the
secure 32kHz oscillator as its source clock, which may be less prone
to glitches than the off-chip 32kHz oscillator. But on HS devices, it
may not be available for Linux use.
It appears that most boards are fine with GPTIMER1, but BeagleBoard
should use GPTIMER12 when using a 32KiHz timer source, due to hardware bugs
in revisions B4 and below. Modify board-omap3beagle.c to use GPTIMER12.
This patch originally used a Kbuild config option to select the GPTIMER,
but was changed to allow this to be specified in board-*.c files, per
Tony's request.
Kalle Vallo <kalle.valo@nokia.com> found a bug in an earlier version of
this patch - thanks Kalle.
Tested on Beagle rev B4 ES2.1, with and without CONFIG_OMAP_32K_TIMER, and
3430SDP.
Signed-off-by: Paul Walmsley <paul@pwsan.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Cc: Kalle Valo <kalle.valo@nokia.com>
2009-04-23 20:11:10 -07:00
|
|
|
|
2012-08-13 01:54:24 -07:00
|
|
|
/*
|
|
|
|
* The realtime counter also called master counter, is a free-running
|
|
|
|
* counter, which is related to real time. It produces the count used
|
|
|
|
* by the CPU local timer peripherals in the MPU cluster. The timer counts
|
|
|
|
* at a rate of 6.144 MHz. Because the device operates on different clocks
|
|
|
|
* in different power modes, the master counter shifts operation between
|
|
|
|
* clocks, adjusting the increment per clock in hardware accordingly to
|
|
|
|
* maintain a constant count rate.
|
|
|
|
*/
|
|
|
|
static void __init realtime_counter_init(void)
|
|
|
|
{
|
|
|
|
void __iomem *base;
|
|
|
|
static struct clk *sys_clk;
|
|
|
|
unsigned long rate;
|
2015-01-05 16:45:45 -07:00
|
|
|
unsigned int reg;
|
|
|
|
unsigned long long num, den;
|
2012-08-13 01:54:24 -07:00
|
|
|
|
|
|
|
base = ioremap(REALTIME_COUNTER_BASE, SZ_32);
|
|
|
|
if (!base) {
|
|
|
|
pr_err("%s: ioremap failed\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
2013-04-03 10:47:59 -07:00
|
|
|
sys_clk = clk_get(NULL, "sys_clkin");
|
2012-10-08 15:01:41 -07:00
|
|
|
if (IS_ERR(sys_clk)) {
|
2012-08-13 01:54:24 -07:00
|
|
|
pr_err("%s: failed to get system clock handle\n", __func__);
|
|
|
|
iounmap(base);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rate = clk_get_rate(sys_clk);
|
2022-11-08 07:19:17 -07:00
|
|
|
clk_put(sys_clk);
|
2015-01-05 16:45:45 -07:00
|
|
|
|
|
|
|
if (soc_is_dra7xx()) {
|
|
|
|
/*
|
|
|
|
* Errata i856 says the 32.768KHz crystal does not start at
|
|
|
|
* power on, so the CPU falls back to an emulated 32KHz clock
|
|
|
|
* based on sysclk / 610 instead. This causes the master counter
|
|
|
|
* frequency to not be 6.144MHz but at sysclk / 610 * 375 / 2
|
|
|
|
* (OR sysclk * 75 / 244)
|
|
|
|
*
|
|
|
|
* This affects at least the DRA7/AM572x 1.0, 1.1 revisions.
|
|
|
|
* Of course any board built without a populated 32.768KHz
|
|
|
|
* crystal would also need this fix even if the CPU is fixed
|
|
|
|
* later.
|
|
|
|
*
|
|
|
|
* Either case can be detected by using the two speedselect bits
|
|
|
|
* If they are not 0, then the 32.768KHz clock driving the
|
|
|
|
* coarse counter that corrects the fine counter every time it
|
|
|
|
* ticks is actually rate/610 rather than 32.768KHz and we
|
|
|
|
* should compensate to avoid the 570ppm (at 20MHz, much worse
|
|
|
|
* at other rates) too fast system time.
|
|
|
|
*/
|
|
|
|
reg = omap_ctrl_readl(DRA7_CTRL_CORE_BOOTSTRAP);
|
|
|
|
if (reg & DRA7_SPEEDSELECT_MASK) {
|
|
|
|
num = 75;
|
|
|
|
den = 244;
|
|
|
|
goto sysclk1_based;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-13 01:54:24 -07:00
|
|
|
/* Numerator/denumerator values refer TRM Realtime Counter section */
|
|
|
|
switch (rate) {
|
2015-01-05 16:45:45 -07:00
|
|
|
case 12000000:
|
2012-08-13 01:54:24 -07:00
|
|
|
num = 64;
|
|
|
|
den = 125;
|
|
|
|
break;
|
2015-01-05 16:45:45 -07:00
|
|
|
case 13000000:
|
2012-08-13 01:54:24 -07:00
|
|
|
num = 768;
|
|
|
|
den = 1625;
|
|
|
|
break;
|
|
|
|
case 19200000:
|
|
|
|
num = 8;
|
|
|
|
den = 25;
|
|
|
|
break;
|
2013-09-18 04:20:11 -07:00
|
|
|
case 20000000:
|
|
|
|
num = 192;
|
|
|
|
den = 625;
|
|
|
|
break;
|
2015-01-05 16:45:45 -07:00
|
|
|
case 26000000:
|
2012-08-13 01:54:24 -07:00
|
|
|
num = 384;
|
|
|
|
den = 1625;
|
|
|
|
break;
|
2015-01-05 16:45:45 -07:00
|
|
|
case 27000000:
|
2012-08-13 01:54:24 -07:00
|
|
|
num = 256;
|
|
|
|
den = 1125;
|
|
|
|
break;
|
|
|
|
case 38400000:
|
|
|
|
default:
|
|
|
|
/* Program it for 38.4 MHz */
|
|
|
|
num = 4;
|
|
|
|
den = 25;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-05 16:45:45 -07:00
|
|
|
sysclk1_based:
|
2012-08-13 01:54:24 -07:00
|
|
|
/* Program numerator and denumerator registers */
|
2014-04-15 10:37:46 -07:00
|
|
|
reg = readl_relaxed(base + INCREMENTER_NUMERATOR_OFFSET) &
|
2012-08-13 01:54:24 -07:00
|
|
|
NUMERATOR_DENUMERATOR_MASK;
|
|
|
|
reg |= num;
|
2014-04-15 10:37:46 -07:00
|
|
|
writel_relaxed(reg, base + INCREMENTER_NUMERATOR_OFFSET);
|
2012-08-13 01:54:24 -07:00
|
|
|
|
2014-04-15 10:37:46 -07:00
|
|
|
reg = readl_relaxed(base + INCREMENTER_DENUMERATOR_RELOAD_OFFSET) &
|
2012-08-13 01:54:24 -07:00
|
|
|
NUMERATOR_DENUMERATOR_MASK;
|
|
|
|
reg |= den;
|
2014-04-15 10:37:46 -07:00
|
|
|
writel_relaxed(reg, base + INCREMENTER_DENUMERATOR_RELOAD_OFFSET);
|
2012-08-13 01:54:24 -07:00
|
|
|
|
2015-01-05 16:45:45 -07:00
|
|
|
arch_timer_freq = DIV_ROUND_UP_ULL(rate * num, den);
|
2013-10-10 00:43:48 -07:00
|
|
|
set_cntfreq();
|
|
|
|
|
2012-08-13 01:54:24 -07:00
|
|
|
iounmap(base);
|
2012-11-20 00:17:15 -07:00
|
|
|
}
|
|
|
|
|
2012-11-08 12:40:59 -07:00
|
|
|
void __init omap5_realtime_timer_init(void)
|
2012-08-13 01:54:24 -07:00
|
|
|
{
|
2020-05-07 09:59:31 -07:00
|
|
|
omap_clk_init();
|
2012-08-13 01:54:24 -07:00
|
|
|
realtime_counter_init();
|
2012-08-13 02:09:03 -07:00
|
|
|
|
2017-05-26 08:40:46 -07:00
|
|
|
timer_probe();
|
2012-08-13 01:54:24 -07:00
|
|
|
}
|