1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2016 Maxime Ripard. All rights reserved.
4  */
5 
6 #ifndef _CCU_GATE_H_
7 #define _CCU_GATE_H_
8 
9 #include "ccu.h"
10 #include "ccu_common.h"
11 
12 struct ccu_gate
13 {
14     u32         enable;
15     u32     fixed_rate;
16 
17     struct ccu_common   common;
18 };
19 
20 #define SUNXI_CCU_GATE_WITH_FIXED_RATE(_struct, _name, _parent, _reg,   \
21                                        _fixed_rate, _gate)  \
22 struct ccu_gate _struct = {                 \
23     .enable     = _gate,                \
24                   .fixed_rate = _fixed_rate,              \
25                                 .common = {                     \
26                                                                 .reg        = _reg,             \
27                                                                 .features   = CCU_FEATURE_FIXED_RATE_GATE,  \
28                                                                 .hw.init    = CLK_HW_INIT(_name,        \
29                                                                         _parent,      \
30                                                                         &ccu_gate_ops,    \
31                                                                         0),       \
32                                           }                           \
33 }
34 
35 #define SUNXI_CCU_GATE_WITH_PREDIV(_struct, _name, _parent, _reg,   \
36                                    _prediv, _gate, _flags)      \
37 struct ccu_gate _struct = {                 \
38     .enable = _gate,                    \
39               .common = {                     \
40                                               .reg        = _reg,             \
41                                               .prediv     = _prediv,          \
42                                               .features   = CCU_FEATURE_ALL_PREDIV,   \
43                                               .hw.init    = CLK_HW_INIT(_name,        \
44                                                       _parent,      \
45                                                       &ccu_gate_ops,    \
46                                                       _flags),      \
47                         }                           \
48 }
49 
50 #define SUNXI_CCU_GATE_WITH_KEY(_struct, _name, _parent, _reg,      \
51                                 _key_value, _gate, _flags)      \
52 struct ccu_gate _struct = {                 \
53     .enable = _gate,                    \
54               .common = {                     \
55                                               .reg        = _reg,             \
56                                               .key_value  = _key_value,           \
57                                               .features   = CCU_FEATURE_KEY_FIELD_MOD,    \
58                                               .hw.init    = CLK_HW_INIT(_name,        \
59                                                       _parent,      \
60                                                       &ccu_gate_ops,    \
61                                                       _flags),      \
62                         }                           \
63 }
64 
65 #define SUNXI_CCU_GATE(_struct, _name, _parent, _reg, _gate, _flags)    \
66     struct ccu_gate _struct = {                 \
67         .enable = _gate,                    \
68                   .common = {                     \
69                                                   .reg        = _reg,             \
70                                                   .hw.init    = CLK_HW_INIT(_name,        \
71                                                           _parent,      \
72                                                           &ccu_gate_ops,    \
73                                                           _flags),      \
74                             }                           \
75     }
76 
77 #define SUNXI_CCU_GATE_HW(_struct, _name, _parent, _reg, _gate, _flags) \
78     struct ccu_gate _struct = {                 \
79         .enable = _gate,                    \
80                   .common = {                     \
81                                                   .reg        = _reg,             \
82                                                   .hw.init    = CLK_HW_INIT_HW(_name,     \
83                                                           _parent,   \
84                                                           &ccu_gate_ops, \
85                                                           _flags),   \
86                             }                           \
87     }
88 
89 #define SUNXI_CCU_GATE_FW(_struct, _name, _parent, _reg, _gate, _flags) \
90     struct ccu_gate _struct = {                 \
91         .enable = _gate,                    \
92                   .common = {                     \
93                                                   .reg        = _reg,             \
94                                                   .hw.init    = CLK_HW_INIT_FW_NAME(_name,    \
95                                                           _parent,  \
96                                                           &ccu_gate_ops, \
97                                                           _flags),  \
98                             }                           \
99     }
100 
101 /*
102  * The following two macros allow the re-use of the data structure
103  * holding the parent info.
104  */
105 #define SUNXI_CCU_GATE_HWS(_struct, _name, _parent, _reg, _gate, _flags) \
106     struct ccu_gate _struct = {                 \
107         .enable = _gate,                    \
108                   .common = {                     \
109                                                   .reg        = _reg,             \
110                                                   .hw.init    = CLK_HW_INIT_HWS(_name,    \
111                                                           _parent,  \
112                                                           &ccu_gate_ops, \
113                                                           _flags),  \
114                             }                           \
115     }
116 
117 #define SUNXI_CCU_GATE_DATA(_struct, _name, _data, _reg, _gate, _flags) \
118     struct ccu_gate _struct = {                 \
119         .enable = _gate,                    \
120                   .common = {                     \
121                                                   .reg        = _reg,             \
122                                                   .hw.init    =               \
123                                                           CLK_HW_INIT_PARENTS_DATA(_name,     \
124                                                                   _data,     \
125                                                                   &ccu_gate_ops, \
126                                                                   _flags),   \
127                             }                           \
128     }
129 
hw_to_ccu_gate(struct clk_hw * hw)130 static inline struct ccu_gate *hw_to_ccu_gate(struct clk_hw *hw)
131 {
132     struct ccu_common *common = hw_to_ccu_common(hw);
133 
134     return container_of(common, struct ccu_gate, common);
135 }
136 
137 void ccu_gate_helper_disable(struct ccu_common *common, u32 gate);
138 int ccu_gate_helper_enable(struct ccu_common *common, u32 gate);
139 int ccu_gate_helper_is_enabled(struct ccu_common *common, u32 gate);
140 
141 extern const struct clk_ops ccu_gate_ops;
142 
143 #endif /* _CCU_GATE_H_ */
144