Skip to content

Commit 3b87265

Browse files
XBurstdlezcano
authored andcommitted
clocksource/drivers/ingenic: Use bitfield macro helpers
Use "FIELD_GET()" and "FIELD_PREP()" to simplify the code. [dlezcano] : Changed title Signed-off-by: 周琰杰 (Zhou Yanjie) <[email protected]> Reviewed-by: Paul Cercueil <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent be83c3b commit 3b87265

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/clocksource/ingenic-sysost.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (c) 2020 周琰杰 (Zhou Yanjie) <[email protected]>
55
*/
66

7+
#include <linux/bitfield.h>
78
#include <linux/bitops.h>
89
#include <linux/clk.h>
910
#include <linux/clk-provider.h>
@@ -34,8 +35,6 @@
3435
/* bits within the OSTCCR register */
3536
#define OSTCCR_PRESCALE1_MASK 0x3
3637
#define OSTCCR_PRESCALE2_MASK 0xc
37-
#define OSTCCR_PRESCALE1_LSB 0
38-
#define OSTCCR_PRESCALE2_LSB 2
3938

4039
/* bits within the OSTCR register */
4140
#define OSTCR_OST1CLR BIT(0)
@@ -98,7 +97,7 @@ static unsigned long ingenic_ost_percpu_timer_recalc_rate(struct clk_hw *hw,
9897

9998
prescale = readl(ost_clk->ost->base + info->ostccr_reg);
10099

101-
prescale = (prescale & OSTCCR_PRESCALE1_MASK) >> OSTCCR_PRESCALE1_LSB;
100+
prescale = FIELD_GET(OSTCCR_PRESCALE1_MASK, prescale);
102101

103102
return parent_rate >> (prescale * 2);
104103
}
@@ -112,7 +111,7 @@ static unsigned long ingenic_ost_global_timer_recalc_rate(struct clk_hw *hw,
112111

113112
prescale = readl(ost_clk->ost->base + info->ostccr_reg);
114113

115-
prescale = (prescale & OSTCCR_PRESCALE2_MASK) >> OSTCCR_PRESCALE2_LSB;
114+
prescale = FIELD_GET(OSTCCR_PRESCALE2_MASK, prescale);
116115

117116
return parent_rate >> (prescale * 2);
118117
}
@@ -151,7 +150,8 @@ static int ingenic_ost_percpu_timer_set_rate(struct clk_hw *hw, unsigned long re
151150
int val;
152151

153152
val = readl(ost_clk->ost->base + info->ostccr_reg);
154-
val = (val & ~OSTCCR_PRESCALE1_MASK) | (prescale << OSTCCR_PRESCALE1_LSB);
153+
val &= ~OSTCCR_PRESCALE1_MASK;
154+
val |= FIELD_PREP(OSTCCR_PRESCALE1_MASK, prescale);
155155
writel(val, ost_clk->ost->base + info->ostccr_reg);
156156

157157
return 0;
@@ -166,7 +166,8 @@ static int ingenic_ost_global_timer_set_rate(struct clk_hw *hw, unsigned long re
166166
int val;
167167

168168
val = readl(ost_clk->ost->base + info->ostccr_reg);
169-
val = (val & ~OSTCCR_PRESCALE2_MASK) | (prescale << OSTCCR_PRESCALE2_LSB);
169+
val &= ~OSTCCR_PRESCALE2_MASK;
170+
val |= FIELD_PREP(OSTCCR_PRESCALE2_MASK, prescale);
170171
writel(val, ost_clk->ost->base + info->ostccr_reg);
171172

172173
return 0;

0 commit comments

Comments
 (0)