Skip to content

Commit 755350b

Browse files
xdarklightdlezcano
authored andcommitted
clocksource/drivers/arm_global_timer: Simplify prescaler register access
Use GENMASK() to define the prescaler mask and make the whole driver use the mask (together with helpers such as FIELD_{GET,PREP,FIT}) instead of needing an additional shift and max value constant. Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20240225151336.2728533-4-martin.blumenstingl@googlemail.com
1 parent e651f2f commit 755350b

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

drivers/clocksource/arm_global_timer.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/init.h>
1111
#include <linux/interrupt.h>
12+
#include <linux/bitfield.h>
1213
#include <linux/clocksource.h>
1314
#include <linux/clockchips.h>
1415
#include <linux/cpu.h>
@@ -31,10 +32,7 @@
3132
#define GT_CONTROL_COMP_ENABLE BIT(1) /* banked */
3233
#define GT_CONTROL_IRQ_ENABLE BIT(2) /* banked */
3334
#define GT_CONTROL_AUTO_INC BIT(3) /* banked */
34-
#define GT_CONTROL_PRESCALER_SHIFT 8
35-
#define GT_CONTROL_PRESCALER_MAX 0xFF
36-
#define GT_CONTROL_PRESCALER_MASK (GT_CONTROL_PRESCALER_MAX << \
37-
GT_CONTROL_PRESCALER_SHIFT)
35+
#define GT_CONTROL_PRESCALER_MASK GENMASK(15, 8)
3836

3937
#define GT_INT_STATUS 0x0c
4038
#define GT_INT_STATUS_EVENT_FLAG BIT(0)
@@ -248,7 +246,7 @@ static void gt_write_presc(u32 psv)
248246

249247
reg = readl(gt_base + GT_CONTROL);
250248
reg &= ~GT_CONTROL_PRESCALER_MASK;
251-
reg |= psv << GT_CONTROL_PRESCALER_SHIFT;
249+
reg |= FIELD_PREP(GT_CONTROL_PRESCALER_MASK, psv);
252250
writel(reg, gt_base + GT_CONTROL);
253251
}
254252

@@ -257,8 +255,7 @@ static u32 gt_read_presc(void)
257255
u32 reg;
258256

259257
reg = readl(gt_base + GT_CONTROL);
260-
reg &= GT_CONTROL_PRESCALER_MASK;
261-
return reg >> GT_CONTROL_PRESCALER_SHIFT;
258+
return FIELD_GET(GT_CONTROL_PRESCALER_MASK, reg);
262259
}
263260

264261
static void __init gt_delay_timer_init(void)
@@ -273,9 +270,9 @@ static int __init gt_clocksource_init(void)
273270
writel(0, gt_base + GT_COUNTER0);
274271
writel(0, gt_base + GT_COUNTER1);
275272
/* set prescaler and enable timer on all the cores */
276-
writel(((CONFIG_ARM_GT_INITIAL_PRESCALER_VAL - 1) <<
277-
GT_CONTROL_PRESCALER_SHIFT)
278-
| GT_CONTROL_TIMER_ENABLE, gt_base + GT_CONTROL);
273+
writel(FIELD_PREP(GT_CONTROL_PRESCALER_MASK,
274+
CONFIG_ARM_GT_INITIAL_PRESCALER_VAL - 1) |
275+
GT_CONTROL_TIMER_ENABLE, gt_base + GT_CONTROL);
279276

280277
#ifdef CONFIG_CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK
281278
sched_clock_register(gt_sched_clock_read, 64, gt_target_rate);
@@ -301,7 +298,7 @@ static int gt_clk_rate_change_cb(struct notifier_block *nb,
301298
psv--;
302299

303300
/* prescaler within legal range? */
304-
if (psv > GT_CONTROL_PRESCALER_MAX)
301+
if (!FIELD_FIT(GT_CONTROL_PRESCALER_MASK, psv))
305302
return NOTIFY_BAD;
306303

307304
/*

0 commit comments

Comments
 (0)