picoxcell: support for Picochip picoxcell devices
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / arm / mach-picoxcell / time.c
blob90a554ff449945fd9738d5f7db9985f3703a7984
1 /*
2 * Copyright (c) 2011 Picochip Ltd., Jamie Iles
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * All enquiries to support@picochip.com
9 */
10 #include <linux/dw_apb_timer.h>
11 #include <linux/of.h>
12 #include <linux/of_address.h>
13 #include <linux/of_irq.h>
14 #include <linux/sched.h>
16 #include <asm/mach/time.h>
17 #include <asm/sched_clock.h>
19 #include "common.h"
21 static void timer_get_base_and_rate(struct device_node *np,
22 void __iomem **base, u32 *rate)
24 *base = of_iomap(np, 0);
26 if (!*base)
27 panic("Unable to map regs for %s", np->name);
29 if (of_property_read_u32(np, "clock-freq", rate))
30 panic("No clock-freq property for %s", np->name);
33 static void picoxcell_add_clockevent(struct device_node *event_timer)
35 void __iomem *iobase;
36 struct dw_apb_clock_event_device *ced;
37 u32 irq, rate;
39 irq = irq_of_parse_and_map(event_timer, 0);
40 if (irq == NO_IRQ)
41 panic("No IRQ for clock event timer");
43 timer_get_base_and_rate(event_timer, &iobase, &rate);
45 ced = dw_apb_clockevent_init(0, event_timer->name, 300, iobase, irq,
46 rate);
47 if (!ced)
48 panic("Unable to initialise clockevent device");
50 dw_apb_clockevent_register(ced);
53 static void picoxcell_add_clocksource(struct device_node *source_timer)
55 void __iomem *iobase;
56 struct dw_apb_clocksource *cs;
57 u32 rate;
59 timer_get_base_and_rate(source_timer, &iobase, &rate);
61 cs = dw_apb_clocksource_init(300, source_timer->name, iobase, rate);
62 if (!cs)
63 panic("Unable to initialise clocksource device");
65 dw_apb_clocksource_start(cs);
66 dw_apb_clocksource_register(cs);
69 static DEFINE_CLOCK_DATA(cd);
70 static void __iomem *sched_io_base;
72 unsigned long long notrace sched_clock(void)
74 cycle_t cyc = sched_io_base ? __raw_readl(sched_io_base) : 0;
76 return cyc_to_sched_clock(&cd, cyc, (u32)~0);
79 static void notrace picoxcell_update_sched_clock(void)
81 cycle_t cyc = sched_io_base ? __raw_readl(sched_io_base) : 0;
83 update_sched_clock(&cd, cyc, (u32)~0);
86 static const struct of_device_id picoxcell_rtc_ids[] __initconst = {
87 { .compatible = "picochip,pc3x2-rtc" },
88 { /* Sentinel */ },
91 static void picoxcell_init_sched_clock(void)
93 struct device_node *sched_timer;
94 u32 rate;
96 sched_timer = of_find_matching_node(NULL, picoxcell_rtc_ids);
97 if (!sched_timer)
98 panic("No RTC for sched clock to use");
100 timer_get_base_and_rate(sched_timer, &sched_io_base, &rate);
101 of_node_put(sched_timer);
103 init_sched_clock(&cd, picoxcell_update_sched_clock, 32, rate);
106 static const struct of_device_id picoxcell_timer_ids[] __initconst = {
107 { .compatible = "picochip,pc3x2-timer" },
111 static void __init picoxcell_timer_init(void)
113 struct device_node *event_timer, *source_timer;
115 event_timer = of_find_matching_node(NULL, picoxcell_timer_ids);
116 if (!event_timer)
117 panic("No timer for clockevent");
118 picoxcell_add_clockevent(event_timer);
120 source_timer = of_find_matching_node(event_timer, picoxcell_timer_ids);
121 if (!source_timer)
122 panic("No timer for clocksource");
123 picoxcell_add_clocksource(source_timer);
125 of_node_put(source_timer);
127 picoxcell_init_sched_clock();
130 struct sys_timer picoxcell_timer = {
131 .init = picoxcell_timer_init,