[RFC,02/11] clk: imx: add clk_hw based API imx_get_clk_hw_from_dt()
Commit Message
Clock providers are recommended to use the struct clk_hw based API, so
add an IMX provider helper to get clk_hw from device tree node name.
This is a preparation patch for the upcoming support to setup clocks
directly from the device tree.
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
drivers/clk/imx/clk.c | 21 +++++++++++++++++++++
drivers/clk/imx/clk.h | 3 +++
2 files changed, 24 insertions(+)
@@ -68,6 +68,27 @@ void imx_check_clk_hws(struct clk_hw *clks[], unsigned int count)
}
EXPORT_SYMBOL_GPL(imx_check_clk_hws);
+struct clk_hw *imx_get_clk_hw_from_dt(struct device_node *np,
+ const char *name)
+{
+ struct of_phandle_args clkspec;
+ struct clk *clk;
+
+ clkspec.np = of_find_node_by_name(np, name);
+ if (clkspec.np) {
+ clk = of_clk_get_from_provider(&clkspec);
+ if (!IS_ERR(clk)) {
+ pr_debug("%s: got %s clock\n", __func__, name);
+ of_node_put(clkspec.np);
+ return __clk_get_hw(clk);
+ }
+ }
+
+ pr_err("%s: failed to %s clock\n", __func__, name);
+ return ERR_PTR(-ENODEV);
+}
+EXPORT_SYMBOL_GPL(imx_get_clk_hw_from_dt);
+
static struct clk *imx_obtain_fixed_clock_from_dt(const char *name)
{
struct of_phandle_args phandle;
@@ -294,6 +294,9 @@ struct clk_hw *clk_hw_register_gate2(struct device *dev, const char *name,
u8 clk_gate_flags, spinlock_t *lock,
unsigned int *share_count);
+struct clk_hw *imx_get_clk_hw_from_dt(struct device_node *np,
+ const char *name);
+
struct clk * imx_obtain_fixed_clock(
const char *name, unsigned long rate);