Skip to content

Commit

Permalink
Merge tag 'clksrc-cleanup-for-3.10-part2' of git://sources.calxeda.co…
Browse files Browse the repository at this point in the history
…m/kernel/linux into late/clksrc

This is the 2nd part of ARM timer clean-ups for 3.10. This series has
the following changes:

- Add sched_clock selection logic to select the highest frequency clock
- Use full 64-bit arch timer counter for sched_clock
- Convert arch timer, sp804 and integrator-cp timers to CLKSRC_OF and
adapt all users to use clocksource_of_init

* tag 'clksrc-cleanup-for-3.10-part2' of git://sources.calxeda.com/kernel/linux:
  devtree: add binding documentation for sp804
  ARM: integrator-cp: convert use CLKSRC_OF for timer init
  ARM: versatile: use OF init for sp804 timer
  ARM: versatile: add versatile dtbs to dtbs target
  ARM: vexpress: remove extra timer-sp control register clearing
  ARM: dts: vexpress: disable CA9 core tile sp804 timer
  ARM: vexpress: remove sp804 OF init
  ARM: highbank: use OF init for sp804 timer
  ARM: timer-sp: convert to use CLKSRC_OF init
  OF: add empty of_device_is_available for !OF
  ARM: convert arm/arm64 arch timer to use CLKSRC_OF init
  ARM: make machine_desc->init_time default to clocksource_of_init
  ARM: arch_timer: use full 64-bit counter for sched_clock
  ARM: make sched_clock just call a function pointer
  ARM: sched_clock: allow changing to higher frequency counter

Signed-off-by: Olof Johansson <olof@lixom.net>

This has a nasty set of conflicts with the exynos MCT code, which was
moved in a separate branch, and then fixed up when merged in, but still
conflicts a bit here. It should have been sorted out by this merge though.
  • Loading branch information
Olof Johansson committed Apr 17, 2013
2 parents 228e302 + 69a517b commit c3e0c87
Show file tree
Hide file tree
Showing 34 changed files with 262 additions and 191 deletions.
29 changes: 29 additions & 0 deletions Documentation/devicetree/bindings/timer/arm,sp804.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ARM sp804 Dual Timers
---------------------------------------

Required properties:
- compatible: Should be "arm,sp804" & "arm,primecell"
- interrupts: Should contain the list of Dual Timer interrupts. This is the
interrupt for timer 1 and timer 2. In the case of a single entry, it is
the combined interrupt or if "arm,sp804-has-irq" is present that
specifies which timer interrupt is connected.
- reg: Should contain location and length for dual timer register.
- clocks: clocks driving the dual timer hardware. This list should be 1 or 3
clocks. With 3 clocks, the order is timer0 clock, timer1 clock,
apb_pclk. A single clock can also be specified if the same clock is
used for all clock inputs.

Optional properties:
- arm,sp804-has-irq = <#>: In the case of only 1 timer irq line connected, this
specifies if the irq connection is for timer 1 or timer 2. A value of 1
or 2 should be used.

Example:

timer0: timer@fc800000 {
compatible = "arm,sp804", "arm,primecell";
reg = <0xfc800000 0x1000>;
interrupts = <0 0 4>, <0 1 4>;
clocks = <&timclk1 &timclk2 &pclk>;
clock-names = "timer1", "timer2", "apb_pclk";
};
1 change: 1 addition & 0 deletions arch/arm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ config PLAT_VERSATILE
config ARM_TIMER_SP804
bool
select CLKSRC_MMIO
select CLKSRC_OF if OF
select HAVE_SCHED_CLOCK

source arch/arm/mm/Kconfig
Expand Down
2 changes: 2 additions & 0 deletions arch/arm/boot/dts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ dtb-$(CONFIG_ARCH_TEGRA) += tegra20-harmony.dtb \
tegra30-cardhu-a04.dtb \
tegra114-dalmore.dtb \
tegra114-pluto.dtb
dtb-$(CONFIG_ARCH_VERSATILE) += versatile-ab.dtb \
versatile-pb.dtb
dtb-$(CONFIG_ARCH_VEXPRESS) += vexpress-v2p-ca5s.dtb \
vexpress-v2p-ca9.dtb \
vexpress-v2p-ca15-tc1.dtb \
Expand Down
6 changes: 3 additions & 3 deletions arch/arm/boot/dts/integratorcp.dts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
};

timer0: timer@13000000 {
compatible = "arm,sp804", "arm,primecell";
compatible = "arm,integrator-cp-timer";
};

timer1: timer@13000100 {
compatible = "arm,sp804", "arm,primecell";
compatible = "arm,integrator-cp-timer";
};

timer2: timer@13000200 {
compatible = "arm,sp804", "arm,primecell";
compatible = "arm,integrator-cp-timer";
};

pic: pic@14000000 {
Expand Down
12 changes: 12 additions & 0 deletions arch/arm/boot/dts/versatile-ab.dts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@
interrupts = <0>;
};

timer@101e2000 {
compatible = "arm,sp804", "arm,primecell";
reg = <0x101e2000 0x1000>;
interrupts = <4>;
};

timer@101e3000 {
compatible = "arm,sp804", "arm,primecell";
reg = <0x101e3000 0x1000>;
interrupts = <5>;
};

gpio0: gpio@101e4000 {
compatible = "arm,pl061", "arm,primecell";
reg = <0x101e4000 0x1000>;
Expand Down
1 change: 1 addition & 0 deletions arch/arm/boot/dts/vexpress-v2p-ca9.dts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<0 49 4>;
clocks = <&oscclk2>, <&oscclk2>;
clock-names = "timclk", "apb_pclk";
status = "disabled";
};

watchdog@100e5000 {
Expand Down
140 changes: 124 additions & 16 deletions arch/arm/common/timer-sp.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,37 @@
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>

#include <asm/sched_clock.h>
#include <asm/hardware/arm_timer.h>
#include <asm/hardware/timer-sp.h>

static long __init sp804_get_clock_rate(const char *name)
static long __init sp804_get_clock_rate(struct clk *clk)
{
struct clk *clk;
long rate;
int err;

clk = clk_get_sys("sp804", name);
if (IS_ERR(clk)) {
pr_err("sp804: %s clock not found: %d\n", name,
(int)PTR_ERR(clk));
return PTR_ERR(clk);
}

err = clk_prepare(clk);
if (err) {
pr_err("sp804: %s clock failed to prepare: %d\n", name, err);
pr_err("sp804: clock failed to prepare: %d\n", err);
clk_put(clk);
return err;
}

err = clk_enable(clk);
if (err) {
pr_err("sp804: %s clock failed to enable: %d\n", name, err);
pr_err("sp804: clock failed to enable: %d\n", err);
clk_unprepare(clk);
clk_put(clk);
return err;
}

rate = clk_get_rate(clk);
if (rate < 0) {
pr_err("sp804: %s clock failed to get rate: %ld\n", name, rate);
pr_err("sp804: clock failed to get rate: %ld\n", rate);
clk_disable(clk);
clk_unprepare(clk);
clk_put(clk);
Expand All @@ -77,9 +73,21 @@ static u32 sp804_read(void)

void __init __sp804_clocksource_and_sched_clock_init(void __iomem *base,
const char *name,
struct clk *clk,
int use_sched_clock)
{
long rate = sp804_get_clock_rate(name);
long rate;

if (!clk) {
clk = clk_get_sys("sp804", name);
if (IS_ERR(clk)) {
pr_err("sp804: clock not found: %d\n",
(int)PTR_ERR(clk));
return;
}
}

rate = sp804_get_clock_rate(clk);

if (rate < 0)
return;
Expand Down Expand Up @@ -171,12 +179,20 @@ static struct irqaction sp804_timer_irq = {
.dev_id = &sp804_clockevent,
};

void __init sp804_clockevents_init(void __iomem *base, unsigned int irq,
const char *name)
void __init __sp804_clockevents_init(void __iomem *base, unsigned int irq, struct clk *clk, const char *name)
{
struct clock_event_device *evt = &sp804_clockevent;
long rate = sp804_get_clock_rate(name);
long rate;

if (!clk)
clk = clk_get_sys("sp804", name);
if (IS_ERR(clk)) {
pr_err("sp804: %s clock not found: %d\n", name,
(int)PTR_ERR(clk));
return;
}

rate = sp804_get_clock_rate(clk);
if (rate < 0)
return;

Expand All @@ -186,6 +202,98 @@ void __init sp804_clockevents_init(void __iomem *base, unsigned int irq,
evt->irq = irq;
evt->cpumask = cpu_possible_mask;

writel(0, base + TIMER_CTRL);

setup_irq(irq, &sp804_timer_irq);
clockevents_config_and_register(evt, rate, 0xf, 0xffffffff);
}

static void __init sp804_of_init(struct device_node *np)
{
static bool initialized = false;
void __iomem *base;
int irq;
u32 irq_num = 0;
struct clk *clk1, *clk2;
const char *name = of_get_property(np, "compatible", NULL);

base = of_iomap(np, 0);
if (WARN_ON(!base))
return;

/* Ensure timers are disabled */
writel(0, base + TIMER_CTRL);
writel(0, base + TIMER_2_BASE + TIMER_CTRL);

if (initialized || !of_device_is_available(np))
goto err;

clk1 = of_clk_get(np, 0);
if (IS_ERR(clk1))
clk1 = NULL;

/* Get the 2nd clock if the timer has 2 timer clocks */
if (of_count_phandle_with_args(np, "clocks", "#clock-cells") == 3) {
clk2 = of_clk_get(np, 1);
if (IS_ERR(clk2)) {
pr_err("sp804: %s clock not found: %d\n", np->name,
(int)PTR_ERR(clk2));
goto err;
}
} else
clk2 = clk1;

irq = irq_of_parse_and_map(np, 0);
if (irq <= 0)
goto err;

of_property_read_u32(np, "arm,sp804-has-irq", &irq_num);
if (irq_num == 2) {
__sp804_clockevents_init(base + TIMER_2_BASE, irq, clk2, name);
__sp804_clocksource_and_sched_clock_init(base, name, clk1, 1);
} else {
__sp804_clockevents_init(base, irq, clk1 , name);
__sp804_clocksource_and_sched_clock_init(base + TIMER_2_BASE,
name, clk2, 1);
}
initialized = true;

return;
err:
iounmap(base);
}
CLOCKSOURCE_OF_DECLARE(sp804, "arm,sp804", sp804_of_init);

static void __init integrator_cp_of_init(struct device_node *np)
{
static int init_count = 0;
void __iomem *base;
int irq;
const char *name = of_get_property(np, "compatible", NULL);

base = of_iomap(np, 0);
if (WARN_ON(!base))
return;

/* Ensure timer is disabled */
writel(0, base + TIMER_CTRL);

if (init_count == 2 || !of_device_is_available(np))
goto err;

if (!init_count)
sp804_clocksource_init(base, name);
else {
irq = irq_of_parse_and_map(np, 0);
if (irq <= 0)
goto err;

sp804_clockevents_init(base, irq, name);
}

init_count++;
return;
err:
iounmap(base);
}
CLOCKSOURCE_OF_DECLARE(intcp, "arm,integrator-cp-timer", integrator_cp_of_init);
13 changes: 1 addition & 12 deletions arch/arm/include/asm/arch_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include <clocksource/arm_arch_timer.h>

#ifdef CONFIG_ARM_ARCH_TIMER
int arch_timer_of_register(void);
int arch_timer_sched_clock_init(void);
int arch_timer_arch_init(void);

/*
* These register accessors are marked inline so the compiler can
Expand Down Expand Up @@ -110,16 +109,6 @@ static inline void __cpuinit arch_counter_set_user_access(void)

asm volatile("mcr p15, 0, %0, c14, c1, 0" : : "r" (cntkctl));
}
#else
static inline int arch_timer_of_register(void)
{
return -ENXIO;
}

static inline int arch_timer_sched_clock_init(void)
{
return -ENXIO;
}
#endif

#endif
16 changes: 12 additions & 4 deletions arch/arm/include/asm/hardware/timer-sp.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
struct clk;

void __sp804_clocksource_and_sched_clock_init(void __iomem *,
const char *, int);
const char *, struct clk *, int);
void __sp804_clockevents_init(void __iomem *, unsigned int,
struct clk *, const char *);

static inline void sp804_clocksource_init(void __iomem *base, const char *name)
{
__sp804_clocksource_and_sched_clock_init(base, name, 0);
__sp804_clocksource_and_sched_clock_init(base, name, NULL, 0);
}

static inline void sp804_clocksource_and_sched_clock_init(void __iomem *base,
const char *name)
{
__sp804_clocksource_and_sched_clock_init(base, name, 1);
__sp804_clocksource_and_sched_clock_init(base, name, NULL, 1);
}

void sp804_clockevents_init(void __iomem *, unsigned int, const char *);
static inline void sp804_clockevents_init(void __iomem *base, unsigned int irq, const char *name)
{
__sp804_clockevents_init(base, irq, NULL, name);

}
2 changes: 2 additions & 0 deletions arch/arm/include/asm/sched_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
extern void sched_clock_postinit(void);
extern void setup_sched_clock(u32 (*read)(void), int bits, unsigned long rate);

extern unsigned long long (*sched_clock_func)(void);

#endif
29 changes: 13 additions & 16 deletions arch/arm/kernel/arch_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ static unsigned long arch_timer_read_counter_long(void)
return arch_timer_read_counter();
}

static u32 arch_timer_read_counter_u32(void)
static u32 sched_clock_mult __read_mostly;

static unsigned long long notrace arch_timer_sched_clock(void)
{
return arch_timer_read_counter();
return arch_timer_read_counter() * sched_clock_mult;
}

static struct delay_timer arch_delay_timer;
Expand All @@ -37,25 +39,20 @@ static void __init arch_timer_delay_timer_register(void)
register_current_timer_delay(&arch_delay_timer);
}

int __init arch_timer_of_register(void)
int __init arch_timer_arch_init(void)
{
int ret;
u32 arch_timer_rate = arch_timer_get_rate();

ret = arch_timer_init();
if (ret)
return ret;
if (arch_timer_rate == 0)
return -ENXIO;

arch_timer_delay_timer_register();

return 0;
}

int __init arch_timer_sched_clock_init(void)
{
if (arch_timer_get_rate() == 0)
return -ENXIO;
/* Cache the sched_clock multiplier to save a divide in the hot path. */
sched_clock_mult = NSEC_PER_SEC / arch_timer_rate;
sched_clock_func = arch_timer_sched_clock;
pr_info("sched_clock: ARM arch timer >56 bits at %ukHz, resolution %uns\n",
arch_timer_rate / 1000, sched_clock_mult);

setup_sched_clock(arch_timer_read_counter_u32,
32, arch_timer_get_rate());
return 0;
}
Loading

0 comments on commit c3e0c87

Please sign in to comment.