clk: meson: add clk-input helper function
authorJerome Brunet <jbrunet@baylibre.com>
Tue, 4 Dec 2018 16:58:18 +0000 (17:58 +0100)
committerNeil Armstrong <narmstrong@baylibre.com>
Wed, 5 Dec 2018 10:24:40 +0000 (11:24 +0100)
Add the clock input helper function. Several amlogic clock controllers
will now be registering bypass clock input. Instead of copying this
code in every of them, let's make an helper function for it

Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
[narmstrong: fixed up to apply on Makefile and clkc.h]
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
Link: https://lkml.kernel.org/r/20181204165819.21541-2-jbrunet@baylibre.com
drivers/clk/meson/Makefile
drivers/clk/meson/clk-input.c [new file with mode: 0644]
drivers/clk/meson/clkc.h

index 0234767f6cfcc0e330cb7d9c639c300b4c229bc9..a849aa809825a0244228b4e72171cda475649291 100644 (file)
@@ -3,6 +3,7 @@
 #
 
 obj-$(CONFIG_COMMON_CLK_AMLOGIC) += clk-pll.o clk-mpll.o clk-phase.o vid-pll-div.o
+obj-$(CONFIG_COMMON_CLK_AMLOGIC) += clk-input.o
 obj-$(CONFIG_COMMON_CLK_AMLOGIC_AUDIO) += clk-triphase.o sclk-div.o
 obj-$(CONFIG_COMMON_CLK_MESON_AO) += meson-aoclk.o
 obj-$(CONFIG_COMMON_CLK_MESON8B) += meson8b.o
diff --git a/drivers/clk/meson/clk-input.c b/drivers/clk/meson/clk-input.c
new file mode 100644 (file)
index 0000000..06b3e3b
--- /dev/null
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/*
+ * Copyright (c) 2018 BayLibre, SAS.
+ * Author: Jerome Brunet <jbrunet@baylibre.com>
+ */
+
+#include <linux/clk.h>
+#include <linux/clk-provider.h>
+#include <linux/device.h>
+#include "clkc.h"
+
+static const struct clk_ops meson_clk_no_ops = {};
+
+struct clk_hw *meson_clk_hw_register_input(struct device *dev,
+                                          const char *of_name,
+                                          const char *clk_name,
+                                          unsigned long flags)
+{
+       struct clk *parent_clk = devm_clk_get(dev, of_name);
+       struct clk_init_data init;
+       const char *parent_name;
+       struct clk_hw *hw;
+       int ret;
+
+       if (IS_ERR(parent_clk))
+               return (struct clk_hw *)parent_clk;
+
+       hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL);
+       if (!hw)
+               return ERR_PTR(-ENOMEM);
+
+       parent_name = __clk_get_name(parent_clk);
+       init.name = clk_name;
+       init.ops = &meson_clk_no_ops;
+       init.flags = flags;
+       init.parent_names = &parent_name;
+       init.num_parents = 1;
+       hw->init = &init;
+
+       ret = devm_clk_hw_register(dev, hw);
+
+       return ret ? ERR_PTR(ret) : hw;
+}
+EXPORT_SYMBOL_GPL(meson_clk_hw_register_input);
index 91666055c75af2053ba23e29e03422d19fe0773f..6183b22c4bf237ebb0ffa6dd0067dc7b19788d4b 100644 (file)
@@ -119,4 +119,9 @@ extern const struct clk_ops meson_clk_mpll_ops;
 extern const struct clk_ops meson_clk_phase_ops;
 extern const struct clk_ops meson_vid_pll_div_ro_ops;
 
+struct clk_hw *meson_clk_hw_register_input(struct device *dev,
+                                          const char *of_name,
+                                          const char *clk_name,
+                                          unsigned long flags);
+
 #endif /* __CLKC_H */