blob: 961192ffd69636a1d5f4ded0fd9740f0fb02dbf2 [file] [log] [blame]
Thomas Abraham721c42a2013-03-09 17:02:44 +09001/*
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#include <mach/map.h>
24
25/**
26 * struct samsung_fixed_rate_clock: information about fixed-rate clock
27 * @id: platform specific id of the clock.
28 * @name: name of this fixed-rate clock.
29 * @parent_name: optional parent clock name.
30 * @flags: optional fixed-rate clock flags.
31 * @fixed-rate: fixed clock rate of this clock.
32 */
33struct samsung_fixed_rate_clock {
34 unsigned int id;
35 char *name;
36 const char *parent_name;
37 unsigned long flags;
38 unsigned long fixed_rate;
39};
40
41#define FRATE(_id, cname, pname, f, frate) \
42 { \
43 .id = _id, \
44 .name = cname, \
45 .parent_name = pname, \
46 .flags = f, \
47 .fixed_rate = frate, \
48 }
49
50/*
51 * struct samsung_fixed_factor_clock: information about fixed-factor clock
52 * @id: platform specific id of the clock.
53 * @name: name of this fixed-factor clock.
54 * @parent_name: parent clock name.
55 * @mult: fixed multiplication factor.
56 * @div: fixed division factor.
57 * @flags: optional fixed-factor clock flags.
58 */
59struct samsung_fixed_factor_clock {
60 unsigned int id;
61 char *name;
62 const char *parent_name;
63 unsigned long mult;
64 unsigned long div;
65 unsigned long flags;
66};
67
68#define FFACTOR(_id, cname, pname, m, d, f) \
69 { \
70 .id = _id, \
71 .name = cname, \
72 .parent_name = pname, \
73 .mult = m, \
74 .div = d, \
75 .flags = f, \
76 }
77
78/**
79 * struct samsung_mux_clock: information about mux clock
80 * @id: platform specific id of the clock.
81 * @dev_name: name of the device to which this clock belongs.
82 * @name: name of this mux clock.
83 * @parent_names: array of pointer to parent clock names.
84 * @num_parents: number of parents listed in @parent_names.
85 * @flags: optional flags for basic clock.
86 * @offset: offset of the register for configuring the mux.
87 * @shift: starting bit location of the mux control bit-field in @reg.
88 * @width: width of the mux control bit-field in @reg.
89 * @mux_flags: flags for mux-type clock.
90 * @alias: optional clock alias name to be assigned to this clock.
91 */
92struct samsung_mux_clock {
93 unsigned int id;
94 const char *dev_name;
95 const char *name;
96 const char **parent_names;
97 u8 num_parents;
98 unsigned long flags;
99 unsigned long offset;
100 u8 shift;
101 u8 width;
102 u8 mux_flags;
103 const char *alias;
104};
105
106#define __MUX(_id, dname, cname, pnames, o, s, w, f, mf, a) \
107 { \
108 .id = _id, \
109 .dev_name = dname, \
110 .name = cname, \
111 .parent_names = pnames, \
112 .num_parents = ARRAY_SIZE(pnames), \
113 .flags = f, \
114 .offset = o, \
115 .shift = s, \
116 .width = w, \
117 .mux_flags = mf, \
118 .alias = a, \
119 }
120
121#define MUX(_id, cname, pnames, o, s, w) \
122 __MUX(_id, NULL, cname, pnames, o, s, w, 0, 0, NULL)
123
124#define MUX_A(_id, cname, pnames, o, s, w, a) \
125 __MUX(_id, NULL, cname, pnames, o, s, w, 0, 0, a)
126
127#define MUX_F(_id, cname, pnames, o, s, w, f, mf) \
128 __MUX(_id, NULL, cname, pnames, o, s, w, f, mf, NULL)
129
130/**
131 * @id: platform specific id of the clock.
132 * struct samsung_div_clock: information about div clock
133 * @dev_name: name of the device to which this clock belongs.
134 * @name: name of this div clock.
135 * @parent_name: name of the parent clock.
136 * @flags: optional flags for basic clock.
137 * @offset: offset of the register for configuring the div.
138 * @shift: starting bit location of the div control bit-field in @reg.
139 * @div_flags: flags for div-type clock.
140 * @alias: optional clock alias name to be assigned to this clock.
141 */
142struct samsung_div_clock {
143 unsigned int id;
144 const char *dev_name;
145 const char *name;
146 const char *parent_name;
147 unsigned long flags;
148 unsigned long offset;
149 u8 shift;
150 u8 width;
151 u8 div_flags;
152 const char *alias;
153};
154
155#define __DIV(_id, dname, cname, pname, o, s, w, f, df, a) \
156 { \
157 .id = _id, \
158 .dev_name = dname, \
159 .name = cname, \
160 .parent_name = pname, \
161 .flags = f, \
162 .offset = o, \
163 .shift = s, \
164 .width = w, \
165 .div_flags = df, \
166 .alias = a, \
167 }
168
169#define DIV(_id, cname, pname, o, s, w) \
170 __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, NULL)
171
172#define DIV_A(_id, cname, pname, o, s, w, a) \
173 __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, a)
174
175#define DIV_F(_id, cname, pname, o, s, w, f, df) \
176 __DIV(_id, NULL, cname, pname, o, s, w, f, df, NULL)
177
178/**
179 * struct samsung_gate_clock: information about gate clock
180 * @id: platform specific id of the clock.
181 * @dev_name: name of the device to which this clock belongs.
182 * @name: name of this gate clock.
183 * @parent_name: name of the parent clock.
184 * @flags: optional flags for basic clock.
185 * @offset: offset of the register for configuring the gate.
186 * @bit_idx: bit index of the gate control bit-field in @reg.
187 * @gate_flags: flags for gate-type clock.
188 * @alias: optional clock alias name to be assigned to this clock.
189 */
190struct samsung_gate_clock {
191 unsigned int id;
192 const char *dev_name;
193 const char *name;
194 const char *parent_name;
195 unsigned long flags;
196 unsigned long offset;
197 u8 bit_idx;
198 u8 gate_flags;
199 const char *alias;
200};
201
202#define __GATE(_id, dname, cname, pname, o, b, f, gf, a) \
203 { \
204 .id = _id, \
205 .dev_name = dname, \
206 .name = cname, \
207 .parent_name = pname, \
208 .flags = f, \
209 .offset = o, \
210 .bit_idx = b, \
211 .gate_flags = gf, \
212 .alias = a, \
213 }
214
215#define GATE(_id, cname, pname, o, b, f, gf) \
216 __GATE(_id, NULL, cname, pname, o, b, f, gf, NULL)
217
218#define GATE_A(_id, cname, pname, o, b, f, gf, a) \
219 __GATE(_id, NULL, cname, pname, o, b, f, gf, a)
220
221#define GATE_D(_id, dname, cname, pname, o, b, f, gf) \
222 __GATE(_id, dname, cname, pname, o, b, f, gf, NULL)
223
224#define GATE_DA(_id, dname, cname, pname, o, b, f, gf, a) \
225 __GATE(_id, dname, cname, pname, o, b, f, gf, a)
226
227#define PNAME(x) static const char *x[] __initdata
228
229/**
230 * struct samsung_clk_reg_dump: register dump of clock controller registers.
231 * @offset: clock register offset from the controller base address.
232 * @value: the value to be register at offset.
233 */
234struct samsung_clk_reg_dump {
235 u32 offset;
236 u32 value;
237};
238
239extern void __init samsung_clk_init(struct device_node *np, void __iomem *base,
240 unsigned long nr_clks, unsigned long *rdump,
241 unsigned long nr_rdump);
242extern void __init samsung_clk_of_register_fixed_ext(
243 struct samsung_fixed_rate_clock *fixed_rate_clk,
244 unsigned int nr_fixed_rate_clk,
245 struct of_device_id *clk_matches);
246
247extern void samsung_clk_add_lookup(struct clk *clk, unsigned int id);
248
249extern void __init samsung_clk_register_fixed_rate(
250 struct samsung_fixed_rate_clock *clk_list, unsigned int nr_clk);
251extern void __init samsung_clk_register_fixed_factor(
252 struct samsung_fixed_factor_clock *list, unsigned int nr_clk);
253extern void __init samsung_clk_register_mux(struct samsung_mux_clock *clk_list,
254 unsigned int nr_clk);
255extern void __init samsung_clk_register_div(struct samsung_div_clock *clk_list,
256 unsigned int nr_clk);
257extern void __init samsung_clk_register_gate(
258 struct samsung_gate_clock *clk_list, unsigned int nr_clk);
259
260extern unsigned long _get_rate(const char *clk_name);
261
262#endif /* __SAMSUNG_CLK_H */