]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/clocksource/clksrc-dbx500-prcmu.c
4f34093bdb4efcf942b5a2312bc0ddd19b3a69e4
[mirror_ubuntu-zesty-kernel.git] / drivers / clocksource / clksrc-dbx500-prcmu.c
1 /*
2 * Copyright (C) ST-Ericsson SA 2011
3 *
4 * License Terms: GNU General Public License v2
5 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson
6 * Author: Sundar Iyer for ST-Ericsson
7 * sched_clock implementation is based on:
8 * plat-nomadik/timer.c Linus Walleij <linus.walleij@stericsson.com>
9 *
10 * DBx500-PRCMU Timer
11 * The PRCMU has 5 timers which are available in a always-on
12 * power domain. We use the Timer 4 for our always-on clock
13 * source on DB8500 and Timer 3 on DB5500.
14 */
15 #include <linux/clockchips.h>
16 #include <linux/clksrc-dbx500-prcmu.h>
17
18 #include <asm/sched_clock.h>
19
20 #include <mach/setup.h>
21
22 #define RATE_32K 32768
23
24 #define TIMER_MODE_CONTINOUS 0x1
25 #define TIMER_DOWNCOUNT_VAL 0xffffffff
26
27 #define PRCMU_TIMER_REF 0
28 #define PRCMU_TIMER_DOWNCOUNT 0x4
29 #define PRCMU_TIMER_MODE 0x8
30
31 #define SCHED_CLOCK_MIN_WRAP 131072 /* 2^32 / 32768 */
32
33 static void __iomem *clksrc_dbx500_timer_base;
34
35 static cycle_t clksrc_dbx500_prcmu_read(struct clocksource *cs)
36 {
37 u32 count, count2;
38
39 do {
40 count = readl(clksrc_dbx500_timer_base +
41 PRCMU_TIMER_DOWNCOUNT);
42 count2 = readl(clksrc_dbx500_timer_base +
43 PRCMU_TIMER_DOWNCOUNT);
44 } while (count2 != count);
45
46 /* Negate because the timer is a decrementing counter */
47 return ~count;
48 }
49
50 static struct clocksource clocksource_dbx500_prcmu = {
51 .name = "dbx500-prcmu-timer",
52 .rating = 300,
53 .read = clksrc_dbx500_prcmu_read,
54 .mask = CLOCKSOURCE_MASK(32),
55 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
56 };
57
58 #ifdef CONFIG_CLKSRC_DBX500_PRCMU_SCHED_CLOCK
59
60 static u32 notrace dbx500_prcmu_sched_clock_read(void)
61 {
62 if (unlikely(!clksrc_dbx500_timer_base))
63 return 0;
64
65 return clksrc_dbx500_prcmu_read(&clocksource_dbx500_prcmu);
66 }
67
68 #endif
69
70 void __init clksrc_dbx500_prcmu_init(void __iomem *base)
71 {
72 clksrc_dbx500_timer_base = base;
73
74 /*
75 * The A9 sub system expects the timer to be configured as
76 * a continous looping timer.
77 * The PRCMU should configure it but if it for some reason
78 * don't we do it here.
79 */
80 if (readl(clksrc_dbx500_timer_base + PRCMU_TIMER_MODE) !=
81 TIMER_MODE_CONTINOUS) {
82 writel(TIMER_MODE_CONTINOUS,
83 clksrc_dbx500_timer_base + PRCMU_TIMER_MODE);
84 writel(TIMER_DOWNCOUNT_VAL,
85 clksrc_dbx500_timer_base + PRCMU_TIMER_REF);
86 }
87 #ifdef CONFIG_CLKSRC_DBX500_PRCMU_SCHED_CLOCK
88 setup_sched_clock(dbx500_prcmu_sched_clock_read,
89 32, RATE_32K);
90 #endif
91 clocksource_register_hz(&clocksource_dbx500_prcmu, RATE_32K);
92 }