Skip to content

Commit 91e8d0c

Browse files
committed
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 small set of patches from the timer departement: - Some more y2038 work - Yet another new clocksource driver - The usual set of small fixes, cleanups and enhancements" * 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: clocksource/drivers/tegra: Remove unused suspend/resume code clockevents/driversi/mps2: add MPS2 Timer driver dt-bindings: document the MPS2 timer bindings clocksource/drivers/mtk_timer: Add __init attribute clockevents/drivers/dw_apb_timer: Implement ->set_state_oneshot_stopped() time: Introduce do_sys_settimeofday64() security: Introduce security_settime64() clocksource: Add missing include of of.h.
2 parents 2fe2edf + 9999c5f commit 91e8d0c

File tree

14 files changed

+354
-28
lines changed

14 files changed

+354
-28
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ARM MPS2 timer
2+
3+
The MPS2 platform has simple general-purpose 32 bits timers.
4+
5+
Required properties:
6+
- compatible : Should be "arm,mps2-timer"
7+
- reg : Address and length of the register set
8+
- interrupts : Reference to the timer interrupt
9+
10+
Required clocking property, have to be one of:
11+
- clocks : The input clock of the timer
12+
- clock-frequency : The rate in HZ in input of the ARM MPS2 timer
13+
14+
Examples:
15+
16+
timer1: mps2-timer@40000000 {
17+
compatible = "arm,mps2-timer";
18+
reg = <0x40000000 0x1000>;
19+
interrupts = <8>;
20+
clocks = <&sysclk>;
21+
};
22+
23+
timer2: mps2-timer@40001000 {
24+
compatible = "arm,mps2-timer";
25+
reg = <0x40001000 0x1000>;
26+
interrupts = <9>;
27+
clock-frequency = <25000000>;
28+
};

drivers/clocksource/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ config CLKSRC_STM32
186186
depends on OF && ARM && (ARCH_STM32 || COMPILE_TEST)
187187
select CLKSRC_MMIO
188188

189+
config CLKSRC_MPS2
190+
bool "Clocksource for MPS2 SoCs" if COMPILE_TEST
191+
depends on GENERIC_SCHED_CLOCK
192+
select CLKSRC_MMIO
193+
select CLKSRC_OF
194+
189195
config ARM_ARCH_TIMER
190196
bool
191197
select CLKSRC_OF if OF

drivers/clocksource/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ obj-$(CONFIG_CLKSRC_EFM32) += time-efm32.o
3939
obj-$(CONFIG_CLKSRC_STM32) += timer-stm32.o
4040
obj-$(CONFIG_CLKSRC_EXYNOS_MCT) += exynos_mct.o
4141
obj-$(CONFIG_CLKSRC_LPC32XX) += time-lpc32xx.o
42+
obj-$(CONFIG_CLKSRC_MPS2) += mps2-timer.o
4243
obj-$(CONFIG_CLKSRC_SAMSUNG_PWM) += samsung_pwm_timer.o
4344
obj-$(CONFIG_FSL_FTM_TIMER) += fsl_ftm_timer.o
4445
obj-$(CONFIG_VF_PIT_TIMER) += vf_pit_timer.o

drivers/clocksource/dw_apb_timer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ dw_apb_clockevent_init(int cpu, const char *name, unsigned rating,
264264
dw_ced->ced.set_state_shutdown = apbt_shutdown;
265265
dw_ced->ced.set_state_periodic = apbt_set_periodic;
266266
dw_ced->ced.set_state_oneshot = apbt_set_oneshot;
267+
dw_ced->ced.set_state_oneshot_stopped = apbt_shutdown;
267268
dw_ced->ced.tick_resume = apbt_resume;
268269
dw_ced->ced.set_next_event = apbt_next_event;
269270
dw_ced->ced.irq = dw_ced->timer.irq;

drivers/clocksource/mps2-timer.c

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
/*
2+
* Copyright (C) 2015 ARM Limited
3+
*
4+
* Author: Vladimir Murzin <[email protected]>
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+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13+
14+
#include <linux/clk.h>
15+
#include <linux/clockchips.h>
16+
#include <linux/clocksource.h>
17+
#include <linux/err.h>
18+
#include <linux/interrupt.h>
19+
#include <linux/io.h>
20+
#include <linux/irq.h>
21+
#include <linux/of_address.h>
22+
#include <linux/of.h>
23+
#include <linux/of_irq.h>
24+
#include <linux/sched_clock.h>
25+
#include <linux/slab.h>
26+
27+
#define TIMER_CTRL 0x0
28+
#define TIMER_CTRL_ENABLE BIT(0)
29+
#define TIMER_CTRL_IE BIT(3)
30+
31+
#define TIMER_VALUE 0x4
32+
#define TIMER_RELOAD 0x8
33+
#define TIMER_INT 0xc
34+
35+
struct clockevent_mps2 {
36+
void __iomem *reg;
37+
u32 clock_count_per_tick;
38+
struct clock_event_device clkevt;
39+
};
40+
41+
static void __iomem *sched_clock_base;
42+
43+
static u64 notrace mps2_sched_read(void)
44+
{
45+
return ~readl_relaxed(sched_clock_base + TIMER_VALUE);
46+
}
47+
48+
static inline struct clockevent_mps2 *to_mps2_clkevt(struct clock_event_device *c)
49+
{
50+
return container_of(c, struct clockevent_mps2, clkevt);
51+
}
52+
53+
static void clockevent_mps2_writel(u32 val, struct clock_event_device *c, u32 offset)
54+
{
55+
writel_relaxed(val, to_mps2_clkevt(c)->reg + offset);
56+
}
57+
58+
static int mps2_timer_shutdown(struct clock_event_device *ce)
59+
{
60+
clockevent_mps2_writel(0, ce, TIMER_RELOAD);
61+
clockevent_mps2_writel(0, ce, TIMER_CTRL);
62+
63+
return 0;
64+
}
65+
66+
static int mps2_timer_set_next_event(unsigned long next, struct clock_event_device *ce)
67+
{
68+
clockevent_mps2_writel(next, ce, TIMER_VALUE);
69+
clockevent_mps2_writel(TIMER_CTRL_IE | TIMER_CTRL_ENABLE, ce, TIMER_CTRL);
70+
71+
return 0;
72+
}
73+
74+
static int mps2_timer_set_periodic(struct clock_event_device *ce)
75+
{
76+
u32 clock_count_per_tick = to_mps2_clkevt(ce)->clock_count_per_tick;
77+
78+
clockevent_mps2_writel(clock_count_per_tick, ce, TIMER_RELOAD);
79+
clockevent_mps2_writel(clock_count_per_tick, ce, TIMER_VALUE);
80+
clockevent_mps2_writel(TIMER_CTRL_IE | TIMER_CTRL_ENABLE, ce, TIMER_CTRL);
81+
82+
return 0;
83+
}
84+
85+
static irqreturn_t mps2_timer_interrupt(int irq, void *dev_id)
86+
{
87+
struct clockevent_mps2 *ce = dev_id;
88+
u32 status = readl_relaxed(ce->reg + TIMER_INT);
89+
90+
if (!status) {
91+
pr_warn("spurious interrupt\n");
92+
return IRQ_NONE;
93+
}
94+
95+
writel_relaxed(1, ce->reg + TIMER_INT);
96+
97+
ce->clkevt.event_handler(&ce->clkevt);
98+
99+
return IRQ_HANDLED;
100+
}
101+
102+
static int __init mps2_clockevent_init(struct device_node *np)
103+
{
104+
void __iomem *base;
105+
struct clk *clk = NULL;
106+
struct clockevent_mps2 *ce;
107+
u32 rate;
108+
int irq, ret;
109+
const char *name = "mps2-clkevt";
110+
111+
ret = of_property_read_u32(np, "clock-frequency", &rate);
112+
if (ret) {
113+
clk = of_clk_get(np, 0);
114+
if (IS_ERR(clk)) {
115+
ret = PTR_ERR(clk);
116+
pr_err("failed to get clock for clockevent: %d\n", ret);
117+
goto out;
118+
}
119+
120+
ret = clk_prepare_enable(clk);
121+
if (ret) {
122+
pr_err("failed to enable clock for clockevent: %d\n", ret);
123+
goto out_clk_put;
124+
}
125+
126+
rate = clk_get_rate(clk);
127+
}
128+
129+
base = of_iomap(np, 0);
130+
if (!base) {
131+
ret = -EADDRNOTAVAIL;
132+
pr_err("failed to map register for clockevent: %d\n", ret);
133+
goto out_clk_disable;
134+
}
135+
136+
irq = irq_of_parse_and_map(np, 0);
137+
if (!irq) {
138+
ret = -ENOENT;
139+
pr_err("failed to get irq for clockevent: %d\n", ret);
140+
goto out_iounmap;
141+
}
142+
143+
ce = kzalloc(sizeof(*ce), GFP_KERNEL);
144+
if (!ce) {
145+
ret = -ENOMEM;
146+
goto out_iounmap;
147+
}
148+
149+
ce->reg = base;
150+
ce->clock_count_per_tick = DIV_ROUND_CLOSEST(rate, HZ);
151+
ce->clkevt.irq = irq;
152+
ce->clkevt.name = name;
153+
ce->clkevt.rating = 200;
154+
ce->clkevt.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
155+
ce->clkevt.cpumask = cpu_possible_mask;
156+
ce->clkevt.set_state_shutdown = mps2_timer_shutdown,
157+
ce->clkevt.set_state_periodic = mps2_timer_set_periodic,
158+
ce->clkevt.set_state_oneshot = mps2_timer_shutdown,
159+
ce->clkevt.set_next_event = mps2_timer_set_next_event;
160+
161+
/* Ensure timer is disabled */
162+
writel_relaxed(0, base + TIMER_CTRL);
163+
164+
ret = request_irq(irq, mps2_timer_interrupt, IRQF_TIMER, name, ce);
165+
if (ret) {
166+
pr_err("failed to request irq for clockevent: %d\n", ret);
167+
goto out_kfree;
168+
}
169+
170+
clockevents_config_and_register(&ce->clkevt, rate, 0xf, 0xffffffff);
171+
172+
return 0;
173+
174+
out_kfree:
175+
kfree(ce);
176+
out_iounmap:
177+
iounmap(base);
178+
out_clk_disable:
179+
/* clk_{disable, unprepare, put}() can handle NULL as a parameter */
180+
clk_disable_unprepare(clk);
181+
out_clk_put:
182+
clk_put(clk);
183+
out:
184+
return ret;
185+
}
186+
187+
static int __init mps2_clocksource_init(struct device_node *np)
188+
{
189+
void __iomem *base;
190+
struct clk *clk = NULL;
191+
u32 rate;
192+
int ret;
193+
const char *name = "mps2-clksrc";
194+
195+
ret = of_property_read_u32(np, "clock-frequency", &rate);
196+
if (ret) {
197+
clk = of_clk_get(np, 0);
198+
if (IS_ERR(clk)) {
199+
ret = PTR_ERR(clk);
200+
pr_err("failed to get clock for clocksource: %d\n", ret);
201+
goto out;
202+
}
203+
204+
ret = clk_prepare_enable(clk);
205+
if (ret) {
206+
pr_err("failed to enable clock for clocksource: %d\n", ret);
207+
goto out_clk_put;
208+
}
209+
210+
rate = clk_get_rate(clk);
211+
}
212+
213+
base = of_iomap(np, 0);
214+
if (!base) {
215+
ret = -EADDRNOTAVAIL;
216+
pr_err("failed to map register for clocksource: %d\n", ret);
217+
goto out_clk_disable;
218+
}
219+
220+
/* Ensure timer is disabled */
221+
writel_relaxed(0, base + TIMER_CTRL);
222+
223+
/* ... and set it up as free-running clocksource */
224+
writel_relaxed(0xffffffff, base + TIMER_VALUE);
225+
writel_relaxed(0xffffffff, base + TIMER_RELOAD);
226+
227+
writel_relaxed(TIMER_CTRL_ENABLE, base + TIMER_CTRL);
228+
229+
ret = clocksource_mmio_init(base + TIMER_VALUE, name,
230+
rate, 200, 32,
231+
clocksource_mmio_readl_down);
232+
if (ret) {
233+
pr_err("failed to init clocksource: %d\n", ret);
234+
goto out_iounmap;
235+
}
236+
237+
sched_clock_base = base;
238+
sched_clock_register(mps2_sched_read, 32, rate);
239+
240+
return 0;
241+
242+
out_iounmap:
243+
iounmap(base);
244+
out_clk_disable:
245+
/* clk_{disable, unprepare, put}() can handle NULL as a parameter */
246+
clk_disable_unprepare(clk);
247+
out_clk_put:
248+
clk_put(clk);
249+
out:
250+
return ret;
251+
}
252+
253+
static void __init mps2_timer_init(struct device_node *np)
254+
{
255+
static int has_clocksource, has_clockevent;
256+
int ret;
257+
258+
if (!has_clocksource) {
259+
ret = mps2_clocksource_init(np);
260+
if (!ret) {
261+
has_clocksource = 1;
262+
return;
263+
}
264+
}
265+
266+
if (!has_clockevent) {
267+
ret = mps2_clockevent_init(np);
268+
if (!ret) {
269+
has_clockevent = 1;
270+
return;
271+
}
272+
}
273+
}
274+
275+
CLOCKSOURCE_OF_DECLARE(mps2_timer, "arm,mps2-timer", mps2_timer_init);

drivers/clocksource/mtk_timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static irqreturn_t mtk_timer_interrupt(int irq, void *dev_id)
152152
}
153153

154154
static void
155-
mtk_timer_setup(struct mtk_clock_event_device *evt, u8 timer, u8 option)
155+
__init mtk_timer_setup(struct mtk_clock_event_device *evt, u8 timer, u8 option)
156156
{
157157
writel(TIMER_CTRL_CLEAR | TIMER_CTRL_DISABLE,
158158
evt->gpt_base + TIMER_CTRL_REG(timer));

drivers/clocksource/tegra20_timer.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,3 @@ static void __init tegra20_init_rtc(struct device_node *np)
258258
register_persistent_clock(NULL, tegra_read_persistent_clock64);
259259
}
260260
CLOCKSOURCE_OF_DECLARE(tegra20_rtc, "nvidia,tegra20-rtc", tegra20_init_rtc);
261-
262-
#ifdef CONFIG_PM
263-
static u32 usec_config;
264-
265-
void tegra_timer_suspend(void)
266-
{
267-
usec_config = timer_readl(TIMERUS_USEC_CFG);
268-
}
269-
270-
void tegra_timer_resume(void)
271-
{
272-
timer_writel(usec_config, TIMERUS_USEC_CFG);
273-
}
274-
#endif

include/linux/clocksource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/cache.h>
1616
#include <linux/timer.h>
1717
#include <linux/init.h>
18+
#include <linux/of.h>
1819
#include <asm/div64.h>
1920
#include <asm/io.h>
2021

include/linux/lsm_hooks.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,8 @@
11901190
* Return 0 if permission is granted.
11911191
* @settime:
11921192
* Check permission to change the system time.
1193-
* struct timespec and timezone are defined in include/linux/time.h
1193+
* struct timespec64 is defined in include/linux/time64.h and timezone
1194+
* is defined in include/linux/time.h
11941195
* @ts contains new time
11951196
* @tz contains new timezone
11961197
* Return 0 if permission is granted.
@@ -1327,7 +1328,7 @@ union security_list_options {
13271328
int (*quotactl)(int cmds, int type, int id, struct super_block *sb);
13281329
int (*quota_on)(struct dentry *dentry);
13291330
int (*syslog)(int type);
1330-
int (*settime)(const struct timespec *ts, const struct timezone *tz);
1331+
int (*settime)(const struct timespec64 *ts, const struct timezone *tz);
13311332
int (*vm_enough_memory)(struct mm_struct *mm, long pages);
13321333

13331334
int (*bprm_set_creds)(struct linux_binprm *bprm);

0 commit comments

Comments
 (0)