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