diff options
author | Dario Binacchi <dariobin@libero.it> | 2020-06-03 15:36:25 +0200 |
---|---|---|
committer | Lukasz Majewski <lukma@denx.de> | 2020-08-24 11:03:26 +0200 |
commit | 12d152620d9de9ea966e1136b7f48f641c981bac (patch) | |
tree | ae79e25d72749366f6f39d49c47594168f37722b /drivers/clk | |
parent | e3b5d74c778a8782f763412679ca4c3cb2d496c3 (diff) |
clk: ccf: mux: change the get_rate helper
The previous version of the get_rate helper does not work if the mux
clock parent is changed after the probe. This error has not been
detected because this condition has not been tested. The error occurs
because the set_parent helper does not change the parent of the clock
device but only the clock selection register. Since changing the parent
of a probed device can be tricky, the new version of the get_rate helper
provides the rate of the selected clock and not that of the parent.
Signed-off-by: Dario Binacchi <dariobin@libero.it>
Diffstat (limited to 'drivers/clk')
-rw-r--r-- | drivers/clk/clk-mux.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c index e10baaf83b..ec8017b7d2 100644 --- a/drivers/clk/clk-mux.c +++ b/drivers/clk/clk-mux.c @@ -149,8 +149,32 @@ static int clk_mux_set_parent(struct clk *clk, struct clk *parent) return 0; } +static ulong clk_mux_get_rate(struct clk *clk) +{ + struct clk_mux *mux = to_clk_mux(clk_dev_binded(clk) ? + dev_get_clk_ptr(clk->dev) : clk); + struct udevice *parent; + struct clk *pclk; + int err, index; + + index = clk_mux_get_parent(clk); + if (index >= mux->num_parents) + return -EFAULT; + + err = uclass_get_device_by_name(UCLASS_CLK, mux->parent_names[index], + &parent); + if (err) + return err; + + pclk = dev_get_clk_ptr(parent); + if (!pclk) + return -ENODEV; + + return clk_get_rate(pclk); +} + const struct clk_ops clk_mux_ops = { - .get_rate = clk_generic_get_rate, + .get_rate = clk_mux_get_rate, .set_parent = clk_mux_set_parent, }; |