With CCF the implementation of functions like clk_get_* and clk_set_defaults() changes. Introduce support for calling the CCF implementations when it is enabled. When disabled this dead code will be compiled out.
Additionally, adjust the Makefile so that we no longer build clk-uclass.c when CCF is enabled. This removes all the conflicting implementations of clk_enable() and friends as well as ensuring that we don't even try and probe any UCLASS_CLK drivers as they are not supported. Signed-off-by: Casey Connolly <[email protected]> --- drivers/clk/Makefile | 2 +- drivers/clk/clk-common.c | 61 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index ee06bffaef72..4bec2e4c61a8 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -3,9 +3,8 @@ # Copyright (c) 2015 Google, Inc # Wolfgang Denk, DENX Software Engineering, [email protected]. # -obj-$(CONFIG_$(PHASE_)CLK) += clk-uclass.o obj-$(CONFIG_$(PHASE_)CLK) += clk-common.o obj-$(CONFIG_$(PHASE_)CLK_GPIO) += clk-gpio.o obj-$(CONFIG_$(PHASE_)CLK_STUB) += clk-stub.o @@ -15,8 +14,9 @@ obj-y += ccf/ else # U-Boot basic fixed clocks, full CCF has a # different and incompatible implementation obj-y += basic/ +obj-$(CONFIG_$(PHASE_)CLK) += clk-uclass.o # U-Boot/IMX "micro" CCF port obj-$(CONFIG_$(PHASE_)CLK_CCF) += uccf/ endif diff --git a/drivers/clk/clk-common.c b/drivers/clk/clk-common.c index 7f30ad496da2..a24878d7302e 100644 --- a/drivers/clk/clk-common.c +++ b/drivers/clk/clk-common.c @@ -22,8 +22,10 @@ #include <linux/bug.h> #include <linux/clk-provider.h> #include <linux/err.h> +#include <linux/clk/clk-conf.h> +#include "ccf/clk.h" #include "clk-common.h" #if CONFIG_IS_ENABLED(OF_REAL) int clk_get_by_index(struct udevice *dev, int index, struct clk *clk) @@ -32,16 +34,23 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk) } int clk_get_by_index_nodev(ofnode node, int index, struct clk *clk) { - struct ofnode_phandle_args args; - int ret; + if (CONFIG_IS_ENABLED(CLK_CCF_FULL)) { + struct clk_hw *hw; - ret = ofnode_parse_phandle_with_args(node, "clocks", "#clock-cells", 0, - index, &args); + hw = of_clk_get_hw(node, index, NULL); + return clk_hw_create_clk_uboot(clk, hw); + } else { + struct ofnode_phandle_args args; + int ret; - return clk_get_by_index_tail(ret, node, &args, "clocks", - index, clk); + ret = ofnode_parse_phandle_with_args(node, "clocks", "#clock-cells", 0, + index, &args); + + return clk_get_by_index_tail(ret, node, &args, "clocks", + index, clk); + } } int clk_get_bulk(struct udevice *dev, struct clk_bulk *bulk) { @@ -77,9 +86,18 @@ bulk_get_err: } int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk) { - return clk_get_by_name_nodev(dev_ofnode(dev), name, clk); + if (CONFIG_IS_ENABLED(CLK_CCF_FULL)) { + struct clk_hw *hw; + + hw = of_clk_get_hw(dev_ofnode(dev), 0, name); + if (IS_ERR(hw)) + return -ENOENT; + return clk_hw_create_clk_uboot(clk, hw); + } else { + return clk_get_by_name_nodev(dev_ofnode(dev), name, clk); + } } #endif /* OF_REAL */ int clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk) @@ -139,15 +157,19 @@ int clk_set_defaults(struct udevice *dev, enum clk_defaults_stage stage) return 0; debug("%s(%s)\n", __func__, dev_read_name(dev)); - ret = clk_set_default_parents(dev, stage); - if (ret) - return ret; + if (CONFIG_IS_ENABLED(CLK_CCF_FULL)) { + return of_clk_set_defaults(dev_ofnode(dev), false); + } else { + ret = clk_set_default_parents(dev, stage); + if (ret) + return ret; - ret = clk_set_default_rates(dev, stage); - if (ret < 0) - return ret; + ret = clk_set_default_rates(dev, stage); + if (ret < 0) + return ret; + } return 0; } @@ -217,4 +239,17 @@ int clk_disable_bulk(struct clk_bulk *bulk) } return 0; } + +#if CONFIG_IS_ENABLED(CLK_CCF_FULL) +long clk_get_parent_rate(struct clk *clk) +{ + struct clk *pclk; + + if (!clk) + return -EINVAL; + + pclk = clk_get_parent(clk); + return clk_get_rate(pclk); +} +#endif -- 2.55.0
