diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-03 19:14:51 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-03 19:14:51 -0400 |
commit | 1b044f1cfc65a7d90b209dfabd57e16d98b58c5b (patch) | |
tree | ad657c911b563f9176b17578c0b88a1ea9916a02 /drivers/clocksource/timer-of.c | |
parent | e0f3e8f14da868047c524a0cf11e08b95fd1b008 (diff) | |
parent | 2287d8664fe7345ead891017eccd879fc605305e (diff) |
Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer updates from Thomas Gleixner:
"A rather large update for timers/timekeeping:
- compat syscall consolidation (Al Viro)
- Posix timer consolidation (Christoph Helwig / Thomas Gleixner)
- Cleanup of the device tree based initialization for clockevents and
clocksources (Daniel Lezcano)
- Consolidation of the FTTMR010 clocksource/event driver (Linus
Walleij)
- The usual set of small fixes and updates all over the place"
* 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (93 commits)
timers: Make the cpu base lock raw
clocksource/drivers/mips-gic-timer: Fix an error code in 'gic_clocksource_of_init()'
clocksource/drivers/fsl_ftm_timer: Unmap region obtained by of_iomap
clocksource/drivers/tcb_clksrc: Make IO endian agnostic
clocksource/drivers/sun4i: Switch to the timer-of common init
clocksource/drivers/timer-of: Fix invalid iomap check
Revert "ktime: Simplify ktime_compare implementation"
clocksource/drivers: Fix uninitialized variable use in timer_of_init
kselftests: timers: Add test for frequency step
kselftests: timers: Fix inconsistency-check to not ignore first timestamp
time: Add warning about imminent deprecation of CONFIG_GENERIC_TIME_VSYSCALL_OLD
time: Clean up CLOCK_MONOTONIC_RAW time handling
posix-cpu-timers: Make timespec to nsec conversion safe
itimer: Make timeval to nsec conversion range limited
timers: Fix parameter description of try_to_del_timer_sync()
ktime: Simplify ktime_compare implementation
clocksource/drivers/fttmr010: Factor out clock read code
clocksource/drivers/fttmr010: Implement delay timer
clocksource/drivers: Add timer-of common init routine
clocksource/drivers/tcb_clksrc: Save timer context on suspend/resume
...
Diffstat (limited to 'drivers/clocksource/timer-of.c')
-rw-r--r-- | drivers/clocksource/timer-of.c | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/drivers/clocksource/timer-of.c b/drivers/clocksource/timer-of.c new file mode 100644 index 000000000000..f6e7491c873c --- /dev/null +++ b/drivers/clocksource/timer-of.c | |||
@@ -0,0 +1,171 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017, Linaro Ltd. All rights reserved. | ||
3 | * | ||
4 | * Author: Daniel Lezcano <daniel.lezcano@linaro.org> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | #include <linux/clk.h> | ||
19 | #include <linux/interrupt.h> | ||
20 | #include <linux/of.h> | ||
21 | #include <linux/of_address.h> | ||
22 | #include <linux/of_irq.h> | ||
23 | #include <linux/slab.h> | ||
24 | |||
25 | #include "timer-of.h" | ||
26 | |||
27 | static __init void timer_irq_exit(struct of_timer_irq *of_irq) | ||
28 | { | ||
29 | struct timer_of *to = container_of(of_irq, struct timer_of, of_irq); | ||
30 | |||
31 | struct clock_event_device *clkevt = &to->clkevt; | ||
32 | |||
33 | of_irq->percpu ? free_percpu_irq(of_irq->irq, clkevt) : | ||
34 | free_irq(of_irq->irq, clkevt); | ||
35 | } | ||
36 | |||
37 | static __init int timer_irq_init(struct device_node *np, | ||
38 | struct of_timer_irq *of_irq) | ||
39 | { | ||
40 | int ret; | ||
41 | struct timer_of *to = container_of(of_irq, struct timer_of, of_irq); | ||
42 | struct clock_event_device *clkevt = &to->clkevt; | ||
43 | |||
44 | of_irq->irq = of_irq->name ? of_irq_get_byname(np, of_irq->name): | ||
45 | irq_of_parse_and_map(np, of_irq->index); | ||
46 | if (!of_irq->irq) { | ||
47 | pr_err("Failed to map interrupt for %s\n", np->full_name); | ||
48 | return -EINVAL; | ||
49 | } | ||
50 | |||
51 | ret = of_irq->percpu ? | ||
52 | request_percpu_irq(of_irq->irq, of_irq->handler, | ||
53 | np->full_name, clkevt) : | ||
54 | request_irq(of_irq->irq, of_irq->handler, | ||
55 | of_irq->flags ? of_irq->flags : IRQF_TIMER, | ||
56 | np->full_name, clkevt); | ||
57 | if (ret) { | ||
58 | pr_err("Failed to request irq %d for %s\n", of_irq->irq, | ||
59 | np->full_name); | ||
60 | return ret; | ||
61 | } | ||
62 | |||
63 | clkevt->irq = of_irq->irq; | ||
64 | |||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | static __init void timer_clk_exit(struct of_timer_clk *of_clk) | ||
69 | { | ||
70 | of_clk->rate = 0; | ||
71 | clk_disable_unprepare(of_clk->clk); | ||
72 | clk_put(of_clk->clk); | ||
73 | } | ||
74 | |||
75 | static __init int timer_clk_init(struct device_node *np, | ||
76 | struct of_timer_clk *of_clk) | ||
77 | { | ||
78 | int ret; | ||
79 | |||
80 | of_clk->clk = of_clk->name ? of_clk_get_by_name(np, of_clk->name) : | ||
81 | of_clk_get(np, of_clk->index); | ||
82 | if (IS_ERR(of_clk->clk)) { | ||
83 | pr_err("Failed to get clock for %s\n", np->full_name); | ||
84 | return PTR_ERR(of_clk->clk); | ||
85 | } | ||
86 | |||
87 | ret = clk_prepare_enable(of_clk->clk); | ||
88 | if (ret) { | ||
89 | pr_err("Failed for enable clock for %s\n", np->full_name); | ||
90 | goto out_clk_put; | ||
91 | } | ||
92 | |||
93 | of_clk->rate = clk_get_rate(of_clk->clk); | ||
94 | if (!of_clk->rate) { | ||
95 | ret = -EINVAL; | ||
96 | pr_err("Failed to get clock rate for %s\n", np->full_name); | ||
97 | goto out_clk_disable; | ||
98 | } | ||
99 | |||
100 | of_clk->period = DIV_ROUND_UP(of_clk->rate, HZ); | ||
101 | out: | ||
102 | return ret; | ||
103 | |||
104 | out_clk_disable: | ||
105 | clk_disable_unprepare(of_clk->clk); | ||
106 | out_clk_put: | ||
107 | clk_put(of_clk->clk); | ||
108 | |||
109 | goto out; | ||
110 | } | ||
111 | |||
112 | static __init void timer_base_exit(struct of_timer_base *of_base) | ||
113 | { | ||
114 | iounmap(of_base->base); | ||
115 | } | ||
116 | |||
117 | static __init int timer_base_init(struct device_node *np, | ||
118 | struct of_timer_base *of_base) | ||
119 | { | ||
120 | const char *name = of_base->name ? of_base->name : np->full_name; | ||
121 | |||
122 | of_base->base = of_io_request_and_map(np, of_base->index, name); | ||
123 | if (!of_base->base) { | ||
124 | pr_err("Failed to iomap (%s)\n", name); | ||
125 | return -ENXIO; | ||
126 | } | ||
127 | |||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | int __init timer_of_init(struct device_node *np, struct timer_of *to) | ||
132 | { | ||
133 | int ret = -EINVAL; | ||
134 | int flags = 0; | ||
135 | |||
136 | if (to->flags & TIMER_OF_BASE) { | ||
137 | ret = timer_base_init(np, &to->of_base); | ||
138 | if (ret) | ||
139 | goto out_fail; | ||
140 | flags |= TIMER_OF_BASE; | ||
141 | } | ||
142 | |||
143 | if (to->flags & TIMER_OF_CLOCK) { | ||
144 | ret = timer_clk_init(np, &to->of_clk); | ||
145 | if (ret) | ||
146 | goto out_fail; | ||
147 | flags |= TIMER_OF_CLOCK; | ||
148 | } | ||
149 | |||
150 | if (to->flags & TIMER_OF_IRQ) { | ||
151 | ret = timer_irq_init(np, &to->of_irq); | ||
152 | if (ret) | ||
153 | goto out_fail; | ||
154 | flags |= TIMER_OF_IRQ; | ||
155 | } | ||
156 | |||
157 | if (!to->clkevt.name) | ||
158 | to->clkevt.name = np->name; | ||
159 | return ret; | ||
160 | |||
161 | out_fail: | ||
162 | if (flags & TIMER_OF_IRQ) | ||
163 | timer_irq_exit(&to->of_irq); | ||
164 | |||
165 | if (flags & TIMER_OF_CLOCK) | ||
166 | timer_clk_exit(&to->of_clk); | ||
167 | |||
168 | if (flags & TIMER_OF_BASE) | ||
169 | timer_base_exit(&to->of_base); | ||
170 | return ret; | ||
171 | } | ||