1 // SPDX-License-Identifier: GPL-2.0+
5 * Peng Fan <peng.fan@nxp.com>
8 #include <linux/clk-provider.h>
9 #include <linux/errno.h>
10 #include <linux/export.h>
12 #include <linux/slab.h>
16 #define CCM_DIV_SHIFT 0
17 #define CCM_DIV_WIDTH 8
18 #define CCM_MUX_SHIFT 8
19 #define CCM_MUX_MASK 3
20 #define CCM_OFF_SHIFT 24
22 #define AUTHEN_OFFSET 0x30
24 #define TZ_NS_MASK BIT(9)
26 struct clk_hw *imx93_clk_composite_flags(const char *name, const char * const *parent_names,
27 int num_parents, void __iomem *reg,
30 struct clk_hw *hw = ERR_PTR(-ENOMEM), *mux_hw;
31 struct clk_hw *div_hw, *gate_hw;
32 struct clk_divider *div = NULL;
33 struct clk_gate *gate = NULL;
34 struct clk_mux *mux = NULL;
37 mux = kzalloc(sizeof(*mux), GFP_KERNEL);
43 mux->shift = CCM_MUX_SHIFT;
44 mux->mask = CCM_MUX_MASK;
45 mux->lock = &imx_ccm_lock;
47 div = kzalloc(sizeof(*div), GFP_KERNEL);
53 div->shift = CCM_DIV_SHIFT;
54 div->width = CCM_DIV_WIDTH;
55 div->lock = &imx_ccm_lock;
56 div->flags = CLK_DIVIDER_ROUND_CLOSEST;
58 if (!(readl(reg + AUTHEN_OFFSET) & TZ_NS_MASK))
62 hw = clk_hw_register_composite(NULL, name, parent_names, num_parents,
63 mux_hw, &clk_mux_ro_ops, div_hw,
64 &clk_divider_ro_ops, NULL, NULL, flags);
66 gate = kzalloc(sizeof(*gate), GFP_KERNEL);
72 gate->bit_idx = CCM_OFF_SHIFT;
73 gate->lock = &imx_ccm_lock;
74 gate->flags = CLK_GATE_SET_TO_DISABLE;
76 hw = clk_hw_register_composite(NULL, name, parent_names, num_parents,
77 mux_hw, &clk_mux_ops, div_hw,
78 &clk_divider_ops, gate_hw,
79 &clk_gate_ops, flags | CLK_SET_RATE_NO_REPARENT);
93 EXPORT_SYMBOL_GPL(imx93_clk_composite_flags);