2005-11-10 14:26:51 +00:00
|
|
|
/*
|
|
|
|
* linux/arch/arm/mach-omap2/timer-gp.c
|
|
|
|
*
|
|
|
|
* 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-24 03:11:10 +00:00
|
|
|
* Copyright (C) 2009 Nokia Corporation
|
|
|
|
*
|
2007-11-13 07:24:02 +00: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 14:26:51 +00:00
|
|
|
* Copyright (C) 2005 Nokia Corporation
|
|
|
|
* Author: Paul Mundt <paul.mundt@nokia.com>
|
2007-10-19 21:21:04 +00:00
|
|
|
* Juha Yrjölä <juha.yrjola@nokia.com>
|
2006-06-26 23:16:12 +00:00
|
|
|
* OMAP Dual-mode timer framework support by Timo Teras
|
2005-11-10 14:26:51 +00:00
|
|
|
*
|
|
|
|
* Some parts based off of TI's 24xx code:
|
|
|
|
*
|
2009-05-28 21:16:04 +00:00
|
|
|
* Copyright (C) 2004-2009 Texas Instruments, Inc.
|
2005-11-10 14:26:51 +00:00
|
|
|
*
|
|
|
|
* Roughly modelled after the OMAP1 MPU timer code.
|
2009-05-28 21:16:04 +00:00
|
|
|
* Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
|
2005-11-10 14:26:51 +00: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.
|
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/err.h>
|
2006-01-07 16:15:52 +00:00
|
|
|
#include <linux/clk.h>
|
2006-06-26 23:16:12 +00:00
|
|
|
#include <linux/delay.h>
|
2006-12-07 01:14:00 +00:00
|
|
|
#include <linux/irq.h>
|
2007-11-13 07:24:02 +00:00
|
|
|
#include <linux/clocksource.h>
|
|
|
|
#include <linux/clockchips.h>
|
2006-01-07 16:15:52 +00:00
|
|
|
|
2005-11-10 14:26:51 +00:00
|
|
|
#include <asm/mach/time.h>
|
2009-10-20 16:40:47 +00:00
|
|
|
#include <plat/dmtimer.h>
|
2009-04-28 15:22:00 +00:00
|
|
|
#include <asm/localtimer.h>
|
2011-02-23 02:59:49 +00:00
|
|
|
#include <asm/sched_clock.h>
|
2005-11-10 14:26:51 +00:00
|
|
|
|
2010-10-08 16:58:35 +00:00
|
|
|
#include "timer-gp.h"
|
|
|
|
|
2011-01-16 04:32:01 +00:00
|
|
|
#include <plat/common.h>
|
|
|
|
|
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-24 03:11:10 +00:00
|
|
|
/* MAX_GPTIMER_ID: number of GPTIMERs on the chip */
|
|
|
|
#define MAX_GPTIMER_ID 12
|
|
|
|
|
2006-06-26 23:16:12 +00:00
|
|
|
static struct omap_dm_timer *gptimer;
|
2007-11-13 07:24:02 +00:00
|
|
|
static struct clock_event_device clockevent_gpt;
|
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-24 03:11:10 +00:00
|
|
|
static u8 __initdata gptimer_id = 1;
|
|
|
|
static u8 __initdata inited;
|
2009-10-06 21:30:23 +00:00
|
|
|
struct omap_dm_timer *gptimer_wakeup;
|
2005-11-10 14:26:51 +00:00
|
|
|
|
2006-10-06 17:53:39 +00:00
|
|
|
static irqreturn_t omap2_gp_timer_interrupt(int irq, void *dev_id)
|
2005-11-10 14:26:51 +00:00
|
|
|
{
|
2007-11-13 07:24:02 +00:00
|
|
|
struct omap_dm_timer *gpt = (struct omap_dm_timer *)dev_id;
|
|
|
|
struct clock_event_device *evt = &clockevent_gpt;
|
|
|
|
|
|
|
|
omap_dm_timer_write_status(gpt, OMAP_TIMER_INT_OVERFLOW);
|
2005-11-10 14:26:51 +00:00
|
|
|
|
2007-11-13 07:24:02 +00:00
|
|
|
evt->event_handler(evt);
|
2005-11-10 14:26:51 +00:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct irqaction omap2_gp_timer_irq = {
|
|
|
|
.name = "gp timer",
|
2007-05-08 07:35:39 +00:00
|
|
|
.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
|
2005-11-10 14:26:51 +00:00
|
|
|
.handler = omap2_gp_timer_interrupt,
|
|
|
|
};
|
|
|
|
|
2007-11-13 07:24:02 +00:00
|
|
|
static int omap2_gp_timer_set_next_event(unsigned long cycles,
|
|
|
|
struct clock_event_device *evt)
|
2005-11-10 14:26:51 +00:00
|
|
|
{
|
2008-07-03 09:24:30 +00:00
|
|
|
omap_dm_timer_set_load_start(gptimer, 0, 0xffffffff - cycles);
|
2007-11-13 07:24:02 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void omap2_gp_timer_set_mode(enum clock_event_mode mode,
|
|
|
|
struct clock_event_device *evt)
|
|
|
|
{
|
|
|
|
u32 period;
|
|
|
|
|
|
|
|
omap_dm_timer_stop(gptimer);
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case CLOCK_EVT_MODE_PERIODIC:
|
|
|
|
period = clk_get_rate(omap_dm_timer_get_fclk(gptimer)) / HZ;
|
|
|
|
period -= 1;
|
2008-07-03 09:24:30 +00:00
|
|
|
omap_dm_timer_set_load_start(gptimer, 1, 0xffffffff - period);
|
2007-11-13 07:24:02 +00:00
|
|
|
break;
|
|
|
|
case CLOCK_EVT_MODE_ONESHOT:
|
|
|
|
break;
|
|
|
|
case CLOCK_EVT_MODE_UNUSED:
|
|
|
|
case CLOCK_EVT_MODE_SHUTDOWN:
|
|
|
|
case CLOCK_EVT_MODE_RESUME:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct clock_event_device clockevent_gpt = {
|
|
|
|
.name = "gp timer",
|
|
|
|
.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
|
|
|
|
.shift = 32,
|
|
|
|
.set_next_event = omap2_gp_timer_set_next_event,
|
|
|
|
.set_mode = omap2_gp_timer_set_mode,
|
|
|
|
};
|
|
|
|
|
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-24 03:11:10 +00:00
|
|
|
/**
|
|
|
|
* omap2_gp_clockevent_set_gptimer - set which GPTIMER is used for clockevents
|
|
|
|
* @id: GPTIMER to use (1..MAX_GPTIMER_ID)
|
|
|
|
*
|
|
|
|
* Define the GPTIMER that the system should use for the tick timer.
|
|
|
|
* Meant to be called from board-*.c files in the event that GPTIMER1, the
|
|
|
|
* default, is unsuitable. Returns -EINVAL on error or 0 on success.
|
|
|
|
*/
|
|
|
|
int __init omap2_gp_clockevent_set_gptimer(u8 id)
|
|
|
|
{
|
|
|
|
if (id < 1 || id > MAX_GPTIMER_ID)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
BUG_ON(inited);
|
|
|
|
|
|
|
|
gptimer_id = id;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-13 07:24:02 +00:00
|
|
|
static void __init omap2_gp_clockevent_init(void)
|
|
|
|
{
|
|
|
|
u32 tick_rate;
|
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-24 03:11:10 +00:00
|
|
|
int src;
|
|
|
|
|
|
|
|
inited = 1;
|
2005-11-10 14:26:51 +00:00
|
|
|
|
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-24 03:11:10 +00:00
|
|
|
gptimer = omap_dm_timer_request_specific(gptimer_id);
|
2006-06-26 23:16:12 +00:00
|
|
|
BUG_ON(gptimer == NULL);
|
2009-10-06 21:30:23 +00:00
|
|
|
gptimer_wakeup = gptimer;
|
2005-11-10 14:26:51 +00:00
|
|
|
|
2007-11-13 07:24:02 +00:00
|
|
|
#if defined(CONFIG_OMAP_32K_TIMER)
|
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-24 03:11:10 +00:00
|
|
|
src = OMAP_TIMER_SRC_32_KHZ;
|
2007-11-13 07:24:02 +00:00
|
|
|
#else
|
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-24 03:11:10 +00:00
|
|
|
src = OMAP_TIMER_SRC_SYS_CLK;
|
|
|
|
WARN(gptimer_id == 12, "WARNING: GPTIMER12 can only use the "
|
|
|
|
"secure 32KiHz clock source\n");
|
2007-11-13 07:24:02 +00:00
|
|
|
#endif
|
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-24 03:11:10 +00:00
|
|
|
|
|
|
|
if (gptimer_id != 12)
|
|
|
|
WARN(IS_ERR_VALUE(omap_dm_timer_set_source(gptimer, src)),
|
|
|
|
"timer-gp: omap_dm_timer_set_source() failed\n");
|
|
|
|
|
2007-11-13 07:24:02 +00:00
|
|
|
tick_rate = clk_get_rate(omap_dm_timer_get_fclk(gptimer));
|
2005-11-10 14:26:51 +00:00
|
|
|
|
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-24 03:11:10 +00:00
|
|
|
pr_info("OMAP clockevent source: GPTIMER%d at %u Hz\n",
|
|
|
|
gptimer_id, tick_rate);
|
|
|
|
|
2007-11-13 07:24:02 +00:00
|
|
|
omap2_gp_timer_irq.dev_id = (void *)gptimer;
|
2006-06-26 23:16:12 +00:00
|
|
|
setup_irq(omap_dm_timer_get_irq(gptimer), &omap2_gp_timer_irq);
|
2007-11-13 07:24:02 +00:00
|
|
|
omap_dm_timer_set_int_enable(gptimer, OMAP_TIMER_INT_OVERFLOW);
|
|
|
|
|
|
|
|
clockevent_gpt.mult = div_sc(tick_rate, NSEC_PER_SEC,
|
|
|
|
clockevent_gpt.shift);
|
|
|
|
clockevent_gpt.max_delta_ns =
|
|
|
|
clockevent_delta2ns(0xffffffff, &clockevent_gpt);
|
|
|
|
clockevent_gpt.min_delta_ns =
|
2009-01-29 16:57:17 +00:00
|
|
|
clockevent_delta2ns(3, &clockevent_gpt);
|
|
|
|
/* Timer internal resynch latency. */
|
2007-11-13 07:24:02 +00:00
|
|
|
|
2008-12-13 10:50:26 +00:00
|
|
|
clockevent_gpt.cpumask = cpumask_of(0);
|
2007-11-13 07:24:02 +00:00
|
|
|
clockevents_register_device(&clockevent_gpt);
|
|
|
|
}
|
|
|
|
|
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-24 03:11:10 +00:00
|
|
|
/* Clocksource code */
|
|
|
|
|
2007-11-13 07:24:02 +00:00
|
|
|
#ifdef CONFIG_OMAP_32K_TIMER
|
|
|
|
/*
|
|
|
|
* When 32k-timer is enabled, don't use GPTimer for clocksource
|
|
|
|
* instead, just leave default clocksource which uses the 32k
|
2011-01-16 04:32:01 +00:00
|
|
|
* sync counter. See clocksource setup in plat-omap/counter_32k.c
|
2007-11-13 07:24:02 +00:00
|
|
|
*/
|
|
|
|
|
2011-01-16 04:32:01 +00:00
|
|
|
static void __init omap2_gp_clocksource_init(void)
|
|
|
|
{
|
|
|
|
omap_init_clocksource_32k();
|
|
|
|
}
|
|
|
|
|
2007-11-13 07:24:02 +00:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* clocksource
|
|
|
|
*/
|
2011-02-23 02:59:49 +00:00
|
|
|
static DEFINE_CLOCK_DATA(cd);
|
2007-11-13 07:24:02 +00:00
|
|
|
static struct omap_dm_timer *gpt_clocksource;
|
2009-04-21 19:24:00 +00:00
|
|
|
static cycle_t clocksource_read_cycles(struct clocksource *cs)
|
2007-11-13 07:24:02 +00:00
|
|
|
{
|
|
|
|
return (cycle_t)omap_dm_timer_read_counter(gpt_clocksource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct clocksource clocksource_gpt = {
|
|
|
|
.name = "gp timer",
|
|
|
|
.rating = 300,
|
|
|
|
.read = clocksource_read_cycles,
|
|
|
|
.mask = CLOCKSOURCE_MASK(32),
|
|
|
|
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
|
|
|
|
};
|
|
|
|
|
2011-02-23 02:59:49 +00:00
|
|
|
static void notrace dmtimer_update_sched_clock(void)
|
|
|
|
{
|
|
|
|
u32 cyc;
|
|
|
|
|
|
|
|
cyc = omap_dm_timer_read_counter(gpt_clocksource);
|
|
|
|
|
|
|
|
update_sched_clock(&cd, cyc, (u32)~0);
|
|
|
|
}
|
|
|
|
|
2007-11-13 07:24:02 +00:00
|
|
|
/* Setup free-running counter for clocksource */
|
|
|
|
static void __init omap2_gp_clocksource_init(void)
|
|
|
|
{
|
|
|
|
static struct omap_dm_timer *gpt;
|
2010-11-18 17:59:51 +00:00
|
|
|
u32 tick_rate;
|
2007-11-13 07:24:02 +00:00
|
|
|
static char err1[] __initdata = KERN_ERR
|
|
|
|
"%s: failed to request dm-timer\n";
|
|
|
|
static char err2[] __initdata = KERN_ERR
|
|
|
|
"%s: can't register clocksource!\n";
|
|
|
|
|
|
|
|
gpt = omap_dm_timer_request();
|
|
|
|
if (!gpt)
|
|
|
|
printk(err1, clocksource_gpt.name);
|
|
|
|
gpt_clocksource = gpt;
|
|
|
|
|
|
|
|
omap_dm_timer_set_source(gpt, OMAP_TIMER_SRC_SYS_CLK);
|
|
|
|
tick_rate = clk_get_rate(omap_dm_timer_get_fclk(gpt));
|
|
|
|
|
2008-07-03 09:24:30 +00:00
|
|
|
omap_dm_timer_set_load_start(gpt, 1, 0);
|
2007-11-13 07:24:02 +00:00
|
|
|
|
2011-02-23 02:59:49 +00:00
|
|
|
init_sched_clock(&cd, dmtimer_update_sched_clock, 32, tick_rate);
|
|
|
|
|
2010-12-13 13:18:44 +00:00
|
|
|
if (clocksource_register_hz(&clocksource_gpt, tick_rate))
|
2007-11-13 07:24:02 +00:00
|
|
|
printk(err2, clocksource_gpt.name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void __init omap2_gp_timer_init(void)
|
|
|
|
{
|
2009-04-28 15:22:00 +00:00
|
|
|
#ifdef CONFIG_LOCAL_TIMERS
|
2010-09-20 21:53:15 +00:00
|
|
|
if (cpu_is_omap44xx()) {
|
|
|
|
twd_base = ioremap(OMAP44XX_LOCAL_TWD_BASE, SZ_256);
|
|
|
|
BUG_ON(!twd_base);
|
|
|
|
}
|
2009-04-28 15:22:00 +00:00
|
|
|
#endif
|
2007-11-13 07:24:02 +00:00
|
|
|
omap_dm_timer_init();
|
|
|
|
|
|
|
|
omap2_gp_clockevent_init();
|
|
|
|
omap2_gp_clocksource_init();
|
2005-11-10 14:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct sys_timer omap_timer = {
|
|
|
|
.init = omap2_gp_timer_init,
|
|
|
|
};
|