Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

authored by

Martin Blumenstingl and committed by
Daniel Lezcano
755350bc e651f2fa

+8 -11
+8 -11
drivers/clocksource/arm_global_timer.c
··· 9 9 10 10 #include <linux/init.h> 11 11 #include <linux/interrupt.h> 12 + #include <linux/bitfield.h> 12 13 #include <linux/clocksource.h> 13 14 #include <linux/clockchips.h> 14 15 #include <linux/cpu.h> ··· 32 31 #define GT_CONTROL_COMP_ENABLE BIT(1) /* banked */ 33 32 #define GT_CONTROL_IRQ_ENABLE BIT(2) /* banked */ 34 33 #define GT_CONTROL_AUTO_INC BIT(3) /* banked */ 35 - #define GT_CONTROL_PRESCALER_SHIFT 8 36 - #define GT_CONTROL_PRESCALER_MAX 0xFF 37 - #define GT_CONTROL_PRESCALER_MASK (GT_CONTROL_PRESCALER_MAX << \ 38 - GT_CONTROL_PRESCALER_SHIFT) 34 + #define GT_CONTROL_PRESCALER_MASK GENMASK(15, 8) 39 35 40 36 #define GT_INT_STATUS 0x0c 41 37 #define GT_INT_STATUS_EVENT_FLAG BIT(0) ··· 246 248 247 249 reg = readl(gt_base + GT_CONTROL); 248 250 reg &= ~GT_CONTROL_PRESCALER_MASK; 249 - reg |= psv << GT_CONTROL_PRESCALER_SHIFT; 251 + reg |= FIELD_PREP(GT_CONTROL_PRESCALER_MASK, psv); 250 252 writel(reg, gt_base + GT_CONTROL); 251 253 } 252 254 ··· 255 257 u32 reg; 256 258 257 259 reg = readl(gt_base + GT_CONTROL); 258 - reg &= GT_CONTROL_PRESCALER_MASK; 259 - return reg >> GT_CONTROL_PRESCALER_SHIFT; 260 + return FIELD_GET(GT_CONTROL_PRESCALER_MASK, reg); 260 261 } 261 262 262 263 static void __init gt_delay_timer_init(void) ··· 270 273 writel(0, gt_base + GT_COUNTER0); 271 274 writel(0, gt_base + GT_COUNTER1); 272 275 /* set prescaler and enable timer on all the cores */ 273 - writel(((CONFIG_ARM_GT_INITIAL_PRESCALER_VAL - 1) << 274 - GT_CONTROL_PRESCALER_SHIFT) 275 - | GT_CONTROL_TIMER_ENABLE, gt_base + GT_CONTROL); 276 + writel(FIELD_PREP(GT_CONTROL_PRESCALER_MASK, 277 + CONFIG_ARM_GT_INITIAL_PRESCALER_VAL - 1) | 278 + GT_CONTROL_TIMER_ENABLE, gt_base + GT_CONTROL); 276 279 277 280 #ifdef CONFIG_CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK 278 281 sched_clock_register(gt_sched_clock_read, 64, gt_target_rate); ··· 298 301 psv--; 299 302 300 303 /* prescaler within legal range? */ 301 - if (psv > GT_CONTROL_PRESCALER_MAX) 304 + if (!FIELD_FIT(GT_CONTROL_PRESCALER_MASK, psv)) 302 305 return NOTIFY_BAD; 303 306 304 307 /*