Skip to content

Commit 464d2ff

Browse files
committed
Merge tag 'timers-v5.11-2' of https://git.linaro.org/people/daniel.lezcano/linux into timers/core
Pull clocksource/events updates from Daniel Lezcano: - Fix error handling if no clock is available on dw_apb_timer_of (Dinh Nguyen) - Fix overhead for erratum handling when the timer has no erratum and fix fault programing for the event stream on the arm arch timer (Keqian Zhu) - Fix potential deadlock when calling runtime PM on sh_cmt (Niklas Söderlund)
2 parents aa3b66f + 8ae954c commit 464d2ff

3 files changed

Lines changed: 71 additions & 31 deletions

File tree

‎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/sh_cmt.c‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ static int sh_cmt_enable(struct sh_cmt_channel *ch)
319319
{
320320
int k, ret;
321321

322-
pm_runtime_get_sync(&ch->cmt->pdev->dev);
323322
dev_pm_syscore_device(&ch->cmt->pdev->dev, true);
324323

325324
/* enable clock */
@@ -394,7 +393,6 @@ static void sh_cmt_disable(struct sh_cmt_channel *ch)
394393
clk_disable(ch->cmt->clk);
395394

396395
dev_pm_syscore_device(&ch->cmt->pdev->dev, false);
397-
pm_runtime_put(&ch->cmt->pdev->dev);
398396
}
399397

400398
/* private flags */
@@ -562,10 +560,16 @@ static int sh_cmt_start(struct sh_cmt_channel *ch, unsigned long flag)
562560
int ret = 0;
563561
unsigned long flags;
564562

563+
if (flag & FLAG_CLOCKSOURCE)
564+
pm_runtime_get_sync(&ch->cmt->pdev->dev);
565+
565566
raw_spin_lock_irqsave(&ch->lock, flags);
566567

567-
if (!(ch->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE)))
568+
if (!(ch->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE))) {
569+
if (flag & FLAG_CLOCKEVENT)
570+
pm_runtime_get_sync(&ch->cmt->pdev->dev);
568571
ret = sh_cmt_enable(ch);
572+
}
569573

570574
if (ret)
571575
goto out;
@@ -590,14 +594,20 @@ static void sh_cmt_stop(struct sh_cmt_channel *ch, unsigned long flag)
590594
f = ch->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE);
591595
ch->flags &= ~flag;
592596

593-
if (f && !(ch->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE)))
597+
if (f && !(ch->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE))) {
594598
sh_cmt_disable(ch);
599+
if (flag & FLAG_CLOCKEVENT)
600+
pm_runtime_put(&ch->cmt->pdev->dev);
601+
}
595602

596603
/* adjust the timeout to maximum if only clocksource left */
597604
if ((flag == FLAG_CLOCKEVENT) && (ch->flags & FLAG_CLOCKSOURCE))
598605
__sh_cmt_set_next(ch, ch->max_match_value);
599606

600607
raw_spin_unlock_irqrestore(&ch->lock, flags);
608+
609+
if (flag & FLAG_CLOCKSOURCE)
610+
pm_runtime_put(&ch->cmt->pdev->dev);
601611
}
602612

603613
static struct sh_cmt_channel *cs_to_sh_cmt(struct clocksource *cs)

0 commit comments

Comments
 (0)