xref: /openbmc/linux/drivers/clk/sprd/gate.h (revision c6fddb28)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 //
3 // Spreadtrum gate clock driver
4 //
5 // Copyright (C) 2017 Spreadtrum, Inc.
6 // Author: Chunyan Zhang <chunyan.zhang@spreadtrum.com>
7 
8 #ifndef _SPRD_GATE_H_
9 #define _SPRD_GATE_H_
10 
11 #include "common.h"
12 
13 struct sprd_gate {
14 	u32			enable_mask;
15 	u16			flags;
16 	u16			sc_offset;
17 	u16			udelay;
18 
19 	struct sprd_clk_common	common;
20 };
21 
22 #define SPRD_SC_GATE_CLK_HW_INIT_FN(_struct, _name, _parent, _reg,	\
23 				    _sc_offset, _enable_mask, _flags,	\
24 				    _gate_flags, _udelay, _ops, _fn)	\
25 	struct sprd_gate _struct = {					\
26 		.enable_mask	= _enable_mask,				\
27 		.sc_offset	= _sc_offset,				\
28 		.flags		= _gate_flags,				\
29 		.udelay		= _udelay,				\
30 		.common	= {						\
31 			.regmap		= NULL,				\
32 			.reg		= _reg,				\
33 			.hw.init	= _fn(_name, _parent,		\
34 					      _ops, _flags),		\
35 		}							\
36 	}
37 
38 #define SPRD_SC_GATE_CLK_OPS_UDELAY(_struct, _name, _parent, _reg,	\
39 				    _sc_offset, _enable_mask, _flags,	\
40 				    _gate_flags, _udelay, _ops)		\
41 	SPRD_SC_GATE_CLK_HW_INIT_FN(_struct, _name, _parent, _reg,	\
42 				    _sc_offset, _enable_mask, _flags,	\
43 				    _gate_flags, _udelay, _ops, CLK_HW_INIT)
44 
45 #define SPRD_SC_GATE_CLK_OPS(_struct, _name, _parent, _reg, _sc_offset,	\
46 			     _enable_mask, _flags, _gate_flags, _ops)	\
47 	SPRD_SC_GATE_CLK_OPS_UDELAY(_struct, _name, _parent, _reg,	\
48 				    _sc_offset, _enable_mask, _flags,	\
49 				    _gate_flags, 0, _ops)
50 
51 #define SPRD_SC_GATE_CLK(_struct, _name, _parent, _reg, _sc_offset,	\
52 			 _enable_mask, _flags, _gate_flags)		\
53 	SPRD_SC_GATE_CLK_OPS(_struct, _name, _parent, _reg, _sc_offset,	\
54 			     _enable_mask, _flags, _gate_flags,		\
55 			     &sprd_sc_gate_ops)
56 
57 #define SPRD_GATE_CLK(_struct, _name, _parent, _reg,			\
58 		      _enable_mask, _flags, _gate_flags)		\
59 	SPRD_SC_GATE_CLK_OPS(_struct, _name, _parent, _reg, 0,		\
60 			     _enable_mask, _flags, _gate_flags,		\
61 			     &sprd_gate_ops)
62 
63 #define SPRD_PLL_SC_GATE_CLK(_struct, _name, _parent, _reg, _sc_offset,	\
64 			     _enable_mask, _flags, _gate_flags,		\
65 			     _udelay)					\
66 	SPRD_SC_GATE_CLK_OPS_UDELAY(_struct, _name, _parent, _reg,	\
67 				    _sc_offset,	_enable_mask, _flags,	\
68 				    _gate_flags, _udelay,		\
69 				    &sprd_pll_sc_gate_ops)
70 
71 
72 #define SPRD_SC_GATE_CLK_HW_OPS_UDELAY(_struct, _name, _parent, _reg,	\
73 				       _sc_offset, _enable_mask,	\
74 				       _flags, _gate_flags,		\
75 				       _udelay, _ops)			\
76 	SPRD_SC_GATE_CLK_HW_INIT_FN(_struct, _name, _parent, _reg,	\
77 				    _sc_offset, _enable_mask, _flags,	\
78 				    _gate_flags, _udelay, _ops,		\
79 				    CLK_HW_INIT_HW)
80 
81 #define SPRD_SC_GATE_CLK_HW_OPS(_struct, _name, _parent, _reg,		\
82 				_sc_offset, _enable_mask, _flags,	\
83 				_gate_flags, _ops)			\
84 	SPRD_SC_GATE_CLK_HW_OPS_UDELAY(_struct, _name, _parent, _reg,	\
85 				       _sc_offset, _enable_mask,	\
86 				       _flags, _gate_flags, 0, _ops)
87 
88 #define SPRD_SC_GATE_CLK_HW(_struct, _name, _parent, _reg,		\
89 			    _sc_offset, _enable_mask, _flags,		\
90 			    _gate_flags)				\
91 	SPRD_SC_GATE_CLK_HW_OPS(_struct, _name, _parent, _reg,		\
92 				_sc_offset, _enable_mask, _flags,	\
93 				_gate_flags, &sprd_sc_gate_ops)
94 
95 #define SPRD_GATE_CLK_HW(_struct, _name, _parent, _reg,			\
96 			 _enable_mask, _flags, _gate_flags)		\
97 	SPRD_SC_GATE_CLK_HW_OPS(_struct, _name, _parent, _reg, 0,	\
98 				_enable_mask, _flags, _gate_flags,	\
99 				&sprd_gate_ops)
100 
101 #define SPRD_PLL_SC_GATE_CLK_HW(_struct, _name, _parent, _reg,		\
102 				_sc_offset, _enable_mask, _flags,	\
103 				_gate_flags, _udelay)			\
104 	SPRD_SC_GATE_CLK_HW_OPS_UDELAY(_struct, _name, _parent, _reg,	\
105 				       _sc_offset, _enable_mask,	\
106 				       _flags, _gate_flags, _udelay,	\
107 				       &sprd_pll_sc_gate_ops)
108 
109 #define SPRD_SC_GATE_CLK_FW_NAME_OPS_UDELAY(_struct, _name, _parent,	\
110 					    _reg, _sc_offset,		\
111 					    _enable_mask, _flags,	\
112 					    _gate_flags, _udelay, _ops)	\
113 	SPRD_SC_GATE_CLK_HW_INIT_FN(_struct, _name, _parent, _reg,	\
114 				    _sc_offset, _enable_mask, _flags,	\
115 				    _gate_flags, _udelay, _ops,		\
116 				    CLK_HW_INIT_FW_NAME)
117 
118 #define SPRD_SC_GATE_CLK_FW_NAME_OPS(_struct, _name, _parent, _reg,	\
119 				     _sc_offset, _enable_mask, _flags,	\
120 				     _gate_flags, _ops)			\
121 	SPRD_SC_GATE_CLK_FW_NAME_OPS_UDELAY(_struct, _name, _parent,	\
122 					    _reg, _sc_offset,		\
123 					    _enable_mask, _flags,	\
124 					    _gate_flags, 0, _ops)
125 
126 #define SPRD_SC_GATE_CLK_FW_NAME(_struct, _name, _parent, _reg,		\
127 				 _sc_offset, _enable_mask, _flags,	\
128 				 _gate_flags)				\
129 	SPRD_SC_GATE_CLK_FW_NAME_OPS(_struct, _name, _parent, _reg,	\
130 				     _sc_offset, _enable_mask, _flags,	\
131 				     _gate_flags, &sprd_sc_gate_ops)
132 
133 #define SPRD_GATE_CLK_FW_NAME(_struct, _name, _parent, _reg,		\
134 			      _enable_mask, _flags, _gate_flags)	\
135 	SPRD_SC_GATE_CLK_FW_NAME_OPS(_struct, _name, _parent, _reg, 0,	\
136 				     _enable_mask, _flags, _gate_flags,	\
137 				     &sprd_gate_ops)
138 
139 #define SPRD_PLL_SC_GATE_CLK_FW_NAME(_struct, _name, _parent, _reg,	\
140 				     _sc_offset, _enable_mask, _flags,	\
141 				     _gate_flags, _udelay)		\
142 	SPRD_SC_GATE_CLK_FW_NAME_OPS_UDELAY(_struct, _name, _parent,	\
143 					    _reg, _sc_offset,		\
144 					    _enable_mask, _flags,	\
145 					    _gate_flags, _udelay,	\
146 					    &sprd_pll_sc_gate_ops)
147 
148 static inline struct sprd_gate *hw_to_sprd_gate(const struct clk_hw *hw)
149 {
150 	struct sprd_clk_common *common = hw_to_sprd_clk_common(hw);
151 
152 	return container_of(common, struct sprd_gate, common);
153 }
154 
155 extern const struct clk_ops sprd_gate_ops;
156 extern const struct clk_ops sprd_sc_gate_ops;
157 extern const struct clk_ops sprd_pll_sc_gate_ops;
158 
159 #endif /* _SPRD_GATE_H_ */
160