Skip to content

Commit 533369b

Browse files
committed
Merge tag 'timers-core-2020-12-14' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timers and timekeeping updates from Thomas Gleixner: "Core: - Robustness improvements for the NOHZ tick management - Fixes and consolidation of the NTP/RTC synchronization code - Small fixes and improvements in various places - A set of function documentation udpates and fixes Drivers: - Cleanups and improvements in various clocksoure/event drivers - Removal of the EZChip NPS clocksource driver as the platfrom support was removed from ARC - The usual set of new device tree binding and json conversions - The RTC driver which have been acked by the RTC maintainer: * fix a long standing bug in the MC146818 library code which can cause reading garbage during the RTC internal update. * changes related to the NTP/RTC consolidation work" * tag 'timers-core-2020-12-14' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (46 commits) ntp: Fix prototype in the !CONFIG_GENERIC_CMOS_UPDATE case tick/sched: Make jiffies update quick check more robust ntp: Consolidate the RTC update implementation ntp: Make the RTC sync offset less obscure ntp, rtc: Move rtc_set_ntp_time() to ntp code ntp: Make the RTC synchronization more reliable rtc: core: Make the sync offset default more realistic rtc: cmos: Make rtc_cmos sync offset correct rtc: mc146818: Reduce spinlock section in mc146818_set_time() rtc: mc146818: Prevent reading garbage clocksource/drivers/sh_cmt: Fix potential deadlock when calling runtime PM clocksource/drivers/arm_arch_timer: Correct fault programming of CNTKCTL_EL1.EVNTI clocksource/drivers/arm_arch_timer: Use stable count reader in erratum sne clocksource/drivers/dw_apb_timer_of: Add error handling if no clock available clocksource/drivers/riscv: Make RISCV_TIMER depends on RISCV_SBI clocksource/drivers/ingenic: Fix section mismatch clocksource/drivers/cadence_ttc: Fix memory leak in ttc_setup_clockevent() dt-bindings: timer: renesas: tmu: Convert to json-schema dt-bindings: timer: renesas: tmu: Document r8a774e1 bindings clocksource/drivers/orion: Add missing clk_disable_unprepare() on error path ...
2 parents 76d4acf + 3cabca8 commit 533369b

36 files changed

Lines changed: 666 additions & 811 deletions

Documentation/devicetree/bindings/timer/renesas,tmu.txt

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/timer/renesas,tmu.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Renesas R-Mobile/R-Car Timer Unit (TMU)
8+
9+
maintainers:
10+
- Geert Uytterhoeven <geert+renesas@glider.be>
11+
- Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
12+
13+
description:
14+
The TMU is a 32-bit timer/counter with configurable clock inputs and
15+
programmable compare match.
16+
17+
Channels share hardware resources but their counter and compare match value
18+
are independent. The TMU hardware supports up to three channels.
19+
20+
properties:
21+
compatible:
22+
items:
23+
- enum:
24+
- renesas,tmu-r8a7740 # R-Mobile A1
25+
- renesas,tmu-r8a774a1 # RZ/G2M
26+
- renesas,tmu-r8a774b1 # RZ/G2N
27+
- renesas,tmu-r8a774c0 # RZ/G2E
28+
- renesas,tmu-r8a774e1 # RZ/G2H
29+
- renesas,tmu-r8a7778 # R-Car M1A
30+
- renesas,tmu-r8a7779 # R-Car H1
31+
- renesas,tmu-r8a77970 # R-Car V3M
32+
- renesas,tmu-r8a77980 # R-Car V3H
33+
- const: renesas,tmu
34+
35+
reg:
36+
maxItems: 1
37+
38+
interrupts:
39+
minItems: 2
40+
maxItems: 3
41+
42+
clocks:
43+
maxItems: 1
44+
45+
clock-names:
46+
const: fck
47+
48+
power-domains:
49+
maxItems: 1
50+
51+
resets:
52+
maxItems: 1
53+
54+
'#renesas,channels':
55+
description:
56+
Number of channels implemented by the timer.
57+
$ref: /schemas/types.yaml#/definitions/uint32
58+
enum: [ 2, 3 ]
59+
default: 3
60+
61+
required:
62+
- compatible
63+
- reg
64+
- interrupts
65+
- clocks
66+
- clock-names
67+
- power-domains
68+
69+
if:
70+
not:
71+
properties:
72+
compatible:
73+
contains:
74+
enum:
75+
- renesas,tmu-r8a7740
76+
- renesas,tmu-r8a7778
77+
- renesas,tmu-r8a7779
78+
then:
79+
required:
80+
- resets
81+
82+
additionalProperties: false
83+
84+
examples:
85+
- |
86+
#include <dt-bindings/clock/r8a7779-clock.h>
87+
#include <dt-bindings/interrupt-controller/arm-gic.h>
88+
#include <dt-bindings/power/r8a7779-sysc.h>
89+
tmu0: timer@ffd80000 {
90+
compatible = "renesas,tmu-r8a7779", "renesas,tmu";
91+
reg = <0xffd80000 0x30>;
92+
interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>,
93+
<GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>,
94+
<GIC_SPI 34 IRQ_TYPE_LEVEL_HIGH>;
95+
clocks = <&mstp0_clks R8A7779_CLK_TMU0>;
96+
clock-names = "fck";
97+
power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
98+
#renesas,channels = <3>;
99+
};

drivers/clocksource/Kconfig

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,6 @@ config CLKSRC_TI_32K
275275
This option enables support for Texas Instruments 32.768 Hz clocksource
276276
available on many OMAP-like platforms.
277277

278-
config CLKSRC_NPS
279-
bool "NPS400 clocksource driver" if COMPILE_TEST
280-
depends on !PHYS_ADDR_T_64BIT
281-
select CLKSRC_MMIO
282-
select TIMER_OF if OF
283-
help
284-
NPS400 clocksource support.
285-
It has a 64-bit counter with update rate up to 1000MHz.
286-
This counter is accessed via couple of 32-bit memory-mapped registers.
287-
288278
config CLKSRC_STM32
289279
bool "Clocksource for STM32 SoCs" if !ARCH_STM32
290280
depends on OF && ARM && (ARCH_STM32 || COMPILE_TEST)
@@ -654,7 +644,7 @@ config ATCPIT100_TIMER
654644

655645
config RISCV_TIMER
656646
bool "Timer for the RISC-V platform" if COMPILE_TEST
657-
depends on GENERIC_SCHED_CLOCK && RISCV
647+
depends on GENERIC_SCHED_CLOCK && RISCV && RISCV_SBI
658648
select TIMER_PROBE
659649
select TIMER_OF
660650
help

drivers/clocksource/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ obj-$(CONFIG_CLKSRC_QCOM) += timer-qcom.o
5656
obj-$(CONFIG_MTK_TIMER) += timer-mediatek.o
5757
obj-$(CONFIG_CLKSRC_PISTACHIO) += timer-pistachio.o
5858
obj-$(CONFIG_CLKSRC_TI_32K) += timer-ti-32k.o
59-
obj-$(CONFIG_CLKSRC_NPS) += timer-nps.o
6059
obj-$(CONFIG_OXNAS_RPS_TIMER) += timer-oxnas-rps.o
6160
obj-$(CONFIG_OWL_TIMER) += timer-owl.o
6261
obj-$(CONFIG_MILBEAUT_TIMER) += timer-milbeaut.o

drivers/clocksource/arm_arch_timer.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,10 @@ static void erratum_set_next_event_tval_generic(const int access, unsigned long
396396
ctrl &= ~ARCH_TIMER_CTRL_IT_MASK;
397397

398398
if (access == ARCH_TIMER_PHYS_ACCESS) {
399-
cval = evt + arch_counter_get_cntpct();
399+
cval = evt + arch_counter_get_cntpct_stable();
400400
write_sysreg(cval, cntp_cval_el0);
401401
} else {
402-
cval = evt + arch_counter_get_cntvct();
402+
cval = evt + arch_counter_get_cntvct_stable();
403403
write_sysreg(cval, cntv_cval_el0);
404404
}
405405

@@ -822,15 +822,24 @@ static void arch_timer_evtstrm_enable(int divider)
822822

823823
static void arch_timer_configure_evtstream(void)
824824
{
825-
int evt_stream_div, pos;
825+
int evt_stream_div, lsb;
826+
827+
/*
828+
* As the event stream can at most be generated at half the frequency
829+
* of the counter, use half the frequency when computing the divider.
830+
*/
831+
evt_stream_div = arch_timer_rate / ARCH_TIMER_EVT_STREAM_FREQ / 2;
832+
833+
/*
834+
* Find the closest power of two to the divisor. If the adjacent bit
835+
* of lsb (last set bit, starts from 0) is set, then we use (lsb + 1).
836+
*/
837+
lsb = fls(evt_stream_div) - 1;
838+
if (lsb > 0 && (evt_stream_div & BIT(lsb - 1)))
839+
lsb++;
826840

827-
/* Find the closest power of two to the divisor */
828-
evt_stream_div = arch_timer_rate / ARCH_TIMER_EVT_STREAM_FREQ;
829-
pos = fls(evt_stream_div);
830-
if (pos > 1 && !(evt_stream_div & (1 << (pos - 2))))
831-
pos--;
832841
/* enable event stream */
833-
arch_timer_evtstrm_enable(min(pos, 15));
842+
arch_timer_evtstrm_enable(max(0, min(lsb, 15)));
834843
}
835844

836845
static void arch_counter_set_user_access(void)

drivers/clocksource/dw_apb_timer_of.c

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
#include <linux/reset.h>
1515
#include <linux/sched_clock.h>
1616

17-
static void __init timer_get_base_and_rate(struct device_node *np,
17+
static int __init timer_get_base_and_rate(struct device_node *np,
1818
void __iomem **base, u32 *rate)
1919
{
2020
struct clk *timer_clk;
2121
struct clk *pclk;
2222
struct reset_control *rstc;
23+
int ret;
2324

2425
*base = of_iomap(np, 0);
2526

@@ -46,55 +47,67 @@ static void __init timer_get_base_and_rate(struct device_node *np,
4647
pr_warn("pclk for %pOFn is present, but could not be activated\n",
4748
np);
4849

50+
if (!of_property_read_u32(np, "clock-freq", rate) &&
51+
!of_property_read_u32(np, "clock-frequency", rate))
52+
return 0;
53+
4954
timer_clk = of_clk_get_by_name(np, "timer");
5055
if (IS_ERR(timer_clk))
51-
goto try_clock_freq;
56+
return PTR_ERR(timer_clk);
5257

53-
if (!clk_prepare_enable(timer_clk)) {
54-
*rate = clk_get_rate(timer_clk);
55-
return;
56-
}
58+
ret = clk_prepare_enable(timer_clk);
59+
if (ret)
60+
return ret;
61+
62+
*rate = clk_get_rate(timer_clk);
63+
if (!(*rate))
64+
return -EINVAL;
5765

58-
try_clock_freq:
59-
if (of_property_read_u32(np, "clock-freq", rate) &&
60-
of_property_read_u32(np, "clock-frequency", rate))
61-
panic("No clock nor clock-frequency property for %pOFn", np);
66+
return 0;
6267
}
6368

64-
static void __init add_clockevent(struct device_node *event_timer)
69+
static int __init add_clockevent(struct device_node *event_timer)
6570
{
6671
void __iomem *iobase;
6772
struct dw_apb_clock_event_device *ced;
6873
u32 irq, rate;
74+
int ret = 0;
6975

7076
irq = irq_of_parse_and_map(event_timer, 0);
7177
if (irq == 0)
7278
panic("No IRQ for clock event timer");
7379

74-
timer_get_base_and_rate(event_timer, &iobase, &rate);
80+
ret = timer_get_base_and_rate(event_timer, &iobase, &rate);
81+
if (ret)
82+
return ret;
7583

7684
ced = dw_apb_clockevent_init(-1, event_timer->name, 300, iobase, irq,
7785
rate);
7886
if (!ced)
79-
panic("Unable to initialise clockevent device");
87+
return -EINVAL;
8088

8189
dw_apb_clockevent_register(ced);
90+
91+
return 0;
8292
}
8393

8494
static void __iomem *sched_io_base;
8595
static u32 sched_rate;
8696

87-
static void __init add_clocksource(struct device_node *source_timer)
97+
static int __init add_clocksource(struct device_node *source_timer)
8898
{
8999
void __iomem *iobase;
90100
struct dw_apb_clocksource *cs;
91101
u32 rate;
102+
int ret;
92103

93-
timer_get_base_and_rate(source_timer, &iobase, &rate);
104+
ret = timer_get_base_and_rate(source_timer, &iobase, &rate);
105+
if (ret)
106+
return ret;
94107

95108
cs = dw_apb_clocksource_init(300, source_timer->name, iobase, rate);
96109
if (!cs)
97-
panic("Unable to initialise clocksource device");
110+
return -EINVAL;
98111

99112
dw_apb_clocksource_start(cs);
100113
dw_apb_clocksource_register(cs);
@@ -106,6 +119,8 @@ static void __init add_clocksource(struct device_node *source_timer)
106119
*/
107120
sched_io_base = iobase + 0x04;
108121
sched_rate = rate;
122+
123+
return 0;
109124
}
110125

111126
static u64 notrace read_sched_clock(void)
@@ -146,10 +161,14 @@ static struct delay_timer dw_apb_delay_timer = {
146161
static int num_called;
147162
static int __init dw_apb_timer_init(struct device_node *timer)
148163
{
164+
int ret = 0;
165+
149166
switch (num_called) {
150167
case 1:
151168
pr_debug("%s: found clocksource timer\n", __func__);
152-
add_clocksource(timer);
169+
ret = add_clocksource(timer);
170+
if (ret)
171+
return ret;
153172
init_sched_clock();
154173
#ifdef CONFIG_ARM
155174
dw_apb_delay_timer.freq = sched_rate;
@@ -158,7 +177,9 @@ static int __init dw_apb_timer_init(struct device_node *timer)
158177
break;
159178
default:
160179
pr_debug("%s: found clockevent timer\n", __func__);
161-
add_clockevent(timer);
180+
ret = add_clockevent(timer);
181+
if (ret)
182+
return ret;
162183
break;
163184
}
164185

drivers/clocksource/ingenic-timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static irqreturn_t ingenic_tcu_cevt_cb(int irq, void *dev_id)
127127
return IRQ_HANDLED;
128128
}
129129

130-
static struct clk * __init ingenic_tcu_get_clock(struct device_node *np, int id)
130+
static struct clk *ingenic_tcu_get_clock(struct device_node *np, int id)
131131
{
132132
struct of_phandle_args args;
133133

0 commit comments

Comments
 (0)