Merge tag 'v3.10.48' into linux-linaro-lsk
[firefly-linux-kernel-4.4.55.git] / drivers / clk / samsung / clk.h
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
3  * Copyright (c) 2013 Linaro Ltd.
4  * Author: Thomas Abraham <thomas.ab@samsung.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * Common Clock Framework support for all Samsung platforms
11 */
12
13 #ifndef __SAMSUNG_CLK_H
14 #define __SAMSUNG_CLK_H
15
16 #include <linux/clk.h>
17 #include <linux/clkdev.h>
18 #include <linux/io.h>
19 #include <linux/clk-provider.h>
20 #include <linux/of.h>
21 #include <linux/of_address.h>
22
23 /**
24  * struct samsung_clock_alias: information about mux clock
25  * @id: platform specific id of the clock.
26  * @dev_name: name of the device to which this clock belongs.
27  * @alias: optional clock alias name to be assigned to this clock.
28  */
29 struct samsung_clock_alias {
30         unsigned int            id;
31         const char              *dev_name;
32         const char              *alias;
33 };
34
35 #define ALIAS(_id, dname, a)    \
36         {                                                       \
37                 .id             = _id,                          \
38                 .dev_name       = dname,                        \
39                 .alias          = a,                            \
40         }
41
42 /**
43  * struct samsung_fixed_rate_clock: information about fixed-rate clock
44  * @id: platform specific id of the clock.
45  * @name: name of this fixed-rate clock.
46  * @parent_name: optional parent clock name.
47  * @flags: optional fixed-rate clock flags.
48  * @fixed-rate: fixed clock rate of this clock.
49  */
50 struct samsung_fixed_rate_clock {
51         unsigned int            id;
52         char                    *name;
53         const char              *parent_name;
54         unsigned long           flags;
55         unsigned long           fixed_rate;
56 };
57
58 #define FRATE(_id, cname, pname, f, frate)              \
59         {                                               \
60                 .id             = _id,                  \
61                 .name           = cname,                \
62                 .parent_name    = pname,                \
63                 .flags          = f,                    \
64                 .fixed_rate     = frate,                \
65         }
66
67 /*
68  * struct samsung_fixed_factor_clock: information about fixed-factor clock
69  * @id: platform specific id of the clock.
70  * @name: name of this fixed-factor clock.
71  * @parent_name: parent clock name.
72  * @mult: fixed multiplication factor.
73  * @div: fixed division factor.
74  * @flags: optional fixed-factor clock flags.
75  */
76 struct samsung_fixed_factor_clock {
77         unsigned int            id;
78         char                    *name;
79         const char              *parent_name;
80         unsigned long           mult;
81         unsigned long           div;
82         unsigned long           flags;
83 };
84
85 #define FFACTOR(_id, cname, pname, m, d, f)             \
86         {                                               \
87                 .id             = _id,                  \
88                 .name           = cname,                \
89                 .parent_name    = pname,                \
90                 .mult           = m,                    \
91                 .div            = d,                    \
92                 .flags          = f,                    \
93         }
94
95 /**
96  * struct samsung_mux_clock: information about mux clock
97  * @id: platform specific id of the clock.
98  * @dev_name: name of the device to which this clock belongs.
99  * @name: name of this mux clock.
100  * @parent_names: array of pointer to parent clock names.
101  * @num_parents: number of parents listed in @parent_names.
102  * @flags: optional flags for basic clock.
103  * @offset: offset of the register for configuring the mux.
104  * @shift: starting bit location of the mux control bit-field in @reg.
105  * @width: width of the mux control bit-field in @reg.
106  * @mux_flags: flags for mux-type clock.
107  * @alias: optional clock alias name to be assigned to this clock.
108  */
109 struct samsung_mux_clock {
110         unsigned int            id;
111         const char              *dev_name;
112         const char              *name;
113         const char              **parent_names;
114         u8                      num_parents;
115         unsigned long           flags;
116         unsigned long           offset;
117         u8                      shift;
118         u8                      width;
119         u8                      mux_flags;
120         const char              *alias;
121 };
122
123 #define __MUX(_id, dname, cname, pnames, o, s, w, f, mf, a)     \
124         {                                                       \
125                 .id             = _id,                          \
126                 .dev_name       = dname,                        \
127                 .name           = cname,                        \
128                 .parent_names   = pnames,                       \
129                 .num_parents    = ARRAY_SIZE(pnames),           \
130                 .flags          = f,                            \
131                 .offset         = o,                            \
132                 .shift          = s,                            \
133                 .width          = w,                            \
134                 .mux_flags      = mf,                           \
135                 .alias          = a,                            \
136         }
137
138 #define MUX(_id, cname, pnames, o, s, w)                        \
139         __MUX(_id, NULL, cname, pnames, o, s, w, 0, 0, NULL)
140
141 #define MUX_A(_id, cname, pnames, o, s, w, a)                   \
142         __MUX(_id, NULL, cname, pnames, o, s, w, 0, 0, a)
143
144 #define MUX_F(_id, cname, pnames, o, s, w, f, mf)               \
145         __MUX(_id, NULL, cname, pnames, o, s, w, f, mf, NULL)
146
147 /**
148  * @id: platform specific id of the clock.
149  * struct samsung_div_clock: information about div clock
150  * @dev_name: name of the device to which this clock belongs.
151  * @name: name of this div clock.
152  * @parent_name: name of the parent clock.
153  * @flags: optional flags for basic clock.
154  * @offset: offset of the register for configuring the div.
155  * @shift: starting bit location of the div control bit-field in @reg.
156  * @div_flags: flags for div-type clock.
157  * @alias: optional clock alias name to be assigned to this clock.
158  */
159 struct samsung_div_clock {
160         unsigned int            id;
161         const char              *dev_name;
162         const char              *name;
163         const char              *parent_name;
164         unsigned long           flags;
165         unsigned long           offset;
166         u8                      shift;
167         u8                      width;
168         u8                      div_flags;
169         const char              *alias;
170         struct clk_div_table    *table;
171 };
172
173 #define __DIV(_id, dname, cname, pname, o, s, w, f, df, a, t)   \
174         {                                                       \
175                 .id             = _id,                          \
176                 .dev_name       = dname,                        \
177                 .name           = cname,                        \
178                 .parent_name    = pname,                        \
179                 .flags          = f,                            \
180                 .offset         = o,                            \
181                 .shift          = s,                            \
182                 .width          = w,                            \
183                 .div_flags      = df,                           \
184                 .alias          = a,                            \
185                 .table          = t,                            \
186         }
187
188 #define DIV(_id, cname, pname, o, s, w)                         \
189         __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, NULL, NULL)
190
191 #define DIV_A(_id, cname, pname, o, s, w, a)                    \
192         __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, a, NULL)
193
194 #define DIV_F(_id, cname, pname, o, s, w, f, df)                \
195         __DIV(_id, NULL, cname, pname, o, s, w, f, df, NULL, NULL)
196
197 #define DIV_T(_id, cname, pname, o, s, w, t)                    \
198         __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, NULL, t)
199
200 /**
201  * struct samsung_gate_clock: information about gate clock
202  * @id: platform specific id of the clock.
203  * @dev_name: name of the device to which this clock belongs.
204  * @name: name of this gate clock.
205  * @parent_name: name of the parent clock.
206  * @flags: optional flags for basic clock.
207  * @offset: offset of the register for configuring the gate.
208  * @bit_idx: bit index of the gate control bit-field in @reg.
209  * @gate_flags: flags for gate-type clock.
210  * @alias: optional clock alias name to be assigned to this clock.
211  */
212 struct samsung_gate_clock {
213         unsigned int            id;
214         const char              *dev_name;
215         const char              *name;
216         const char              *parent_name;
217         unsigned long           flags;
218         unsigned long           offset;
219         u8                      bit_idx;
220         u8                      gate_flags;
221         const char              *alias;
222 };
223
224 #define __GATE(_id, dname, cname, pname, o, b, f, gf, a)        \
225         {                                                       \
226                 .id             = _id,                          \
227                 .dev_name       = dname,                        \
228                 .name           = cname,                        \
229                 .parent_name    = pname,                        \
230                 .flags          = f,                            \
231                 .offset         = o,                            \
232                 .bit_idx        = b,                            \
233                 .gate_flags     = gf,                           \
234                 .alias          = a,                            \
235         }
236
237 #define GATE(_id, cname, pname, o, b, f, gf)                    \
238         __GATE(_id, NULL, cname, pname, o, b, f, gf, NULL)
239
240 #define GATE_A(_id, cname, pname, o, b, f, gf, a)               \
241         __GATE(_id, NULL, cname, pname, o, b, f, gf, a)
242
243 #define GATE_D(_id, dname, cname, pname, o, b, f, gf)           \
244         __GATE(_id, dname, cname, pname, o, b, f, gf, NULL)
245
246 #define GATE_DA(_id, dname, cname, pname, o, b, f, gf, a)       \
247         __GATE(_id, dname, cname, pname, o, b, f, gf, a)
248
249 #define PNAME(x) static const char *x[] __initdata
250
251 /**
252  * struct samsung_clk_reg_dump: register dump of clock controller registers.
253  * @offset: clock register offset from the controller base address.
254  * @value: the value to be register at offset.
255  */
256 struct samsung_clk_reg_dump {
257         u32     offset;
258         u32     value;
259 };
260
261 extern void __init samsung_clk_init(struct device_node *np, void __iomem *base,
262                 unsigned long nr_clks, unsigned long *rdump,
263                 unsigned long nr_rdump, unsigned long *soc_rdump,
264                 unsigned long nr_soc_rdump);
265 extern void __init samsung_clk_of_register_fixed_ext(
266                 struct samsung_fixed_rate_clock *fixed_rate_clk,
267                 unsigned int nr_fixed_rate_clk,
268                 struct of_device_id *clk_matches);
269
270 extern void samsung_clk_add_lookup(struct clk *clk, unsigned int id);
271
272 extern void samsung_clk_register_alias(struct samsung_clock_alias *list,
273                 unsigned int nr_clk);
274 extern void __init samsung_clk_register_fixed_rate(
275                 struct samsung_fixed_rate_clock *clk_list, unsigned int nr_clk);
276 extern void __init samsung_clk_register_fixed_factor(
277                 struct samsung_fixed_factor_clock *list, unsigned int nr_clk);
278 extern void __init samsung_clk_register_mux(struct samsung_mux_clock *clk_list,
279                 unsigned int nr_clk);
280 extern void __init samsung_clk_register_div(struct samsung_div_clock *clk_list,
281                 unsigned int nr_clk);
282 extern void __init samsung_clk_register_gate(
283                 struct samsung_gate_clock *clk_list, unsigned int nr_clk);
284
285 extern unsigned long _get_rate(const char *clk_name);
286
287 #endif /* __SAMSUNG_CLK_H */