1 From a1dcaba80910c0196b6e51111ba3890372067e0e Mon Sep 17 00:00:00 2001
2 From: Eric Anholt <eric@anholt.net>
3 Date: Thu, 2 May 2019 15:11:05 -0700
4 Subject: [PATCH] clk: bcm2835: Add support for setting leaf clock
7 As long as you wait for !BUSY, you can do glitch-free updates of clock
8 rate while the clock is running.
10 Signed-off-by: Eric Anholt <eric@anholt.net>
12 drivers/clk/bcm/clk-bcm2835.c | 22 +++++++++++++---------
13 1 file changed, 13 insertions(+), 9 deletions(-)
15 --- a/drivers/clk/bcm/clk-bcm2835.c
16 +++ b/drivers/clk/bcm/clk-bcm2835.c
17 @@ -1115,15 +1115,19 @@ static int bcm2835_clock_set_rate(struct
19 spin_lock(&cprman->regs_lock);
22 - * Setting up frac support
24 - * In principle it is recommended to stop/start the clock first,
25 - * but as we set CLK_SET_RATE_GATE during registration of the
26 - * clock this requirement should be take care of by the
28 + ctl = cprman_read(cprman, data->ctl_reg);
30 + /* If the clock is running, we have to pause clock generation while
31 + * updating the control and div regs. This is glitchless (no clock
32 + * signals generated faster than the rate) but each reg access is two
33 + * OSC cycles so the clock will slow down for a moment.
35 - ctl = cprman_read(cprman, data->ctl_reg) & ~CM_FRAC;
36 + if (ctl & CM_ENABLE) {
37 + cprman_write(cprman, data->ctl_reg, ctl & ~CM_ENABLE);
38 + bcm2835_clock_wait_busy(clock);
42 ctl |= (div & CM_DIV_FRAC_MASK) ? CM_FRAC : 0;
43 cprman_write(cprman, data->ctl_reg, ctl);
45 @@ -1499,7 +1503,7 @@ static struct clk_hw *bcm2835_register_c
46 init.ops = &bcm2835_vpu_clock_clk_ops;
48 init.ops = &bcm2835_clock_clk_ops;
49 - init.flags |= CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE;
50 + init.flags |= CLK_SET_PARENT_GATE;
52 /* If the clock wasn't actually enabled at boot, it's not