xref: /kernel/linux/linux-6.6/drivers/clk/imx/clk.h (revision 62306a36)
162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __MACH_IMX_CLK_H
362306a36Sopenharmony_ci#define __MACH_IMX_CLK_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/bits.h>
662306a36Sopenharmony_ci#include <linux/spinlock.h>
762306a36Sopenharmony_ci#include <linux/clk-provider.h>
862306a36Sopenharmony_ci
962306a36Sopenharmony_ciextern spinlock_t imx_ccm_lock;
1062306a36Sopenharmony_ciextern bool mcore_booted;
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_civoid imx_check_clocks(struct clk *clks[], unsigned int count);
1362306a36Sopenharmony_civoid imx_check_clk_hws(struct clk_hw *clks[], unsigned int count);
1462306a36Sopenharmony_ci#ifndef MODULE
1562306a36Sopenharmony_civoid imx_register_uart_clocks(void);
1662306a36Sopenharmony_ci#else
1762306a36Sopenharmony_cistatic inline void imx_register_uart_clocks(void)
1862306a36Sopenharmony_ci{
1962306a36Sopenharmony_ci}
2062306a36Sopenharmony_ci#endif
2162306a36Sopenharmony_civoid imx_mmdc_mask_handshake(void __iomem *ccm_base, unsigned int chn);
2262306a36Sopenharmony_civoid imx_unregister_hw_clocks(struct clk_hw *hws[], unsigned int count);
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ciextern void imx_cscmr1_fixup(u32 *val);
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_cienum imx_pllv1_type {
2762306a36Sopenharmony_ci	IMX_PLLV1_IMX1,
2862306a36Sopenharmony_ci	IMX_PLLV1_IMX21,
2962306a36Sopenharmony_ci	IMX_PLLV1_IMX25,
3062306a36Sopenharmony_ci	IMX_PLLV1_IMX27,
3162306a36Sopenharmony_ci	IMX_PLLV1_IMX31,
3262306a36Sopenharmony_ci	IMX_PLLV1_IMX35,
3362306a36Sopenharmony_ci};
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_cienum imx_sscg_pll_type {
3662306a36Sopenharmony_ci	SCCG_PLL1,
3762306a36Sopenharmony_ci	SCCG_PLL2,
3862306a36Sopenharmony_ci};
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_cienum imx_pll14xx_type {
4162306a36Sopenharmony_ci	PLL_1416X,
4262306a36Sopenharmony_ci	PLL_1443X,
4362306a36Sopenharmony_ci};
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_cienum imx_pllv4_type {
4662306a36Sopenharmony_ci	IMX_PLLV4_IMX7ULP,
4762306a36Sopenharmony_ci	IMX_PLLV4_IMX8ULP,
4862306a36Sopenharmony_ci	IMX_PLLV4_IMX8ULP_1GHZ,
4962306a36Sopenharmony_ci};
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_cienum imx_pfdv2_type {
5262306a36Sopenharmony_ci	IMX_PFDV2_IMX7ULP,
5362306a36Sopenharmony_ci	IMX_PFDV2_IMX8ULP,
5462306a36Sopenharmony_ci};
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci/* NOTE: Rate table should be kept sorted in descending order. */
5762306a36Sopenharmony_cistruct imx_pll14xx_rate_table {
5862306a36Sopenharmony_ci	unsigned int rate;
5962306a36Sopenharmony_ci	unsigned int pdiv;
6062306a36Sopenharmony_ci	unsigned int mdiv;
6162306a36Sopenharmony_ci	unsigned int sdiv;
6262306a36Sopenharmony_ci	unsigned int kdiv;
6362306a36Sopenharmony_ci};
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cistruct imx_pll14xx_clk {
6662306a36Sopenharmony_ci	enum imx_pll14xx_type type;
6762306a36Sopenharmony_ci	const struct imx_pll14xx_rate_table *rate_table;
6862306a36Sopenharmony_ci	int rate_count;
6962306a36Sopenharmony_ci	int flags;
7062306a36Sopenharmony_ci};
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ciextern struct imx_pll14xx_clk imx_1416x_pll;
7362306a36Sopenharmony_ciextern struct imx_pll14xx_clk imx_1443x_pll;
7462306a36Sopenharmony_ciextern struct imx_pll14xx_clk imx_1443x_dram_pll;
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci#define CLK_FRACN_GPPLL_INTEGER	BIT(0)
7762306a36Sopenharmony_ci#define CLK_FRACN_GPPLL_FRACN	BIT(1)
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci/* NOTE: Rate table should be kept sorted in descending order. */
8062306a36Sopenharmony_cistruct imx_fracn_gppll_rate_table {
8162306a36Sopenharmony_ci	unsigned int rate;
8262306a36Sopenharmony_ci	unsigned int mfi;
8362306a36Sopenharmony_ci	unsigned int mfn;
8462306a36Sopenharmony_ci	unsigned int mfd;
8562306a36Sopenharmony_ci	unsigned int rdiv;
8662306a36Sopenharmony_ci	unsigned int odiv;
8762306a36Sopenharmony_ci};
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_cistruct imx_fracn_gppll_clk {
9062306a36Sopenharmony_ci	const struct imx_fracn_gppll_rate_table *rate_table;
9162306a36Sopenharmony_ci	int rate_count;
9262306a36Sopenharmony_ci	int flags;
9362306a36Sopenharmony_ci};
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_cistruct clk_hw *imx_clk_fracn_gppll(const char *name, const char *parent_name, void __iomem *base,
9662306a36Sopenharmony_ci				   const struct imx_fracn_gppll_clk *pll_clk);
9762306a36Sopenharmony_cistruct clk_hw *imx_clk_fracn_gppll_integer(const char *name, const char *parent_name,
9862306a36Sopenharmony_ci					   void __iomem *base,
9962306a36Sopenharmony_ci					   const struct imx_fracn_gppll_clk *pll_clk);
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ciextern struct imx_fracn_gppll_clk imx_fracn_gppll;
10262306a36Sopenharmony_ciextern struct imx_fracn_gppll_clk imx_fracn_gppll_integer;
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#define imx_clk_cpu(name, parent_name, div, mux, pll, step) \
10562306a36Sopenharmony_ci	to_clk(imx_clk_hw_cpu(name, parent_name, div, mux, pll, step))
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci#define clk_register_gate2(dev, name, parent_name, flags, reg, bit_idx, \
10862306a36Sopenharmony_ci				cgr_val, cgr_mask, clk_gate_flags, lock, share_count) \
10962306a36Sopenharmony_ci	to_clk(clk_hw_register_gate2(dev, name, parent_name, flags, reg, bit_idx, \
11062306a36Sopenharmony_ci				cgr_val, cgr_mask, clk_gate_flags, lock, share_count))
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci#define imx_clk_pllv3(type, name, parent_name, base, div_mask) \
11362306a36Sopenharmony_ci	to_clk(imx_clk_hw_pllv3(type, name, parent_name, base, div_mask))
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci#define imx_clk_pfd(name, parent_name, reg, idx) \
11662306a36Sopenharmony_ci	to_clk(imx_clk_hw_pfd(name, parent_name, reg, idx))
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci#define imx_clk_gate_exclusive(name, parent, reg, shift, exclusive_mask) \
11962306a36Sopenharmony_ci	to_clk(imx_clk_hw_gate_exclusive(name, parent, reg, shift, exclusive_mask))
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci#define imx_clk_fixed(name, rate) \
12262306a36Sopenharmony_ci	to_clk(imx_clk_hw_fixed(name, rate))
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci#define imx_clk_fixed_factor(name, parent, mult, div) \
12562306a36Sopenharmony_ci	to_clk(imx_clk_hw_fixed_factor(name, parent, mult, div))
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci#define imx_clk_divider(name, parent, reg, shift, width) \
12862306a36Sopenharmony_ci	to_clk(imx_clk_hw_divider(name, parent, reg, shift, width))
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci#define imx_clk_divider_flags(name, parent, reg, shift, width, flags) \
13162306a36Sopenharmony_ci	to_clk(imx_clk_hw_divider_flags(name, parent, reg, shift, width, flags))
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci#define imx_clk_gate(name, parent, reg, shift) \
13462306a36Sopenharmony_ci	to_clk(imx_clk_hw_gate(name, parent, reg, shift))
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci#define imx_clk_gate_dis(name, parent, reg, shift) \
13762306a36Sopenharmony_ci	to_clk(imx_clk_hw_gate_dis(name, parent, reg, shift))
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci#define imx_clk_gate2(name, parent, reg, shift) \
14062306a36Sopenharmony_ci	to_clk(imx_clk_hw_gate2(name, parent, reg, shift))
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci#define imx_clk_gate2_cgr(name, parent, reg, shift, cgr_val) \
14362306a36Sopenharmony_ci	to_clk(__imx_clk_hw_gate2(name, parent, reg, shift, cgr_val, 0, NULL))
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci#define imx_clk_gate2_flags(name, parent, reg, shift, flags) \
14662306a36Sopenharmony_ci	to_clk(imx_clk_hw_gate2_flags(name, parent, reg, shift, flags))
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci#define imx_clk_mux(name, reg, shift, width, parents, num_parents) \
14962306a36Sopenharmony_ci	to_clk(imx_clk_hw_mux(name, reg, shift, width, parents, num_parents))
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci#define imx_clk_mux_flags(name, reg, shift, width, parents, num_parents, flags) \
15262306a36Sopenharmony_ci	to_clk(imx_clk_hw_mux_flags(name, reg, shift, width, parents, num_parents, flags))
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci#define imx_clk_mux2_flags(name, reg, shift, width, parents, num_parents, flags) \
15562306a36Sopenharmony_ci	to_clk(imx_clk_hw_mux2_flags(name, reg, shift, width, parents, num_parents, flags))
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci#define imx_clk_pllv1(type, name, parent, base) \
15862306a36Sopenharmony_ci	to_clk(imx_clk_hw_pllv1(type, name, parent, base))
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci#define imx_clk_pllv2(name, parent, base) \
16162306a36Sopenharmony_ci	to_clk(imx_clk_hw_pllv2(name, parent, base))
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci#define imx_clk_hw_gate(name, parent, reg, shift) \
16462306a36Sopenharmony_ci	imx_clk_hw_gate_flags(name, parent, reg, shift, 0)
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci#define imx_clk_hw_gate2(name, parent, reg, shift) \
16762306a36Sopenharmony_ci	imx_clk_hw_gate2_flags(name, parent, reg, shift, 0)
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci#define imx_clk_hw_gate_dis(name, parent, reg, shift) \
17062306a36Sopenharmony_ci	imx_clk_hw_gate_dis_flags(name, parent, reg, shift, 0)
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_ci#define imx_clk_hw_gate_dis_flags(name, parent, reg, shift, flags) \
17362306a36Sopenharmony_ci	__imx_clk_hw_gate(name, parent, reg, shift, flags, CLK_GATE_SET_TO_DISABLE)
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci#define imx_clk_hw_gate_flags(name, parent, reg, shift, flags) \
17662306a36Sopenharmony_ci	__imx_clk_hw_gate(name, parent, reg, shift, flags, 0)
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci#define imx_clk_hw_gate2_flags(name, parent, reg, shift, flags) \
17962306a36Sopenharmony_ci	__imx_clk_hw_gate2(name, parent, reg, shift, 0x3, flags, NULL)
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci#define imx_clk_hw_gate2_shared(name, parent, reg, shift, shared_count) \
18262306a36Sopenharmony_ci	__imx_clk_hw_gate2(name, parent, reg, shift, 0x3, 0, shared_count)
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci#define imx_clk_hw_gate2_shared2(name, parent, reg, shift, shared_count) \
18562306a36Sopenharmony_ci	__imx_clk_hw_gate2(name, parent, reg, shift, 0x3, CLK_OPS_PARENT_ENABLE, shared_count)
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ci#define imx_clk_hw_gate3(name, parent, reg, shift) \
18862306a36Sopenharmony_ci	imx_clk_hw_gate3_flags(name, parent, reg, shift, 0)
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci#define imx_clk_hw_gate3_flags(name, parent, reg, shift, flags) \
19162306a36Sopenharmony_ci	__imx_clk_hw_gate(name, parent, reg, shift, flags | CLK_OPS_PARENT_ENABLE, 0)
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci#define imx_clk_hw_gate4(name, parent, reg, shift) \
19462306a36Sopenharmony_ci	imx_clk_hw_gate4_flags(name, parent, reg, shift, 0)
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci#define imx_clk_hw_gate4_flags(name, parent, reg, shift, flags) \
19762306a36Sopenharmony_ci	imx_clk_hw_gate2_flags(name, parent, reg, shift, flags | CLK_OPS_PARENT_ENABLE)
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci#define imx_clk_hw_mux2(name, reg, shift, width, parents, num_parents) \
20062306a36Sopenharmony_ci	imx_clk_hw_mux2_flags(name, reg, shift, width, parents, num_parents, 0)
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ci#define imx_clk_hw_mux(name, reg, shift, width, parents, num_parents) \
20362306a36Sopenharmony_ci	__imx_clk_hw_mux(name, reg, shift, width, parents, num_parents, 0, 0)
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci#define imx_clk_hw_mux_flags(name, reg, shift, width, parents, num_parents, flags) \
20662306a36Sopenharmony_ci	__imx_clk_hw_mux(name, reg, shift, width, parents, num_parents, flags, 0)
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci#define imx_clk_hw_mux_ldb(name, reg, shift, width, parents, num_parents) \
20962306a36Sopenharmony_ci	__imx_clk_hw_mux(name, reg, shift, width, parents, num_parents, CLK_SET_RATE_PARENT, CLK_MUX_READ_ONLY)
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci#define imx_clk_hw_mux2_flags(name, reg, shift, width, parents, num_parents, flags) \
21262306a36Sopenharmony_ci	__imx_clk_hw_mux(name, reg, shift, width, parents, num_parents, flags | CLK_OPS_PARENT_ENABLE, 0)
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ci#define imx_clk_hw_divider(name, parent, reg, shift, width) \
21562306a36Sopenharmony_ci	__imx_clk_hw_divider(name, parent, reg, shift, width, CLK_SET_RATE_PARENT)
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ci#define imx_clk_hw_divider2(name, parent, reg, shift, width) \
21862306a36Sopenharmony_ci	__imx_clk_hw_divider(name, parent, reg, shift, width, \
21962306a36Sopenharmony_ci				CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE)
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci#define imx_clk_hw_divider_flags(name, parent, reg, shift, width, flags) \
22262306a36Sopenharmony_ci	__imx_clk_hw_divider(name, parent, reg, shift, width, flags)
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ci#define imx_clk_hw_pll14xx(name, parent_name, base, pll_clk) \
22562306a36Sopenharmony_ci	imx_dev_clk_hw_pll14xx(NULL, name, parent_name, base, pll_clk)
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_cistruct clk_hw *imx_dev_clk_hw_pll14xx(struct device *dev, const char *name,
22862306a36Sopenharmony_ci				const char *parent_name, void __iomem *base,
22962306a36Sopenharmony_ci				const struct imx_pll14xx_clk *pll_clk);
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_pllv1(enum imx_pllv1_type type, const char *name,
23262306a36Sopenharmony_ci		const char *parent, void __iomem *base);
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_pllv2(const char *name, const char *parent,
23562306a36Sopenharmony_ci		void __iomem *base);
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_frac_pll(const char *name, const char *parent_name,
23862306a36Sopenharmony_ci			     void __iomem *base);
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_sscg_pll(const char *name,
24162306a36Sopenharmony_ci				const char * const *parent_names,
24262306a36Sopenharmony_ci				u8 num_parents,
24362306a36Sopenharmony_ci				u8 parent, u8 bypass1, u8 bypass2,
24462306a36Sopenharmony_ci				void __iomem *base,
24562306a36Sopenharmony_ci				unsigned long flags);
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_cienum imx_pllv3_type {
24862306a36Sopenharmony_ci	IMX_PLLV3_GENERIC,
24962306a36Sopenharmony_ci	IMX_PLLV3_SYS,
25062306a36Sopenharmony_ci	IMX_PLLV3_USB,
25162306a36Sopenharmony_ci	IMX_PLLV3_USB_VF610,
25262306a36Sopenharmony_ci	IMX_PLLV3_AV,
25362306a36Sopenharmony_ci	IMX_PLLV3_ENET,
25462306a36Sopenharmony_ci	IMX_PLLV3_ENET_IMX7,
25562306a36Sopenharmony_ci	IMX_PLLV3_SYS_VF610,
25662306a36Sopenharmony_ci	IMX_PLLV3_DDR_IMX7,
25762306a36Sopenharmony_ci	IMX_PLLV3_AV_IMX7,
25862306a36Sopenharmony_ci};
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_pllv3(enum imx_pllv3_type type, const char *name,
26162306a36Sopenharmony_ci		const char *parent_name, void __iomem *base, u32 div_mask);
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ci#define PLL_1416X_RATE(_rate, _m, _p, _s)		\
26462306a36Sopenharmony_ci	{						\
26562306a36Sopenharmony_ci		.rate	=	(_rate),		\
26662306a36Sopenharmony_ci		.mdiv	=	(_m),			\
26762306a36Sopenharmony_ci		.pdiv	=	(_p),			\
26862306a36Sopenharmony_ci		.sdiv	=	(_s),			\
26962306a36Sopenharmony_ci	}
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_ci#define PLL_1443X_RATE(_rate, _m, _p, _s, _k)		\
27262306a36Sopenharmony_ci	{						\
27362306a36Sopenharmony_ci		.rate	=	(_rate),		\
27462306a36Sopenharmony_ci		.mdiv	=	(_m),			\
27562306a36Sopenharmony_ci		.pdiv	=	(_p),			\
27662306a36Sopenharmony_ci		.sdiv	=	(_s),			\
27762306a36Sopenharmony_ci		.kdiv	=	(_k),			\
27862306a36Sopenharmony_ci	}
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_pllv4(enum imx_pllv4_type type, const char *name,
28162306a36Sopenharmony_ci		const char *parent_name, void __iomem *base);
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_cistruct clk_hw *clk_hw_register_gate2(struct device *dev, const char *name,
28462306a36Sopenharmony_ci		const char *parent_name, unsigned long flags,
28562306a36Sopenharmony_ci		void __iomem *reg, u8 bit_idx, u8 cgr_val, u8 cgr_mask,
28662306a36Sopenharmony_ci		u8 clk_gate_flags, spinlock_t *lock,
28762306a36Sopenharmony_ci		unsigned int *share_count);
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_cistruct clk * imx_obtain_fixed_clock(
29062306a36Sopenharmony_ci			const char *name, unsigned long rate);
29162306a36Sopenharmony_ci
29262306a36Sopenharmony_cistruct clk_hw *imx_obtain_fixed_clock_hw(
29362306a36Sopenharmony_ci			const char *name, unsigned long rate);
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_cistruct clk_hw *imx_obtain_fixed_of_clock(struct device_node *np,
29662306a36Sopenharmony_ci					 const char *name, unsigned long rate);
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_cistruct clk_hw *imx_get_clk_hw_by_name(struct device_node *np, const char *name);
29962306a36Sopenharmony_ci
30062306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_gate_exclusive(const char *name, const char *parent,
30162306a36Sopenharmony_ci	 void __iomem *reg, u8 shift, u32 exclusive_mask);
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_pfd(const char *name, const char *parent_name,
30462306a36Sopenharmony_ci		void __iomem *reg, u8 idx);
30562306a36Sopenharmony_ci
30662306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_pfdv2(enum imx_pfdv2_type type, const char *name,
30762306a36Sopenharmony_ci	 const char *parent_name, void __iomem *reg, u8 idx);
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_busy_divider(const char *name, const char *parent_name,
31062306a36Sopenharmony_ci				 void __iomem *reg, u8 shift, u8 width,
31162306a36Sopenharmony_ci				 void __iomem *busy_reg, u8 busy_shift);
31262306a36Sopenharmony_ci
31362306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_busy_mux(const char *name, void __iomem *reg, u8 shift,
31462306a36Sopenharmony_ci			     u8 width, void __iomem *busy_reg, u8 busy_shift,
31562306a36Sopenharmony_ci			     const char * const *parent_names, int num_parents);
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_cistruct clk_hw *imx7ulp_clk_hw_composite(const char *name,
31862306a36Sopenharmony_ci				     const char * const *parent_names,
31962306a36Sopenharmony_ci				     int num_parents, bool mux_present,
32062306a36Sopenharmony_ci				     bool rate_present, bool gate_present,
32162306a36Sopenharmony_ci				     void __iomem *reg);
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_cistruct clk_hw *imx8ulp_clk_hw_composite(const char *name,
32462306a36Sopenharmony_ci				     const char * const *parent_names,
32562306a36Sopenharmony_ci				     int num_parents, bool mux_present,
32662306a36Sopenharmony_ci				     bool rate_present, bool gate_present,
32762306a36Sopenharmony_ci				     void __iomem *reg, bool has_swrst);
32862306a36Sopenharmony_ci
32962306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_fixup_divider(const char *name, const char *parent,
33062306a36Sopenharmony_ci				  void __iomem *reg, u8 shift, u8 width,
33162306a36Sopenharmony_ci				  void (*fixup)(u32 *val));
33262306a36Sopenharmony_ci
33362306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_fixup_mux(const char *name, void __iomem *reg,
33462306a36Sopenharmony_ci			      u8 shift, u8 width, const char * const *parents,
33562306a36Sopenharmony_ci			      int num_parents, void (*fixup)(u32 *val));
33662306a36Sopenharmony_ci
33762306a36Sopenharmony_cistatic inline struct clk *to_clk(struct clk_hw *hw)
33862306a36Sopenharmony_ci{
33962306a36Sopenharmony_ci	if (IS_ERR_OR_NULL(hw))
34062306a36Sopenharmony_ci		return ERR_CAST(hw);
34162306a36Sopenharmony_ci	return hw->clk;
34262306a36Sopenharmony_ci}
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_cistatic inline struct clk_hw *imx_clk_hw_fixed(const char *name, int rate)
34562306a36Sopenharmony_ci{
34662306a36Sopenharmony_ci	return clk_hw_register_fixed_rate(NULL, name, NULL, 0, rate);
34762306a36Sopenharmony_ci}
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_cistatic inline struct clk_hw *imx_clk_hw_fixed_factor(const char *name,
35062306a36Sopenharmony_ci		const char *parent, unsigned int mult, unsigned int div)
35162306a36Sopenharmony_ci{
35262306a36Sopenharmony_ci	return clk_hw_register_fixed_factor(NULL, name, parent,
35362306a36Sopenharmony_ci			CLK_SET_RATE_PARENT, mult, div);
35462306a36Sopenharmony_ci}
35562306a36Sopenharmony_ci
35662306a36Sopenharmony_cistatic inline struct clk_hw *imx_clk_hw_divider_closest(const char *name,
35762306a36Sopenharmony_ci						const char *parent,
35862306a36Sopenharmony_ci						void __iomem *reg, u8 shift,
35962306a36Sopenharmony_ci						u8 width)
36062306a36Sopenharmony_ci{
36162306a36Sopenharmony_ci	return clk_hw_register_divider(NULL, name, parent, 0,
36262306a36Sopenharmony_ci				       reg, shift, width, CLK_DIVIDER_ROUND_CLOSEST, &imx_ccm_lock);
36362306a36Sopenharmony_ci}
36462306a36Sopenharmony_ci
36562306a36Sopenharmony_cistatic inline struct clk_hw *__imx_clk_hw_divider(const char *name,
36662306a36Sopenharmony_ci						   const char *parent,
36762306a36Sopenharmony_ci						   void __iomem *reg, u8 shift,
36862306a36Sopenharmony_ci						   u8 width, unsigned long flags)
36962306a36Sopenharmony_ci{
37062306a36Sopenharmony_ci	return clk_hw_register_divider(NULL, name, parent, flags,
37162306a36Sopenharmony_ci				       reg, shift, width, 0, &imx_ccm_lock);
37262306a36Sopenharmony_ci}
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_cistatic inline struct clk_hw *__imx_clk_hw_gate(const char *name, const char *parent,
37562306a36Sopenharmony_ci						void __iomem *reg, u8 shift,
37662306a36Sopenharmony_ci						unsigned long flags,
37762306a36Sopenharmony_ci						unsigned long clk_gate_flags)
37862306a36Sopenharmony_ci{
37962306a36Sopenharmony_ci	return clk_hw_register_gate(NULL, name, parent, flags | CLK_SET_RATE_PARENT, reg,
38062306a36Sopenharmony_ci					shift, clk_gate_flags, &imx_ccm_lock);
38162306a36Sopenharmony_ci}
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_cistatic inline struct clk_hw *__imx_clk_hw_gate2(const char *name, const char *parent,
38462306a36Sopenharmony_ci						void __iomem *reg, u8 shift, u8 cgr_val,
38562306a36Sopenharmony_ci						unsigned long flags,
38662306a36Sopenharmony_ci						unsigned int *share_count)
38762306a36Sopenharmony_ci{
38862306a36Sopenharmony_ci	return clk_hw_register_gate2(NULL, name, parent, flags | CLK_SET_RATE_PARENT, reg,
38962306a36Sopenharmony_ci					shift, cgr_val, 0x3, 0, &imx_ccm_lock, share_count);
39062306a36Sopenharmony_ci}
39162306a36Sopenharmony_ci
39262306a36Sopenharmony_cistatic inline struct clk_hw *__imx_clk_hw_mux(const char *name, void __iomem *reg,
39362306a36Sopenharmony_ci			u8 shift, u8 width, const char * const *parents,
39462306a36Sopenharmony_ci			int num_parents, unsigned long flags, unsigned long clk_mux_flags)
39562306a36Sopenharmony_ci{
39662306a36Sopenharmony_ci	return clk_hw_register_mux(NULL, name, parents, num_parents,
39762306a36Sopenharmony_ci			flags | CLK_SET_RATE_NO_REPARENT, reg, shift,
39862306a36Sopenharmony_ci			width, clk_mux_flags, &imx_ccm_lock);
39962306a36Sopenharmony_ci}
40062306a36Sopenharmony_ci
40162306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_cpu(const char *name, const char *parent_name,
40262306a36Sopenharmony_ci		struct clk *div, struct clk *mux, struct clk *pll,
40362306a36Sopenharmony_ci		struct clk *step);
40462306a36Sopenharmony_ci
40562306a36Sopenharmony_ci#define IMX_COMPOSITE_CORE		BIT(0)
40662306a36Sopenharmony_ci#define IMX_COMPOSITE_BUS		BIT(1)
40762306a36Sopenharmony_ci#define IMX_COMPOSITE_FW_MANAGED	BIT(2)
40862306a36Sopenharmony_ci
40962306a36Sopenharmony_ci#define IMX_COMPOSITE_CLK_FLAGS_DEFAULT \
41062306a36Sopenharmony_ci	(CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE)
41162306a36Sopenharmony_ci#define IMX_COMPOSITE_CLK_FLAGS_CRITICAL \
41262306a36Sopenharmony_ci	(IMX_COMPOSITE_CLK_FLAGS_DEFAULT | CLK_IS_CRITICAL)
41362306a36Sopenharmony_ci#define IMX_COMPOSITE_CLK_FLAGS_GET_RATE_NO_CACHE \
41462306a36Sopenharmony_ci	(IMX_COMPOSITE_CLK_FLAGS_DEFAULT | CLK_GET_RATE_NOCACHE)
41562306a36Sopenharmony_ci#define IMX_COMPOSITE_CLK_FLAGS_CRITICAL_GET_RATE_NO_CACHE \
41662306a36Sopenharmony_ci	(IMX_COMPOSITE_CLK_FLAGS_GET_RATE_NO_CACHE | CLK_IS_CRITICAL)
41762306a36Sopenharmony_ci
41862306a36Sopenharmony_cistruct clk_hw *__imx8m_clk_hw_composite(const char *name,
41962306a36Sopenharmony_ci					    const char * const *parent_names,
42062306a36Sopenharmony_ci					    int num_parents,
42162306a36Sopenharmony_ci					    void __iomem *reg,
42262306a36Sopenharmony_ci					    u32 composite_flags,
42362306a36Sopenharmony_ci					    unsigned long flags);
42462306a36Sopenharmony_ci
42562306a36Sopenharmony_ci#define _imx8m_clk_hw_composite(name, parent_names, reg, composite_flags, flags) \
42662306a36Sopenharmony_ci	__imx8m_clk_hw_composite(name, parent_names, \
42762306a36Sopenharmony_ci		ARRAY_SIZE(parent_names), reg, composite_flags, flags)
42862306a36Sopenharmony_ci
42962306a36Sopenharmony_ci#define imx8m_clk_hw_composite(name, parent_names, reg) \
43062306a36Sopenharmony_ci	_imx8m_clk_hw_composite(name, parent_names, reg, \
43162306a36Sopenharmony_ci			0, IMX_COMPOSITE_CLK_FLAGS_DEFAULT)
43262306a36Sopenharmony_ci
43362306a36Sopenharmony_ci#define imx8m_clk_hw_composite_flags(name, parent_names, reg, flags) \
43462306a36Sopenharmony_ci	_imx8m_clk_hw_composite(name, parent_names, reg, \
43562306a36Sopenharmony_ci			0, IMX_COMPOSITE_CLK_FLAGS_DEFAULT |  flags)
43662306a36Sopenharmony_ci
43762306a36Sopenharmony_ci#define imx8m_clk_hw_composite_critical(name, parent_names, reg) \
43862306a36Sopenharmony_ci	_imx8m_clk_hw_composite(name, parent_names, reg, \
43962306a36Sopenharmony_ci			0, IMX_COMPOSITE_CLK_FLAGS_CRITICAL)
44062306a36Sopenharmony_ci
44162306a36Sopenharmony_ci#define imx8m_clk_hw_composite_bus(name, parent_names, reg)	\
44262306a36Sopenharmony_ci	_imx8m_clk_hw_composite(name, parent_names, reg, \
44362306a36Sopenharmony_ci			IMX_COMPOSITE_BUS, IMX_COMPOSITE_CLK_FLAGS_DEFAULT)
44462306a36Sopenharmony_ci
44562306a36Sopenharmony_ci#define imx8m_clk_hw_composite_bus_critical(name, parent_names, reg)	\
44662306a36Sopenharmony_ci	_imx8m_clk_hw_composite(name, parent_names, reg, \
44762306a36Sopenharmony_ci			IMX_COMPOSITE_BUS, IMX_COMPOSITE_CLK_FLAGS_CRITICAL)
44862306a36Sopenharmony_ci
44962306a36Sopenharmony_ci#define imx8m_clk_hw_composite_core(name, parent_names, reg)	\
45062306a36Sopenharmony_ci	_imx8m_clk_hw_composite(name, parent_names, reg, \
45162306a36Sopenharmony_ci			IMX_COMPOSITE_CORE, IMX_COMPOSITE_CLK_FLAGS_DEFAULT)
45262306a36Sopenharmony_ci
45362306a36Sopenharmony_ci#define imx8m_clk_hw_fw_managed_composite(name, parent_names, reg) \
45462306a36Sopenharmony_ci	_imx8m_clk_hw_composite(name, parent_names, reg, \
45562306a36Sopenharmony_ci			IMX_COMPOSITE_FW_MANAGED, \
45662306a36Sopenharmony_ci			IMX_COMPOSITE_CLK_FLAGS_GET_RATE_NO_CACHE)
45762306a36Sopenharmony_ci
45862306a36Sopenharmony_ci#define imx8m_clk_hw_fw_managed_composite_critical(name, parent_names, reg) \
45962306a36Sopenharmony_ci	_imx8m_clk_hw_composite(name, parent_names, reg, \
46062306a36Sopenharmony_ci			IMX_COMPOSITE_FW_MANAGED, \
46162306a36Sopenharmony_ci			IMX_COMPOSITE_CLK_FLAGS_CRITICAL_GET_RATE_NO_CACHE)
46262306a36Sopenharmony_ci
46362306a36Sopenharmony_cistruct clk_hw *imx93_clk_composite_flags(const char *name,
46462306a36Sopenharmony_ci					 const char * const *parent_names,
46562306a36Sopenharmony_ci					 int num_parents,
46662306a36Sopenharmony_ci					 void __iomem *reg,
46762306a36Sopenharmony_ci					 u32 domain_id,
46862306a36Sopenharmony_ci					 unsigned long flags);
46962306a36Sopenharmony_ci#define imx93_clk_composite(name, parent_names, num_parents, reg, domain_id) \
47062306a36Sopenharmony_ci	imx93_clk_composite_flags(name, parent_names, num_parents, reg, domain_id \
47162306a36Sopenharmony_ci				  CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE)
47262306a36Sopenharmony_ci
47362306a36Sopenharmony_cistruct clk_hw *imx93_clk_gate(struct device *dev, const char *name, const char *parent_name,
47462306a36Sopenharmony_ci			      unsigned long flags, void __iomem *reg, u32 bit_idx, u32 val,
47562306a36Sopenharmony_ci			      u32 mask, u32 domain_id, unsigned int *share_count);
47662306a36Sopenharmony_ci
47762306a36Sopenharmony_cistruct clk_hw *imx_clk_hw_divider_gate(const char *name, const char *parent_name,
47862306a36Sopenharmony_ci		unsigned long flags, void __iomem *reg, u8 shift, u8 width,
47962306a36Sopenharmony_ci		u8 clk_divider_flags, const struct clk_div_table *table,
48062306a36Sopenharmony_ci		spinlock_t *lock);
48162306a36Sopenharmony_ci
48262306a36Sopenharmony_cistruct clk_hw *imx_clk_gpr_mux(const char *name, const char *compatible,
48362306a36Sopenharmony_ci			       u32 reg, const char **parent_names,
48462306a36Sopenharmony_ci			       u8 num_parents, const u32 *mux_table, u32 mask);
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_ci#endif
487