Skip to content

Commit ab5354c

Browse files
rjarzmikdlezcano
authored andcommitted
clocksource: pxa: Add device-tree support for PXA timer
Add device-tree support to PXA platforms. The driver still needs to maintain backward non device-tree compatibility as well, which implies : - a non device-tree init function - a static registers base address in the driver Signed-off-by: Robert Jarzmik <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]>
1 parent c5421d7 commit ab5354c

File tree

1 file changed

+101
-36
lines changed

1 file changed

+101
-36
lines changed

drivers/clocksource/pxa_timer.c

Lines changed: 101 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,30 @@
1515
#include <linux/kernel.h>
1616
#include <linux/init.h>
1717
#include <linux/interrupt.h>
18+
#include <linux/clk.h>
1819
#include <linux/clockchips.h>
20+
#include <linux/of_address.h>
21+
#include <linux/of_irq.h>
1922
#include <linux/sched_clock.h>
2023

2124
#include <asm/div64.h>
22-
#include <asm/mach/irq.h>
23-
#include <asm/mach/time.h>
24-
#include <mach/regs-ost.h>
25-
#include <mach/irqs.h>
25+
26+
#define OSMR0 0x00 /* OS Timer 0 Match Register */
27+
#define OSMR1 0x04 /* OS Timer 1 Match Register */
28+
#define OSMR2 0x08 /* OS Timer 2 Match Register */
29+
#define OSMR3 0x0C /* OS Timer 3 Match Register */
30+
31+
#define OSCR 0x10 /* OS Timer Counter Register */
32+
#define OSSR 0x14 /* OS Timer Status Register */
33+
#define OWER 0x18 /* OS Timer Watchdog Enable Register */
34+
#define OIER 0x1C /* OS Timer Interrupt Enable Register */
35+
36+
#define OSSR_M3 (1 << 3) /* Match status channel 3 */
37+
#define OSSR_M2 (1 << 2) /* Match status channel 2 */
38+
#define OSSR_M1 (1 << 1) /* Match status channel 1 */
39+
#define OSSR_M0 (1 << 0) /* Match status channel 0 */
40+
41+
#define OIER_E0 (1 << 0) /* Interrupt enable channel 0 */
2642

2743
/*
2844
* This is PXA's sched_clock implementation. This has a resolution
@@ -33,9 +49,14 @@
3349
* calls to sched_clock() which should always be the case in practice.
3450
*/
3551

52+
#define timer_readl(reg) readl_relaxed(timer_base + (reg))
53+
#define timer_writel(val, reg) writel_relaxed((val), timer_base + (reg))
54+
55+
static void __iomem *timer_base;
56+
3657
static u64 notrace pxa_read_sched_clock(void)
3758
{
38-
return readl_relaxed(OSCR);
59+
return timer_readl(OSCR);
3960
}
4061

4162

@@ -47,8 +68,8 @@ pxa_ost0_interrupt(int irq, void *dev_id)
4768
struct clock_event_device *c = dev_id;
4869

4970
/* Disarm the compare/match, signal the event. */
50-
writel_relaxed(readl_relaxed(OIER) & ~OIER_E0, OIER);
51-
writel_relaxed(OSSR_M0, OSSR);
71+
timer_writel(timer_readl(OIER) & ~OIER_E0, OIER);
72+
timer_writel(OSSR_M0, OSSR);
5273
c->event_handler(c);
5374

5475
return IRQ_HANDLED;
@@ -59,10 +80,10 @@ pxa_osmr0_set_next_event(unsigned long delta, struct clock_event_device *dev)
5980
{
6081
unsigned long next, oscr;
6182

62-
writel_relaxed(readl_relaxed(OIER) | OIER_E0, OIER);
63-
next = readl_relaxed(OSCR) + delta;
64-
writel_relaxed(next, OSMR0);
65-
oscr = readl_relaxed(OSCR);
83+
timer_writel(timer_readl(OIER) | OIER_E0, OIER);
84+
next = timer_readl(OSCR) + delta;
85+
timer_writel(next, OSMR0);
86+
oscr = timer_readl(OSCR);
6687

6788
return (signed)(next - oscr) <= MIN_OSCR_DELTA ? -ETIME : 0;
6889
}
@@ -72,15 +93,15 @@ pxa_osmr0_set_mode(enum clock_event_mode mode, struct clock_event_device *dev)
7293
{
7394
switch (mode) {
7495
case CLOCK_EVT_MODE_ONESHOT:
75-
writel_relaxed(readl_relaxed(OIER) & ~OIER_E0, OIER);
76-
writel_relaxed(OSSR_M0, OSSR);
96+
timer_writel(timer_readl(OIER) & ~OIER_E0, OIER);
97+
timer_writel(OSSR_M0, OSSR);
7798
break;
7899

79100
case CLOCK_EVT_MODE_UNUSED:
80101
case CLOCK_EVT_MODE_SHUTDOWN:
81102
/* initializing, released, or preparing for suspend */
82-
writel_relaxed(readl_relaxed(OIER) & ~OIER_E0, OIER);
83-
writel_relaxed(OSSR_M0, OSSR);
103+
timer_writel(timer_readl(OIER) & ~OIER_E0, OIER);
104+
timer_writel(OSSR_M0, OSSR);
84105
break;
85106

86107
case CLOCK_EVT_MODE_RESUME:
@@ -94,12 +115,12 @@ static unsigned long osmr[4], oier, oscr;
94115

95116
static void pxa_timer_suspend(struct clock_event_device *cedev)
96117
{
97-
osmr[0] = readl_relaxed(OSMR0);
98-
osmr[1] = readl_relaxed(OSMR1);
99-
osmr[2] = readl_relaxed(OSMR2);
100-
osmr[3] = readl_relaxed(OSMR3);
101-
oier = readl_relaxed(OIER);
102-
oscr = readl_relaxed(OSCR);
118+
osmr[0] = timer_readl(OSMR0);
119+
osmr[1] = timer_readl(OSMR1);
120+
osmr[2] = timer_readl(OSMR2);
121+
osmr[3] = timer_readl(OSMR3);
122+
oier = timer_readl(OIER);
123+
oscr = timer_readl(OSCR);
103124
}
104125

105126
static void pxa_timer_resume(struct clock_event_device *cedev)
@@ -113,12 +134,12 @@ static void pxa_timer_resume(struct clock_event_device *cedev)
113134
if (osmr[0] - oscr < MIN_OSCR_DELTA)
114135
osmr[0] += MIN_OSCR_DELTA;
115136

116-
writel_relaxed(osmr[0], OSMR0);
117-
writel_relaxed(osmr[1], OSMR1);
118-
writel_relaxed(osmr[2], OSMR2);
119-
writel_relaxed(osmr[3], OSMR3);
120-
writel_relaxed(oier, OIER);
121-
writel_relaxed(oscr, OSCR);
137+
timer_writel(osmr[0], OSMR0);
138+
timer_writel(osmr[1], OSMR1);
139+
timer_writel(osmr[2], OSMR2);
140+
timer_writel(osmr[3], OSMR3);
141+
timer_writel(oier, OIER);
142+
timer_writel(oscr, OSCR);
122143
}
123144
#else
124145
#define pxa_timer_suspend NULL
@@ -142,21 +163,65 @@ static struct irqaction pxa_ost0_irq = {
142163
.dev_id = &ckevt_pxa_osmr0,
143164
};
144165

145-
void __init pxa_timer_init(void)
166+
static void pxa_timer_common_init(int irq, unsigned long clock_tick_rate)
146167
{
147-
unsigned long clock_tick_rate = get_clock_tick_rate();
148-
149-
writel_relaxed(0, OIER);
150-
writel_relaxed(OSSR_M0 | OSSR_M1 | OSSR_M2 | OSSR_M3, OSSR);
168+
timer_writel(0, OIER);
169+
timer_writel(OSSR_M0 | OSSR_M1 | OSSR_M2 | OSSR_M3, OSSR);
151170

152171
sched_clock_register(pxa_read_sched_clock, 32, clock_tick_rate);
153172

154173
ckevt_pxa_osmr0.cpumask = cpumask_of(0);
155174

156-
setup_irq(IRQ_OST0, &pxa_ost0_irq);
175+
setup_irq(irq, &pxa_ost0_irq);
157176

158-
clocksource_mmio_init(OSCR, "oscr0", clock_tick_rate, 200, 32,
159-
clocksource_mmio_readl_up);
177+
clocksource_mmio_init(timer_base + OSCR, "oscr0", clock_tick_rate, 200,
178+
32, clocksource_mmio_readl_up);
160179
clockevents_config_and_register(&ckevt_pxa_osmr0, clock_tick_rate,
161-
MIN_OSCR_DELTA * 2, 0x7fffffff);
180+
MIN_OSCR_DELTA * 2, 0x7fffffff);
181+
}
182+
183+
static void __init pxa_timer_dt_init(struct device_node *np)
184+
{
185+
struct clk *clk;
186+
int irq;
187+
188+
/* timer registers are shared with watchdog timer */
189+
timer_base = of_iomap(np, 0);
190+
if (!timer_base)
191+
panic("%s: unable to map resource\n", np->name);
192+
193+
clk = of_clk_get(np, 0);
194+
if (IS_ERR(clk)) {
195+
pr_crit("%s: unable to get clk\n", np->name);
196+
return;
197+
}
198+
clk_prepare_enable(clk);
199+
200+
/* we are only interested in OS-timer0 irq */
201+
irq = irq_of_parse_and_map(np, 0);
202+
if (irq <= 0) {
203+
pr_crit("%s: unable to parse OS-timer0 irq\n", np->name);
204+
return;
205+
}
206+
207+
pxa_timer_common_init(irq, clk_get_rate(clk));
208+
}
209+
CLOCKSOURCE_OF_DECLARE(pxa_timer, "marvell,pxa-timer", pxa_timer_dt_init);
210+
211+
/*
212+
* Legacy timer init for non device-tree boards.
213+
*/
214+
void __init pxa_timer_nodt_init(int irq, void __iomem *base,
215+
unsigned long clock_tick_rate)
216+
{
217+
struct clk *clk;
218+
219+
timer_base = base;
220+
clk = clk_get(NULL, "OSTIMER0");
221+
if (clk && !IS_ERR(clk))
222+
clk_prepare_enable(clk);
223+
else
224+
pr_crit("%s: unable to get clk\n", __func__);
225+
226+
pxa_timer_common_init(irq, clock_tick_rate);
162227
}

0 commit comments

Comments
 (0)