Skip to content

Commit

Permalink
MN10300: Generic time support
Browse files Browse the repository at this point in the history
Implement generic time support for MN10300.

Signed-off-by: Mark Salter <[email protected]>
Signed-off-by: David Howells <[email protected]>
  • Loading branch information
mosalter authored and dhowells committed Oct 27, 2010
1 parent 2502c64 commit 730c1fa
Show file tree
Hide file tree
Showing 12 changed files with 401 additions and 115 deletions.
22 changes: 22 additions & 0 deletions arch/mn10300/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ config GENERIC_FIND_NEXT_BIT
config GENERIC_HWEIGHT
def_bool y

config GENERIC_TIME
def_bool y

config GENERIC_CLOCKEVENTS
def_bool y

config GENERIC_CLOCKEVENTS_BUILD
def_bool y
depends on GENERIC_CLOCKEVENTS

config GENERIC_CLOCKEVENTS_BROADCAST
bool

config CEVT_MN10300
def_bool y
depends on GENERIC_CLOCKEVENTS

config CSRC_MN10300
def_bool y
depends on GENERIC_TIME

config GENERIC_BUG
def_bool y

Expand Down Expand Up @@ -245,6 +266,7 @@ config MN10300_USING_JTAG
single-stepping, which are taken over completely by the JTAG unit.

source "kernel/Kconfig.hz"
source "kernel/time/Kconfig"

config MN10300_RTC
bool "Using MN10300 RTC"
Expand Down
17 changes: 15 additions & 2 deletions arch/mn10300/include/asm/timex.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,28 @@

#define CLOCK_TICK_RATE MN10300_JCCLK /* Underlying HZ */

extern cycles_t cacheflush_time;

#ifdef __KERNEL__

extern cycles_t cacheflush_time;

static inline cycles_t get_cycles(void)
{
return read_timestamp_counter();
}

extern int init_clockevents(void);
extern int init_clocksource(void);

static inline void setup_jiffies_interrupt(int irq,
struct irqaction *action)
{
u16 tmp;
setup_irq(irq, action);
set_intr_level(irq, NUM2GxICR_LEVEL(CONFIG_TIMER_IRQ_LEVEL));
GxICR(irq) |= GxICR_ENABLE | GxICR_DETECT | GxICR_REQUEST;
tmp = GxICR(irq);
}

#endif /* __KERNEL__ */

#endif /* _ASM_TIMEX_H */
2 changes: 2 additions & 0 deletions arch/mn10300/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ obj-$(CONFIG_MN10300_RTC) += rtc.o
obj-$(CONFIG_PROFILE) += profile.o profile-low.o
obj-$(CONFIG_MODULES) += module.o
obj-$(CONFIG_KPROBES) += kprobes.o
obj-$(CONFIG_CSRC_MN10300) += csrc-mn10300.o
obj-$(CONFIG_CEVT_MN10300) += cevt-mn10300.o
131 changes: 131 additions & 0 deletions arch/mn10300/kernel/cevt-mn10300.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/* MN10300 clockevents
*
* Copyright (C) 2010 Red Hat, Inc. All Rights Reserved.
* Written by Mark Salter ([email protected])
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public Licence
* as published by the Free Software Foundation; either version
* 2 of the Licence, or (at your option) any later version.
*/
#include <linux/clockchips.h>
#include <linux/interrupt.h>
#include <linux/percpu.h>
#include <linux/smp.h>
#include <asm/timex.h>
#include "internal.h"

#ifdef CONFIG_SMP
#if (CONFIG_NR_CPUS > 2) && !defined(CONFIG_GEENERIC_CLOCKEVENTS_BROADCAST)
#error "This doesn't scale well! Need per-core local timers."
#endif
#else /* CONFIG_SMP */
#define stop_jiffies_counter1()
#define reload_jiffies_counter1(x)
#define TMJC1IRQ TMJCIRQ
#endif


static int next_event(unsigned long delta,
struct clock_event_device *evt)
{
unsigned int cpu = smp_processor_id();

if (cpu == 0) {
stop_jiffies_counter();
reload_jiffies_counter(delta - 1);
} else {
stop_jiffies_counter1();
reload_jiffies_counter1(delta - 1);
}
return 0;
}

static void set_clock_mode(enum clock_event_mode mode,
struct clock_event_device *evt)
{
/* Nothing to do ... */
}

static DEFINE_PER_CPU(struct clock_event_device, mn10300_clockevent_device);
static DEFINE_PER_CPU(struct irqaction, timer_irq);

static irqreturn_t timer_interrupt(int irq, void *dev_id)
{
struct clock_event_device *cd;
unsigned int cpu = smp_processor_id();

if (cpu == 0)
stop_jiffies_counter();
else
stop_jiffies_counter1();

cd = &per_cpu(mn10300_clockevent_device, cpu);
cd->event_handler(cd);

return IRQ_HANDLED;
}

static void event_handler(struct clock_event_device *dev)
{
}

int __init init_clockevents(void)
{
struct clock_event_device *cd;
struct irqaction *iact;
unsigned int cpu = smp_processor_id();

cd = &per_cpu(mn10300_clockevent_device, cpu);

if (cpu == 0) {
stop_jiffies_counter();
cd->irq = TMJCIRQ;
} else {
stop_jiffies_counter1();
cd->irq = TMJC1IRQ;
}

cd->name = "Timestamp";
cd->features = CLOCK_EVT_FEAT_ONESHOT;

/* Calculate the min / max delta */
clockevent_set_clock(cd, MN10300_JCCLK);

cd->max_delta_ns = clockevent_delta2ns(TMJCBR_MAX, cd);
cd->min_delta_ns = clockevent_delta2ns(100, cd);

cd->rating = 200;
cd->cpumask = cpumask_of(smp_processor_id());
cd->set_mode = set_clock_mode;
cd->event_handler = event_handler;
cd->set_next_event = next_event;

iact = &per_cpu(timer_irq, cpu);
iact->flags = IRQF_DISABLED | IRQF_SHARED | IRQF_TIMER;
iact->handler = timer_interrupt;

clockevents_register_device(cd);

#if defined(CONFIG_SMP) && !defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
/* setup timer irq affinity so it only runs on this cpu */
{
struct irq_desc *desc;
desc = irq_to_desc(cd->irq);
cpumask_copy(desc->affinity, cpumask_of(cpu));
iact->flags |= IRQF_NOBALANCING;
}
#endif

if (cpu == 0) {
reload_jiffies_counter(MN10300_JC_PER_HZ - 1);
iact->name = "CPU0 Timer";
} else {
reload_jiffies_counter1(MN10300_JC_PER_HZ - 1);
iact->name = "CPU1 Timer";
}

setup_jiffies_interrupt(cd->irq, iact);

return 0;
}
35 changes: 35 additions & 0 deletions arch/mn10300/kernel/csrc-mn10300.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* MN10300 clocksource
*
* Copyright (C) 2010 Red Hat, Inc. All Rights Reserved.
* Written by Mark Salter ([email protected])
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public Licence
* as published by the Free Software Foundation; either version
* 2 of the Licence, or (at your option) any later version.
*/
#include <linux/clocksource.h>
#include <linux/init.h>
#include <asm/timex.h>
#include "internal.h"

static cycle_t mn10300_read(struct clocksource *cs)
{
return read_timestamp_counter();
}

static struct clocksource clocksource_mn10300 = {
.name = "TSC",
.rating = 200,
.read = mn10300_read,
.mask = CLOCKSOURCE_MASK(32),
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
};

int __init init_clocksource(void)
{
startup_timestamp_counter();
clocksource_set_clock(&clocksource_mn10300, MN10300_TSCCLK);
clocksource_register(&clocksource_mn10300);
return 0;
}
13 changes: 13 additions & 0 deletions arch/mn10300/kernel/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* 2 of the Licence, or (at your option) any later version.
*/

struct clocksource;
struct clock_event_device;

/*
* kthread.S
*/
Expand All @@ -30,3 +33,13 @@ extern void mn10300_low_ipi_handler(void);
* time.c
*/
extern irqreturn_t local_timer_interrupt(void);

/*
* time.c
*/
#ifdef CONFIG_CEVT_MN10300
extern void clockevent_set_clock(struct clock_event_device *, unsigned int);
#endif
#ifdef CONFIG_CSRC_MN10300
extern void clocksource_set_clock(struct clocksource *, unsigned int);
#endif
32 changes: 13 additions & 19 deletions arch/mn10300/kernel/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
#include <asm/setup.h>
#include <asm/serial-regs.h>

#ifdef CONFIG_SMP
#undef GxICR
#define GxICR(X) CROSS_GxICR(X, irq_affinity_online[X])

#undef GxICR_u8
#define GxICR_u8(X) CROSS_GxICR_u8(X, irq_affinity_online[X])
#endif /* CONFIG_SMP */

unsigned long __mn10300_irq_enabled_epsw[NR_CPUS] __cacheline_aligned_in_smp = {
[0 ... NR_CPUS - 1] = EPSW_IE | EPSW_IM_7
};
Expand Down Expand Up @@ -92,9 +84,11 @@ static void mn10300_cpupic_mask_ack(unsigned int irq)
GxICR(irq) = (tmp & GxICR_LEVEL);
tmp2 = GxICR(irq);

irq_affinity_online[irq] = any_online_cpu(*irq_desc[irq].affinity);
GxICR(irq) = (tmp & (GxICR_LEVEL | GxICR_ENABLE)) | GxICR_DETECT;
tmp = GxICR(irq);
irq_affinity_online[irq] =
any_online_cpu(*irq_desc[irq].affinity);
CROSS_GxICR(irq, irq_affinity_online[irq]) =
(tmp & (GxICR_LEVEL | GxICR_ENABLE)) | GxICR_DETECT;
tmp = CROSS_GxICR(irq, irq_affinity_online[irq]);
}

arch_local_irq_restore(flags);
Expand Down Expand Up @@ -128,8 +122,8 @@ static void mn10300_cpupic_unmask_clear(unsigned int irq)
tmp = GxICR(irq);

irq_affinity_online[irq] = any_online_cpu(*irq_desc[irq].affinity);
GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
tmp = GxICR(irq);
CROSS_GxICR(irq, irq_affinity_online[irq]) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
tmp = CROSS_GxICR(irq, irq_affinity_online[irq]);
}

arch_local_irq_restore(flags);
Expand Down Expand Up @@ -217,7 +211,7 @@ static struct irq_chip mn10300_cpu_pic_level = {
.unmask = mn10300_cpupic_unmask_clear,
#ifdef CONFIG_SMP
.set_affinity = mn10300_cpupic_setaffinity,
#endif /* CONFIG_SMP */
#endif
};

/*
Expand All @@ -235,7 +229,7 @@ static struct irq_chip mn10300_cpu_pic_edge = {
.unmask = mn10300_cpupic_unmask,
#ifdef CONFIG_SMP
.set_affinity = mn10300_cpupic_setaffinity,
#endif /* CONFIG_SMP */
#endif
};

/*
Expand Down Expand Up @@ -446,9 +440,9 @@ void migrate_irqs(void)
if (irq_affinity_online[irq] == self) {
u16 x, tmp;

x = CROSS_GxICR(irq, self);
CROSS_GxICR(irq, self) = x & GxICR_LEVEL;
tmp = CROSS_GxICR(irq, self);
x = GxICR(irq);
GxICR(irq) = x & GxICR_LEVEL;
tmp = GxICR(irq);

new = any_online_cpu(irq_desc[irq].affinity);
irq_affinity_online[irq] = new;
Expand All @@ -458,7 +452,7 @@ void migrate_irqs(void)
tmp = CROSS_GxICR(irq, new);

x &= GxICR_LEVEL | GxICR_ENABLE;
if (CROSS_GxICR(irq, self) & GxICR_REQUEST)
if (GxICR(irq) & GxICR_REQUEST) {
x |= GxICR_REQUEST | GxICR_DETECT;
CROSS_GxICR(irq, new) = x;
tmp = CROSS_GxICR(irq, new);
Expand Down
Loading

0 comments on commit 730c1fa

Please sign in to comment.