aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clocksource
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2013-06-08 16:58:27 -0400
committerThomas Gleixner <tglx@linutronix.de>2013-06-08 16:58:27 -0400
commit762cf9695d714d312ef7369bed1b9f9467c9e64e (patch)
tree92fd329124ae6b4fab43c24e44d847fe6ae6401b /drivers/clocksource
parentce0b098981544d9f4e910ea48f3af3e726ca6d6b (diff)
parent77ba83bb1bb1cdabd522d32536f8eee65a870145 (diff)
Merge branch 'timers/clockevents' of git://git.linaro.org/people/dlezcano/clockevents into timers/core
Diffstat (limited to 'drivers/clocksource')
-rw-r--r--drivers/clocksource/Kconfig5
-rw-r--r--drivers/clocksource/Makefile2
-rw-r--r--drivers/clocksource/dw_apb_timer_of.c2
-rw-r--r--drivers/clocksource/vf_pit_timer.c194
-rw-r--r--drivers/clocksource/zevio-timer.c215
5 files changed, 417 insertions, 1 deletions
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index f151c6cf27c3..0a04257edf65 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -85,3 +85,8 @@ config CLKSRC_SAMSUNG_PWM
85 Samsung S3C, S5P and Exynos SoCs, replacing an earlier driver 85 Samsung S3C, S5P and Exynos SoCs, replacing an earlier driver
86 for all devicetree enabled platforms. This driver will be 86 for all devicetree enabled platforms. This driver will be
87 needed only on systems that do not have the Exynos MCT available. 87 needed only on systems that do not have the Exynos MCT available.
88
89config VF_PIT_TIMER
90 bool
91 help
92 Support for Period Interrupt Timer on Freescale Vybrid Family SoCs.
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index 8d979c72aa94..4853ea0f8fd5 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -22,10 +22,12 @@ obj-$(CONFIG_ARCH_PRIMA2) += timer-prima2.o
22obj-$(CONFIG_SUN4I_TIMER) += sun4i_timer.o 22obj-$(CONFIG_SUN4I_TIMER) += sun4i_timer.o
23obj-$(CONFIG_ARCH_TEGRA) += tegra20_timer.o 23obj-$(CONFIG_ARCH_TEGRA) += tegra20_timer.o
24obj-$(CONFIG_VT8500_TIMER) += vt8500_timer.o 24obj-$(CONFIG_VT8500_TIMER) += vt8500_timer.o
25obj-$(CONFIG_ARCH_NSPIRE) += zevio-timer.o
25obj-$(CONFIG_ARCH_BCM) += bcm_kona_timer.o 26obj-$(CONFIG_ARCH_BCM) += bcm_kona_timer.o
26obj-$(CONFIG_CADENCE_TTC_TIMER) += cadence_ttc_timer.o 27obj-$(CONFIG_CADENCE_TTC_TIMER) += cadence_ttc_timer.o
27obj-$(CONFIG_CLKSRC_EXYNOS_MCT) += exynos_mct.o 28obj-$(CONFIG_CLKSRC_EXYNOS_MCT) += exynos_mct.o
28obj-$(CONFIG_CLKSRC_SAMSUNG_PWM) += samsung_pwm_timer.o 29obj-$(CONFIG_CLKSRC_SAMSUNG_PWM) += samsung_pwm_timer.o
30obj-$(CONFIG_VF_PIT_TIMER) += vf_pit_timer.o
29 31
30obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o 32obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o
31obj-$(CONFIG_CLKSRC_METAG_GENERIC) += metag_generic.o 33obj-$(CONFIG_CLKSRC_METAG_GENERIC) += metag_generic.o
diff --git a/drivers/clocksource/dw_apb_timer_of.c b/drivers/clocksource/dw_apb_timer_of.c
index 8d2f809a0967..af13b8559b61 100644
--- a/drivers/clocksource/dw_apb_timer_of.c
+++ b/drivers/clocksource/dw_apb_timer_of.c
@@ -43,7 +43,7 @@ static void add_clockevent(struct device_node *event_timer)
43 u32 irq, rate; 43 u32 irq, rate;
44 44
45 irq = irq_of_parse_and_map(event_timer, 0); 45 irq = irq_of_parse_and_map(event_timer, 0);
46 if (irq == NO_IRQ) 46 if (irq == 0)
47 panic("No IRQ for clock event timer"); 47 panic("No IRQ for clock event timer");
48 48
49 timer_get_base_and_rate(event_timer, &iobase, &rate); 49 timer_get_base_and_rate(event_timer, &iobase, &rate);
diff --git a/drivers/clocksource/vf_pit_timer.c b/drivers/clocksource/vf_pit_timer.c
new file mode 100644
index 000000000000..598399d57fc5
--- /dev/null
+++ b/drivers/clocksource/vf_pit_timer.c
@@ -0,0 +1,194 @@
1/*
2 * Copyright 2012-2013 Freescale Semiconductor, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 */
9
10#include <linux/interrupt.h>
11#include <linux/clockchips.h>
12#include <linux/clk.h>
13#include <linux/of_address.h>
14#include <linux/of_irq.h>
15#include <asm/sched_clock.h>
16
17/*
18 * Each pit takes 0x10 Bytes register space
19 */
20#define PITMCR 0x00
21#define PIT0_OFFSET 0x100
22#define PITn_OFFSET(n) (PIT0_OFFSET + 0x10 * (n))
23#define PITLDVAL 0x00
24#define PITCVAL 0x04
25#define PITTCTRL 0x08
26#define PITTFLG 0x0c
27
28#define PITMCR_MDIS (0x1 << 1)
29
30#define PITTCTRL_TEN (0x1 << 0)
31#define PITTCTRL_TIE (0x1 << 1)
32#define PITCTRL_CHN (0x1 << 2)
33
34#define PITTFLG_TIF 0x1
35
36static void __iomem *clksrc_base;
37static void __iomem *clkevt_base;
38static unsigned long cycle_per_jiffy;
39
40static inline void pit_timer_enable(void)
41{
42 __raw_writel(PITTCTRL_TEN | PITTCTRL_TIE, clkevt_base + PITTCTRL);
43}
44
45static inline void pit_timer_disable(void)
46{
47 __raw_writel(0, clkevt_base + PITTCTRL);
48}
49
50static inline void pit_irq_acknowledge(void)
51{
52 __raw_writel(PITTFLG_TIF, clkevt_base + PITTFLG);
53}
54
55static unsigned int pit_read_sched_clock(void)
56{
57 return __raw_readl(clksrc_base + PITCVAL);
58}
59
60static int __init pit_clocksource_init(unsigned long rate)
61{
62 /* set the max load value and start the clock source counter */
63 __raw_writel(0, clksrc_base + PITTCTRL);
64 __raw_writel(~0UL, clksrc_base + PITLDVAL);
65 __raw_writel(PITTCTRL_TEN, clksrc_base + PITTCTRL);
66
67 setup_sched_clock(pit_read_sched_clock, 32, rate);
68 return clocksource_mmio_init(clksrc_base + PITCVAL, "vf-pit", rate,
69 300, 32, clocksource_mmio_readl_down);
70}
71
72static int pit_set_next_event(unsigned long delta,
73 struct clock_event_device *unused)
74{
75 /*
76 * set a new value to PITLDVAL register will not restart the timer,
77 * to abort the current cycle and start a timer period with the new
78 * value, the timer must be disabled and enabled again.
79 * and the PITLAVAL should be set to delta minus one according to pit
80 * hardware requirement.
81 */
82 pit_timer_disable();
83 __raw_writel(delta - 1, clkevt_base + PITLDVAL);
84 pit_timer_enable();
85
86 return 0;
87}
88
89static void pit_set_mode(enum clock_event_mode mode,
90 struct clock_event_device *evt)
91{
92 switch (mode) {
93 case CLOCK_EVT_MODE_PERIODIC:
94 pit_set_next_event(cycle_per_jiffy, evt);
95 break;
96 default:
97 break;
98 }
99}
100
101static irqreturn_t pit_timer_interrupt(int irq, void *dev_id)
102{
103 struct clock_event_device *evt = dev_id;
104
105 pit_irq_acknowledge();
106
107 /*
108 * pit hardware doesn't support oneshot, it will generate an interrupt
109 * and reload the counter value from PITLDVAL when PITCVAL reach zero,
110 * and start the counter again. So software need to disable the timer
111 * to stop the counter loop in ONESHOT mode.
112 */
113 if (likely(evt->mode == CLOCK_EVT_MODE_ONESHOT))
114 pit_timer_disable();
115
116 evt->event_handler(evt);
117
118 return IRQ_HANDLED;
119}
120
121static struct clock_event_device clockevent_pit = {
122 .name = "VF pit timer",
123 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
124 .set_mode = pit_set_mode,
125 .set_next_event = pit_set_next_event,
126 .rating = 300,
127};
128
129static struct irqaction pit_timer_irq = {
130 .name = "VF pit timer",
131 .flags = IRQF_TIMER | IRQF_IRQPOLL,
132 .handler = pit_timer_interrupt,
133 .dev_id = &clockevent_pit,
134};
135
136static int __init pit_clockevent_init(unsigned long rate, int irq)
137{
138 __raw_writel(0, clkevt_base + PITTCTRL);
139 __raw_writel(PITTFLG_TIF, clkevt_base + PITTFLG);
140
141 BUG_ON(setup_irq(irq, &pit_timer_irq));
142
143 clockevent_pit.cpumask = cpumask_of(0);
144 clockevent_pit.irq = irq;
145 /*
146 * The value for the LDVAL register trigger is calculated as:
147 * LDVAL trigger = (period / clock period) - 1
148 * The pit is a 32-bit down count timer, when the conter value
149 * reaches 0, it will generate an interrupt, thus the minimal
150 * LDVAL trigger value is 1. And then the min_delta is
151 * minimal LDVAL trigger value + 1, and the max_delta is full 32-bit.
152 */
153 clockevents_config_and_register(&clockevent_pit, rate, 2, 0xffffffff);
154
155 return 0;
156}
157
158static void __init pit_timer_init(struct device_node *np)
159{
160 struct clk *pit_clk;
161 void __iomem *timer_base;
162 unsigned long clk_rate;
163 int irq;
164
165 timer_base = of_iomap(np, 0);
166 BUG_ON(!timer_base);
167
168 /*
169 * PIT0 and PIT1 can be chained to build a 64-bit timer,
170 * so choose PIT2 as clocksource, PIT3 as clockevent device,
171 * and leave PIT0 and PIT1 unused for anyone else who needs them.
172 */
173 clksrc_base = timer_base + PITn_OFFSET(2);
174 clkevt_base = timer_base + PITn_OFFSET(3);
175
176 irq = irq_of_parse_and_map(np, 0);
177 BUG_ON(irq <= 0);
178
179 pit_clk = of_clk_get(np, 0);
180 BUG_ON(IS_ERR(pit_clk));
181
182 BUG_ON(clk_prepare_enable(pit_clk));
183
184 clk_rate = clk_get_rate(pit_clk);
185 cycle_per_jiffy = clk_rate / (HZ);
186
187 /* enable the pit module */
188 __raw_writel(~PITMCR_MDIS, timer_base + PITMCR);
189
190 BUG_ON(pit_clocksource_init(clk_rate));
191
192 pit_clockevent_init(clk_rate, irq);
193}
194CLOCKSOURCE_OF_DECLARE(vf610, "fsl,vf610-pit", pit_timer_init);
diff --git a/drivers/clocksource/zevio-timer.c b/drivers/clocksource/zevio-timer.c
new file mode 100644
index 000000000000..ca81809d159d
--- /dev/null
+++ b/drivers/clocksource/zevio-timer.c
@@ -0,0 +1,215 @@
1/*
2 * linux/drivers/clocksource/zevio-timer.c
3 *
4 * Copyright (C) 2013 Daniel Tang <tangrs@tangrs.id.au>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
9 *
10 */
11
12#include <linux/io.h>
13#include <linux/irq.h>
14#include <linux/of.h>
15#include <linux/of_address.h>
16#include <linux/of_irq.h>
17#include <linux/clk.h>
18#include <linux/clockchips.h>
19#include <linux/cpumask.h>
20#include <linux/interrupt.h>
21#include <linux/slab.h>
22
23#define IO_CURRENT_VAL 0x00
24#define IO_DIVIDER 0x04
25#define IO_CONTROL 0x08
26
27#define IO_TIMER1 0x00
28#define IO_TIMER2 0x0C
29
30#define IO_MATCH_BEGIN 0x18
31#define IO_MATCH(x) (IO_MATCH_BEGIN + ((x) << 2))
32
33#define IO_INTR_STS 0x00
34#define IO_INTR_ACK 0x00
35#define IO_INTR_MSK 0x04
36
37#define CNTL_STOP_TIMER (1 << 4)
38#define CNTL_RUN_TIMER (0 << 4)
39
40#define CNTL_INC (1 << 3)
41#define CNTL_DEC (0 << 3)
42
43#define CNTL_TOZERO 0
44#define CNTL_MATCH(x) ((x) + 1)
45#define CNTL_FOREVER 7
46
47/* There are 6 match registers but we only use one. */
48#define TIMER_MATCH 0
49
50#define TIMER_INTR_MSK (1 << (TIMER_MATCH))
51#define TIMER_INTR_ALL 0x3F
52
53struct zevio_timer {
54 void __iomem *base;
55 void __iomem *timer1, *timer2;
56 void __iomem *interrupt_regs;
57
58 struct clk *clk;
59 struct clock_event_device clkevt;
60 struct irqaction clkevt_irq;
61
62 char clocksource_name[64];
63 char clockevent_name[64];
64};
65
66static int zevio_timer_set_event(unsigned long delta,
67 struct clock_event_device *dev)
68{
69 struct zevio_timer *timer = container_of(dev, struct zevio_timer,
70 clkevt);
71
72 writel(delta, timer->timer1 + IO_CURRENT_VAL);
73 writel(CNTL_RUN_TIMER | CNTL_DEC | CNTL_MATCH(TIMER_MATCH),
74 timer->timer1 + IO_CONTROL);
75
76 return 0;
77}
78
79static void zevio_timer_set_mode(enum clock_event_mode mode,
80 struct clock_event_device *dev)
81{
82 struct zevio_timer *timer = container_of(dev, struct zevio_timer,
83 clkevt);
84
85 switch (mode) {
86 case CLOCK_EVT_MODE_RESUME:
87 case CLOCK_EVT_MODE_ONESHOT:
88 /* Enable timer interrupts */
89 writel(TIMER_INTR_MSK, timer->interrupt_regs + IO_INTR_MSK);
90 writel(TIMER_INTR_ALL, timer->interrupt_regs + IO_INTR_ACK);
91 break;
92 case CLOCK_EVT_MODE_SHUTDOWN:
93 case CLOCK_EVT_MODE_UNUSED:
94 /* Disable timer interrupts */
95 writel(0, timer->interrupt_regs + IO_INTR_MSK);
96 writel(TIMER_INTR_ALL, timer->interrupt_regs + IO_INTR_ACK);
97 /* Stop timer */
98 writel(CNTL_STOP_TIMER, timer->timer1 + IO_CONTROL);
99 break;
100 case CLOCK_EVT_MODE_PERIODIC:
101 default:
102 /* Unsupported */
103 break;
104 }
105}
106
107static irqreturn_t zevio_timer_interrupt(int irq, void *dev_id)
108{
109 struct zevio_timer *timer = dev_id;
110 u32 intr;
111
112 intr = readl(timer->interrupt_regs + IO_INTR_ACK);
113 if (!(intr & TIMER_INTR_MSK))
114 return IRQ_NONE;
115
116 writel(TIMER_INTR_MSK, timer->interrupt_regs + IO_INTR_ACK);
117 writel(CNTL_STOP_TIMER, timer->timer1 + IO_CONTROL);
118
119 if (timer->clkevt.event_handler)
120 timer->clkevt.event_handler(&timer->clkevt);
121
122 return IRQ_HANDLED;
123}
124
125static int __init zevio_timer_add(struct device_node *node)
126{
127 struct zevio_timer *timer;
128 struct resource res;
129 int irqnr, ret;
130
131 timer = kzalloc(sizeof(*timer), GFP_KERNEL);
132 if (!timer)
133 return -ENOMEM;
134
135 timer->base = of_iomap(node, 0);
136 if (!timer->base) {
137 ret = -EINVAL;
138 goto error_free;
139 }
140 timer->timer1 = timer->base + IO_TIMER1;
141 timer->timer2 = timer->base + IO_TIMER2;
142
143 timer->clk = of_clk_get(node, 0);
144 if (IS_ERR(timer->clk)) {
145 ret = PTR_ERR(timer->clk);
146 pr_err("Timer clock not found! (error %d)\n", ret);
147 goto error_unmap;
148 }
149
150 timer->interrupt_regs = of_iomap(node, 1);
151 irqnr = irq_of_parse_and_map(node, 0);
152
153 of_address_to_resource(node, 0, &res);
154 scnprintf(timer->clocksource_name, sizeof(timer->clocksource_name),
155 "%llx.%s_clocksource",
156 (unsigned long long)res.start, node->name);
157
158 scnprintf(timer->clockevent_name, sizeof(timer->clockevent_name),
159 "%llx.%s_clockevent",
160 (unsigned long long)res.start, node->name);
161
162 if (timer->interrupt_regs && irqnr) {
163 timer->clkevt.name = timer->clockevent_name;
164 timer->clkevt.set_next_event = zevio_timer_set_event;
165 timer->clkevt.set_mode = zevio_timer_set_mode;
166 timer->clkevt.rating = 200;
167 timer->clkevt.cpumask = cpu_all_mask;
168 timer->clkevt.features = CLOCK_EVT_FEAT_ONESHOT;
169 timer->clkevt.irq = irqnr;
170
171 writel(CNTL_STOP_TIMER, timer->timer1 + IO_CONTROL);
172 writel(0, timer->timer1 + IO_DIVIDER);
173
174 /* Start with timer interrupts disabled */
175 writel(0, timer->interrupt_regs + IO_INTR_MSK);
176 writel(TIMER_INTR_ALL, timer->interrupt_regs + IO_INTR_ACK);
177
178 /* Interrupt to occur when timer value matches 0 */
179 writel(0, timer->base + IO_MATCH(TIMER_MATCH));
180
181 timer->clkevt_irq.name = timer->clockevent_name;
182 timer->clkevt_irq.handler = zevio_timer_interrupt;
183 timer->clkevt_irq.dev_id = timer;
184 timer->clkevt_irq.flags = IRQF_TIMER | IRQF_IRQPOLL;
185
186 setup_irq(irqnr, &timer->clkevt_irq);
187
188 clockevents_config_and_register(&timer->clkevt,
189 clk_get_rate(timer->clk), 0x0001, 0xffff);
190 pr_info("Added %s as clockevent\n", timer->clockevent_name);
191 }
192
193 writel(CNTL_STOP_TIMER, timer->timer2 + IO_CONTROL);
194 writel(0, timer->timer2 + IO_CURRENT_VAL);
195 writel(0, timer->timer2 + IO_DIVIDER);
196 writel(CNTL_RUN_TIMER | CNTL_FOREVER | CNTL_INC,
197 timer->timer2 + IO_CONTROL);
198
199 clocksource_mmio_init(timer->timer2 + IO_CURRENT_VAL,
200 timer->clocksource_name,
201 clk_get_rate(timer->clk),
202 200, 16,
203 clocksource_mmio_readw_up);
204
205 pr_info("Added %s as clocksource\n", timer->clocksource_name);
206
207 return 0;
208error_unmap:
209 iounmap(timer->base);
210error_free:
211 kfree(timer);
212 return ret;
213}
214
215CLOCKSOURCE_OF_DECLARE(zevio_timer, "lsi,zevio-timer", zevio_timer_add);