Skip to content

Commit 5b2667a

Browse files
committed
clk: at91: clk-main: update key before writing AT91_CKGR_MOR
SAMA5D2 datasheet specifies on chapter 33.22.8 (PMC Clock Generator Main Oscillator Register) that writing any value other than 0x37 on KEY field aborts the write operation. Use the key when selecting main clock parent. Fixes: 27cb1c2 ("clk: at91: rework main clk implementation") Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com> Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/1598338751-20607-3-git-send-email-claudiu.beznea@microchip.com Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 464982b commit 5b2667a

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

drivers/clk/at91/clk-main.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,17 @@ static int clk_sam9x5_main_set_parent(struct clk_hw *hw, u8 index)
437437
return -EINVAL;
438438

439439
regmap_read(regmap, AT91_CKGR_MOR, &tmp);
440-
tmp &= ~MOR_KEY_MASK;
441440

442441
if (index && !(tmp & AT91_PMC_MOSCSEL))
443-
regmap_write(regmap, AT91_CKGR_MOR, tmp | AT91_PMC_MOSCSEL);
442+
tmp = AT91_PMC_MOSCSEL;
444443
else if (!index && (tmp & AT91_PMC_MOSCSEL))
445-
regmap_write(regmap, AT91_CKGR_MOR, tmp & ~AT91_PMC_MOSCSEL);
444+
tmp = 0;
445+
else
446+
return 0;
447+
448+
regmap_update_bits(regmap, AT91_CKGR_MOR,
449+
AT91_PMC_MOSCSEL | MOR_KEY_MASK,
450+
tmp | AT91_PMC_KEY);
446451

447452
while (!clk_sam9x5_main_ready(regmap))
448453
cpu_relax();

0 commit comments

Comments
 (0)