1 /* SPDX-License-Identifier: GPL-2.0 */
3 // Spreadtrum gate clock driver
5 // Copyright (C) 2017 Spreadtrum, Inc.
6 // Author: Chunyan Zhang <chunyan.zhang@spreadtrum.com>
19 struct sprd_clk_common common
;
23 * sprd_gate->flags is used for:
24 * CLK_GATE_SET_TO_DISABLE BIT(0)
25 * CLK_GATE_HIWORD_MASK BIT(1)
26 * CLK_GATE_BIG_ENDIAN BIT(2)
27 * so we define new flags from BIT(3)
29 #define SPRD_GATE_NON_AON BIT(3) /* not alway powered on, check before read */
31 #define SPRD_SC_GATE_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, \
32 _sc_offset, _enable_mask, _flags, \
33 _gate_flags, _udelay, _ops, _fn) \
34 struct sprd_gate _struct = { \
35 .enable_mask = _enable_mask, \
36 .sc_offset = _sc_offset, \
37 .flags = _gate_flags, \
42 .hw.init = _fn(_name, _parent, \
47 #define SPRD_SC_GATE_CLK_OPS_UDELAY(_struct, _name, _parent, _reg, \
48 _sc_offset, _enable_mask, _flags, \
49 _gate_flags, _udelay, _ops) \
50 SPRD_SC_GATE_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, \
51 _sc_offset, _enable_mask, _flags, \
52 _gate_flags, _udelay, _ops, CLK_HW_INIT)
54 #define SPRD_SC_GATE_CLK_OPS(_struct, _name, _parent, _reg, _sc_offset, \
55 _enable_mask, _flags, _gate_flags, _ops) \
56 SPRD_SC_GATE_CLK_OPS_UDELAY(_struct, _name, _parent, _reg, \
57 _sc_offset, _enable_mask, _flags, \
60 #define SPRD_SC_GATE_CLK(_struct, _name, _parent, _reg, _sc_offset, \
61 _enable_mask, _flags, _gate_flags) \
62 SPRD_SC_GATE_CLK_OPS(_struct, _name, _parent, _reg, _sc_offset, \
63 _enable_mask, _flags, _gate_flags, \
66 #define SPRD_GATE_CLK(_struct, _name, _parent, _reg, \
67 _enable_mask, _flags, _gate_flags) \
68 SPRD_SC_GATE_CLK_OPS(_struct, _name, _parent, _reg, 0, \
69 _enable_mask, _flags, _gate_flags, \
72 #define SPRD_PLL_SC_GATE_CLK(_struct, _name, _parent, _reg, _sc_offset, \
73 _enable_mask, _flags, _gate_flags, \
75 SPRD_SC_GATE_CLK_OPS_UDELAY(_struct, _name, _parent, _reg, \
76 _sc_offset, _enable_mask, _flags, \
77 _gate_flags, _udelay, \
78 &sprd_pll_sc_gate_ops)
81 #define SPRD_SC_GATE_CLK_HW_OPS_UDELAY(_struct, _name, _parent, _reg, \
82 _sc_offset, _enable_mask, \
83 _flags, _gate_flags, \
85 SPRD_SC_GATE_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, \
86 _sc_offset, _enable_mask, _flags, \
87 _gate_flags, _udelay, _ops, \
90 #define SPRD_SC_GATE_CLK_HW_OPS(_struct, _name, _parent, _reg, \
91 _sc_offset, _enable_mask, _flags, \
93 SPRD_SC_GATE_CLK_HW_OPS_UDELAY(_struct, _name, _parent, _reg, \
94 _sc_offset, _enable_mask, \
95 _flags, _gate_flags, 0, _ops)
97 #define SPRD_SC_GATE_CLK_HW(_struct, _name, _parent, _reg, \
98 _sc_offset, _enable_mask, _flags, \
100 SPRD_SC_GATE_CLK_HW_OPS(_struct, _name, _parent, _reg, \
101 _sc_offset, _enable_mask, _flags, \
102 _gate_flags, &sprd_sc_gate_ops)
104 #define SPRD_GATE_CLK_HW(_struct, _name, _parent, _reg, \
105 _enable_mask, _flags, _gate_flags) \
106 SPRD_SC_GATE_CLK_HW_OPS(_struct, _name, _parent, _reg, 0, \
107 _enable_mask, _flags, _gate_flags, \
110 #define SPRD_PLL_SC_GATE_CLK_HW(_struct, _name, _parent, _reg, \
111 _sc_offset, _enable_mask, _flags, \
112 _gate_flags, _udelay) \
113 SPRD_SC_GATE_CLK_HW_OPS_UDELAY(_struct, _name, _parent, _reg, \
114 _sc_offset, _enable_mask, \
115 _flags, _gate_flags, _udelay, \
116 &sprd_pll_sc_gate_ops)
118 #define SPRD_SC_GATE_CLK_FW_NAME_OPS_UDELAY(_struct, _name, _parent, \
120 _enable_mask, _flags, \
121 _gate_flags, _udelay, _ops) \
122 SPRD_SC_GATE_CLK_HW_INIT_FN(_struct, _name, _parent, _reg, \
123 _sc_offset, _enable_mask, _flags, \
124 _gate_flags, _udelay, _ops, \
127 #define SPRD_SC_GATE_CLK_FW_NAME_OPS(_struct, _name, _parent, _reg, \
128 _sc_offset, _enable_mask, _flags, \
130 SPRD_SC_GATE_CLK_FW_NAME_OPS_UDELAY(_struct, _name, _parent, \
132 _enable_mask, _flags, \
133 _gate_flags, 0, _ops)
135 #define SPRD_SC_GATE_CLK_FW_NAME(_struct, _name, _parent, _reg, \
136 _sc_offset, _enable_mask, _flags, \
138 SPRD_SC_GATE_CLK_FW_NAME_OPS(_struct, _name, _parent, _reg, \
139 _sc_offset, _enable_mask, _flags, \
140 _gate_flags, &sprd_sc_gate_ops)
142 #define SPRD_GATE_CLK_FW_NAME(_struct, _name, _parent, _reg, \
143 _enable_mask, _flags, _gate_flags) \
144 SPRD_SC_GATE_CLK_FW_NAME_OPS(_struct, _name, _parent, _reg, 0, \
145 _enable_mask, _flags, _gate_flags, \
148 #define SPRD_PLL_SC_GATE_CLK_FW_NAME(_struct, _name, _parent, _reg, \
149 _sc_offset, _enable_mask, _flags, \
150 _gate_flags, _udelay) \
151 SPRD_SC_GATE_CLK_FW_NAME_OPS_UDELAY(_struct, _name, _parent, \
153 _enable_mask, _flags, \
154 _gate_flags, _udelay, \
155 &sprd_pll_sc_gate_ops)
157 static inline struct sprd_gate
*hw_to_sprd_gate(const struct clk_hw
*hw
)
159 struct sprd_clk_common
*common
= hw_to_sprd_clk_common(hw
);
161 return container_of(common
, struct sprd_gate
, common
);
164 extern const struct clk_ops sprd_gate_ops
;
165 extern const struct clk_ops sprd_sc_gate_ops
;
166 extern const struct clk_ops sprd_pll_sc_gate_ops
;
168 #endif /* _SPRD_GATE_H_ */