xref: /openbmc/linux/drivers/clk/imx/clk-scu.h (revision 036a4b4b)
1fe37b482SAisheng Dong /* SPDX-License-Identifier: GPL-2.0+ */
2fe37b482SAisheng Dong /*
35964012cSDong Aisheng  * Copyright 2018-2021 NXP
4fe37b482SAisheng Dong  *   Dong Aisheng <aisheng.dong@nxp.com>
5fe37b482SAisheng Dong  */
6fe37b482SAisheng Dong 
7fe37b482SAisheng Dong #ifndef __IMX_CLK_SCU_H
8fe37b482SAisheng Dong #define __IMX_CLK_SCU_H
9fe37b482SAisheng Dong 
10fe37b482SAisheng Dong #include <linux/firmware/imx/sci.h>
1177d8f306SDong Aisheng #include <linux/of.h>
12fe37b482SAisheng Dong 
135392c5deSDong Aisheng #define IMX_SCU_GPR_CLK_GATE	BIT(0)
145392c5deSDong Aisheng #define IMX_SCU_GPR_CLK_DIV	BIT(1)
155392c5deSDong Aisheng #define IMX_SCU_GPR_CLK_MUX	BIT(2)
165392c5deSDong Aisheng 
175964012cSDong Aisheng struct imx_clk_scu_rsrc_table {
185964012cSDong Aisheng 	const u32 *rsrc;
195964012cSDong Aisheng 	u8 num;
205964012cSDong Aisheng };
215964012cSDong Aisheng 
2277d8f306SDong Aisheng extern struct list_head imx_scu_clks[];
23ea0c5cbaSDong Aisheng extern const struct dev_pm_ops imx_clk_lpcg_scu_pm_ops;
24*036a4b4bSJacky Bai extern const struct imx_clk_scu_rsrc_table imx_clk_scu_rsrc_imx8dxl;
255964012cSDong Aisheng extern const struct imx_clk_scu_rsrc_table imx_clk_scu_rsrc_imx8qxp;
26afd0406bSDong Aisheng extern const struct imx_clk_scu_rsrc_table imx_clk_scu_rsrc_imx8qm;
2777d8f306SDong Aisheng 
285964012cSDong Aisheng int imx_clk_scu_init(struct device_node *np,
295964012cSDong Aisheng 		     const struct imx_clk_scu_rsrc_table *data);
3077d8f306SDong Aisheng struct clk_hw *imx_scu_of_clk_src_get(struct of_phandle_args *clkspec,
3177d8f306SDong Aisheng 				      void *data);
3277d8f306SDong Aisheng struct clk_hw *imx_clk_scu_alloc_dev(const char *name,
3377d8f306SDong Aisheng 				     const char * const *parents,
3477d8f306SDong Aisheng 				     int num_parents, u32 rsrc_id, u8 clk_type);
35666aed2dSAisheng Dong 
362f1a2c1dSDong Aisheng struct clk_hw *__imx_clk_scu(struct device *dev, const char *name,
372f1a2c1dSDong Aisheng 			     const char * const *parents, int num_parents,
382f1a2c1dSDong Aisheng 			     u32 rsrc_id, u8 clk_type);
39666aed2dSAisheng Dong 
4077d8f306SDong Aisheng void imx_clk_scu_unregister(void);
4177d8f306SDong Aisheng 
42a4bfc85cSDong Aisheng struct clk_hw *__imx_clk_lpcg_scu(struct device *dev, const char *name,
43a4bfc85cSDong Aisheng 				  const char *parent_name, unsigned long flags,
44a4bfc85cSDong Aisheng 				  void __iomem *reg, u8 bit_idx, bool hw_gate);
45a4bfc85cSDong Aisheng void imx_clk_lpcg_scu_unregister(struct clk_hw *hw);
46a4bfc85cSDong Aisheng 
475392c5deSDong Aisheng struct clk_hw *__imx_clk_gpr_scu(const char *name, const char * const *parent_name,
485392c5deSDong Aisheng 				 int num_parents, u32 rsrc_id, u8 gpr_id, u8 flags,
495392c5deSDong Aisheng 				 bool invert);
505392c5deSDong Aisheng 
imx_clk_scu(const char * name,u32 rsrc_id,u8 clk_type)51666aed2dSAisheng Dong static inline struct clk_hw *imx_clk_scu(const char *name, u32 rsrc_id,
5291e91677SDong Aisheng 					 u8 clk_type)
53666aed2dSAisheng Dong {
5477d8f306SDong Aisheng 	return imx_clk_scu_alloc_dev(name, NULL, 0, rsrc_id, clk_type);
55666aed2dSAisheng Dong }
56666aed2dSAisheng Dong 
imx_clk_scu2(const char * name,const char * const * parents,int num_parents,u32 rsrc_id,u8 clk_type)57666aed2dSAisheng Dong static inline struct clk_hw *imx_clk_scu2(const char *name, const char * const *parents,
5891e91677SDong Aisheng 					  int num_parents, u32 rsrc_id, u8 clk_type)
59666aed2dSAisheng Dong {
6077d8f306SDong Aisheng 	return imx_clk_scu_alloc_dev(name, parents, num_parents, rsrc_id, clk_type);
61666aed2dSAisheng Dong }
62fe37b482SAisheng Dong 
imx_clk_lpcg_scu_dev(struct device * dev,const char * name,const char * parent_name,unsigned long flags,void __iomem * reg,u8 bit_idx,bool hw_gate)63a4bfc85cSDong Aisheng static inline struct clk_hw *imx_clk_lpcg_scu_dev(struct device *dev, const char *name,
64a4bfc85cSDong Aisheng 						  const char *parent_name, unsigned long flags,
65a4bfc85cSDong Aisheng 						  void __iomem *reg, u8 bit_idx, bool hw_gate)
66a4bfc85cSDong Aisheng {
67a4bfc85cSDong Aisheng 	return __imx_clk_lpcg_scu(dev, name, parent_name, flags, reg,
68a4bfc85cSDong Aisheng 				  bit_idx, hw_gate);
69a4bfc85cSDong Aisheng }
70a4bfc85cSDong Aisheng 
imx_clk_lpcg_scu(const char * name,const char * parent_name,unsigned long flags,void __iomem * reg,u8 bit_idx,bool hw_gate)71a4bfc85cSDong Aisheng static inline struct clk_hw *imx_clk_lpcg_scu(const char *name, const char *parent_name,
722f77296dSAisheng Dong 					      unsigned long flags, void __iomem *reg,
73a4bfc85cSDong Aisheng 					      u8 bit_idx, bool hw_gate)
74a4bfc85cSDong Aisheng {
75a4bfc85cSDong Aisheng 	return __imx_clk_lpcg_scu(NULL, name, parent_name, flags, reg,
76a4bfc85cSDong Aisheng 				  bit_idx, hw_gate);
77a4bfc85cSDong Aisheng }
785392c5deSDong Aisheng 
imx_clk_gate_gpr_scu(const char * name,const char * parent_name,u32 rsrc_id,u8 gpr_id,bool invert)795392c5deSDong Aisheng static inline struct clk_hw *imx_clk_gate_gpr_scu(const char *name, const char *parent_name,
805392c5deSDong Aisheng 						  u32 rsrc_id, u8 gpr_id, bool invert)
815392c5deSDong Aisheng {
825392c5deSDong Aisheng 	return __imx_clk_gpr_scu(name, &parent_name, 1, rsrc_id, gpr_id,
835392c5deSDong Aisheng 				 IMX_SCU_GPR_CLK_GATE, invert);
845392c5deSDong Aisheng }
855392c5deSDong Aisheng 
imx_clk_divider_gpr_scu(const char * name,const char * parent_name,u32 rsrc_id,u8 gpr_id)865392c5deSDong Aisheng static inline struct clk_hw *imx_clk_divider_gpr_scu(const char *name, const char *parent_name,
875392c5deSDong Aisheng 						     u32 rsrc_id, u8 gpr_id)
885392c5deSDong Aisheng {
895392c5deSDong Aisheng 	return __imx_clk_gpr_scu(name, &parent_name, 1, rsrc_id, gpr_id,
905392c5deSDong Aisheng 				 IMX_SCU_GPR_CLK_DIV, 0);
915392c5deSDong Aisheng }
925392c5deSDong Aisheng 
imx_clk_mux_gpr_scu(const char * name,const char * const * parent_names,int num_parents,u32 rsrc_id,u8 gpr_id)935392c5deSDong Aisheng static inline struct clk_hw *imx_clk_mux_gpr_scu(const char *name, const char * const *parent_names,
945392c5deSDong Aisheng 						 int num_parents, u32 rsrc_id, u8 gpr_id)
955392c5deSDong Aisheng {
965392c5deSDong Aisheng 	return __imx_clk_gpr_scu(name, parent_names, num_parents, rsrc_id,
975392c5deSDong Aisheng 				 gpr_id, IMX_SCU_GPR_CLK_MUX, 0);
985392c5deSDong Aisheng }
99fe37b482SAisheng Dong #endif
100