rk: restore file mode
[firefly-linux-kernel-4.4.55.git] / include / linux / clk-private.h
1 /*
2  *  linux/include/linux/clk-private.h
3  *
4  *  Copyright (c) 2010-2011 Jeremy Kerr <jeremy.kerr@canonical.com>
5  *  Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11 #ifndef __LINUX_CLK_PRIVATE_H
12 #define __LINUX_CLK_PRIVATE_H
13
14 #include <linux/clk-provider.h>
15 #include <linux/list.h>
16
17 /*
18  * WARNING: Do not include clk-private.h from any file that implements struct
19  * clk_ops.  Doing so is a layering violation!
20  *
21  * This header exists only to allow for statically initialized clock data.  Any
22  * static clock data must be defined in a separate file from the logic that
23  * implements the clock operations for that same data.
24  */
25
26 #ifdef CONFIG_COMMON_CLK
27
28 struct clk {
29         const char              *name;
30         const struct clk_ops    *ops;
31         struct clk_hw           *hw;
32         struct clk              *parent;
33         const char              **parent_names;
34         struct clk              **parents;
35         u8                      num_parents;
36         u8                      new_parent_index;
37         unsigned long           rate;
38         unsigned long           new_rate;
39         struct clk              *new_parent;
40         struct clk              *new_child;
41         unsigned long           flags;
42         unsigned int            enable_count;
43         unsigned int            prepare_count;
44         struct hlist_head       children;
45         struct hlist_node       child_node;
46         unsigned int            notifier_count;
47
48         void                    *private_data;
49 #ifdef CONFIG_COMMON_CLK_DEBUG
50         struct dentry           *dentry;
51 #endif
52 };
53
54 /*
55  * DOC: Basic clock implementations common to many platforms
56  *
57  * Each basic clock hardware type is comprised of a structure describing the
58  * clock hardware, implementations of the relevant callbacks in struct clk_ops,
59  * unique flags for that hardware type, a registration function and an
60  * alternative macro for static initialization
61  */
62
63 #define DEFINE_CLK(_name, _ops, _flags, _parent_names,          \
64                 _parents)                                       \
65         static struct clk _name = {                             \
66                 .name = #_name,                                 \
67                 .ops = &_ops,                                   \
68                 .hw = &_name##_hw.hw,                           \
69                 .parent_names = _parent_names,                  \
70                 .num_parents = ARRAY_SIZE(_parent_names),       \
71                 .parents = _parents,                            \
72                 .flags = _flags | CLK_IS_BASIC,                 \
73         }
74
75 #define DEFINE_CLK_FIXED_RATE(_name, _flags, _rate,             \
76                                 _fixed_rate_flags)              \
77         static struct clk _name;                                \
78         static const char *_name##_parent_names[] = {};         \
79         static struct clk_fixed_rate _name##_hw = {             \
80                 .hw = {                                         \
81                         .clk = &_name,                          \
82                 },                                              \
83                 .fixed_rate = _rate,                            \
84                 .flags = _fixed_rate_flags,                     \
85         };                                                      \
86         DEFINE_CLK(_name, clk_fixed_rate_ops, _flags,           \
87                         _name##_parent_names, NULL);
88
89 #define DEFINE_CLK_GATE(_name, _parent_name, _parent_ptr,       \
90                                 _flags, _reg, _bit_idx,         \
91                                 _gate_flags, _lock)             \
92         static struct clk _name;                                \
93         static const char *_name##_parent_names[] = {           \
94                 _parent_name,                                   \
95         };                                                      \
96         static struct clk *_name##_parents[] = {                \
97                 _parent_ptr,                                    \
98         };                                                      \
99         static struct clk_gate _name##_hw = {                   \
100                 .hw = {                                         \
101                         .clk = &_name,                          \
102                 },                                              \
103                 .reg = _reg,                                    \
104                 .bit_idx = _bit_idx,                            \
105                 .flags = _gate_flags,                           \
106                 .lock = _lock,                                  \
107         };                                                      \
108         DEFINE_CLK(_name, clk_gate_ops, _flags,                 \
109                         _name##_parent_names, _name##_parents);
110
111 #define _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr,   \
112                                 _flags, _reg, _shift, _width,   \
113                                 _divider_flags, _table, _lock)  \
114         static struct clk _name;                                \
115         static const char *_name##_parent_names[] = {           \
116                 _parent_name,                                   \
117         };                                                      \
118         static struct clk *_name##_parents[] = {                \
119                 _parent_ptr,                                    \
120         };                                                      \
121         static struct clk_divider _name##_hw = {                \
122                 .hw = {                                         \
123                         .clk = &_name,                          \
124                 },                                              \
125                 .reg = _reg,                                    \
126                 .shift = _shift,                                \
127                 .width = _width,                                \
128                 .flags = _divider_flags,                        \
129                 .table = _table,                                \
130                 .lock = _lock,                                  \
131         };                                                      \
132         DEFINE_CLK(_name, clk_divider_ops, _flags,              \
133                         _name##_parent_names, _name##_parents);
134
135 #define DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr,    \
136                                 _flags, _reg, _shift, _width,   \
137                                 _divider_flags, _lock)          \
138         _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr,   \
139                                 _flags, _reg, _shift, _width,   \
140                                 _divider_flags, NULL, _lock)
141
142 #define DEFINE_CLK_DIVIDER_TABLE(_name, _parent_name,           \
143                                 _parent_ptr, _flags, _reg,      \
144                                 _shift, _width, _divider_flags, \
145                                 _table, _lock)                  \
146         _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr,   \
147                                 _flags, _reg, _shift, _width,   \
148                                 _divider_flags, _table, _lock)  \
149
150 #define DEFINE_CLK_MUX(_name, _parent_names, _parents, _flags,  \
151                                 _reg, _shift, _width,           \
152                                 _mux_flags, _lock)              \
153         static struct clk _name;                                \
154         static struct clk_mux _name##_hw = {                    \
155                 .hw = {                                         \
156                         .clk = &_name,                          \
157                 },                                              \
158                 .reg = _reg,                                    \
159                 .shift = _shift,                                \
160                 .mask = BIT(_width) - 1,                        \
161                 .flags = _mux_flags,                            \
162                 .lock = _lock,                                  \
163         };                                                      \
164         DEFINE_CLK(_name, clk_mux_ops, _flags, _parent_names,   \
165                         _parents);
166
167 #define DEFINE_CLK_FIXED_FACTOR(_name, _parent_name,            \
168                                 _parent_ptr, _flags,            \
169                                 _mult, _div)                    \
170         static struct clk _name;                                \
171         static const char *_name##_parent_names[] = {           \
172                 _parent_name,                                   \
173         };                                                      \
174         static struct clk *_name##_parents[] = {                \
175                 _parent_ptr,                                    \
176         };                                                      \
177         static struct clk_fixed_factor _name##_hw = {           \
178                 .hw = {                                         \
179                         .clk = &_name,                          \
180                 },                                              \
181                 .mult = _mult,                                  \
182                 .div = _div,                                    \
183         };                                                      \
184         DEFINE_CLK(_name, clk_fixed_factor_ops, _flags,         \
185                         _name##_parent_names, _name##_parents);
186
187 /**
188  * __clk_init - initialize the data structures in a struct clk
189  * @dev:        device initializing this clk, placeholder for now
190  * @clk:        clk being initialized
191  *
192  * Initializes the lists in struct clk, queries the hardware for the
193  * parent and rate and sets them both.
194  *
195  * Any struct clk passed into __clk_init must have the following members
196  * populated:
197  *      .name
198  *      .ops
199  *      .hw
200  *      .parent_names
201  *      .num_parents
202  *      .flags
203  *
204  * It is not necessary to call clk_register if __clk_init is used directly with
205  * statically initialized clock data.
206  *
207  * Returns 0 on success, otherwise an error code.
208  */
209 int __clk_init(struct device *dev, struct clk *clk);
210
211 struct clk *__clk_register(struct device *dev, struct clk_hw *hw);
212
213 #endif /* CONFIG_COMMON_CLK */
214 #endif /* CLK_PRIVATE_H */