Skip to content

Commit a132837

Browse files
passgatbebarino
authored andcommitted
clk: stm32f4: use FIELD helpers to access the PLLCFGR fields
Use GENMASK() along with FIELD_GET() and FIELD_PREP() helpers to access the PLLCFGR fields instead of manually masking and shifting. Signed-off-by: Dario Binacchi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 223d32e commit a132837

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

drivers/clk/clk-stm32f4.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Inspired by clk-asm9260.c .
66
*/
77

8+
#include <linux/bitfield.h>
89
#include <linux/clk-provider.h>
910
#include <linux/err.h>
1011
#include <linux/io.h>
@@ -39,6 +40,8 @@
3940
#define STM32F4_RCC_DCKCFGR 0x8c
4041
#define STM32F7_RCC_DCKCFGR2 0x90
4142

43+
#define STM32F4_RCC_PLLCFGR_N_MASK GENMASK(14, 6)
44+
4245
#define NONE -1
4346
#define NO_IDX NONE
4447
#define NO_MUX NONE
@@ -632,9 +635,11 @@ static unsigned long stm32f4_pll_recalc(struct clk_hw *hw,
632635
{
633636
struct clk_gate *gate = to_clk_gate(hw);
634637
struct stm32f4_pll *pll = to_stm32f4_pll(gate);
638+
unsigned long val;
635639
unsigned long n;
636640

637-
n = (readl(base + pll->offset) >> 6) & 0x1ff;
641+
val = readl(base + pll->offset);
642+
n = FIELD_GET(STM32F4_RCC_PLLCFGR_N_MASK, val);
638643

639644
return parent_rate * n;
640645
}
@@ -673,9 +678,10 @@ static int stm32f4_pll_set_rate(struct clk_hw *hw, unsigned long rate,
673678

674679
n = rate / parent_rate;
675680

676-
val = readl(base + pll->offset) & ~(0x1ff << 6);
681+
val = readl(base + pll->offset) & ~STM32F4_RCC_PLLCFGR_N_MASK;
682+
val |= FIELD_PREP(STM32F4_RCC_PLLCFGR_N_MASK, n);
677683

678-
writel(val | ((n & 0x1ff) << 6), base + pll->offset);
684+
writel(val, base + pll->offset);
679685

680686
if (pll_state)
681687
stm32f4_pll_enable(hw);

0 commit comments

Comments
 (0)