blob: 26a752b18f88c27092ceced42f3ee70b58dd67b8 [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;
Heiko Stuebner798ed612013-03-18 13:43:52 +0900153 struct clk_div_table *table;
Thomas Abraham721c42a2013-03-09 17:02:44 +0900154};
155
Heiko Stuebner798ed612013-03-18 13:43:52 +0900156#define __DIV(_id, dname, cname, pname, o, s, w, f, df, a, t) \
Thomas Abraham721c42a2013-03-09 17:02:44 +0900157 { \
158 .id = _id, \
159 .dev_name = dname, \
160 .name = cname, \
161 .parent_name = pname, \
162 .flags = f, \
163 .offset = o, \
164 .shift = s, \
165 .width = w, \
166 .div_flags = df, \
167 .alias = a, \
Heiko Stuebner798ed612013-03-18 13:43:52 +0900168 .table = t, \
Thomas Abraham721c42a2013-03-09 17:02:44 +0900169 }
170
171#define DIV(_id, cname, pname, o, s, w) \
Heiko Stuebner798ed612013-03-18 13:43:52 +0900172 __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, NULL, NULL)
Thomas Abraham721c42a2013-03-09 17:02:44 +0900173
174#define DIV_A(_id, cname, pname, o, s, w, a) \
Heiko Stuebner798ed612013-03-18 13:43:52 +0900175 __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, a, NULL)
Thomas Abraham721c42a2013-03-09 17:02:44 +0900176
177#define DIV_F(_id, cname, pname, o, s, w, f, df) \
Heiko Stuebner798ed612013-03-18 13:43:52 +0900178 __DIV(_id, NULL, cname, pname, o, s, w, f, df, NULL, NULL)
179
180#define DIV_T(_id, cname, pname, o, s, w, t) \
181 __DIV(_id, NULL, cname, pname, o, s, w, 0, 0, NULL, t)
Thomas Abraham721c42a2013-03-09 17:02:44 +0900182
183/**
184 * struct samsung_gate_clock: information about gate clock
185 * @id: platform specific id of the clock.
186 * @dev_name: name of the device to which this clock belongs.
187 * @name: name of this gate clock.
188 * @parent_name: name of the parent clock.
189 * @flags: optional flags for basic clock.
190 * @offset: offset of the register for configuring the gate.
191 * @bit_idx: bit index of the gate control bit-field in @reg.
192 * @gate_flags: flags for gate-type clock.
193 * @alias: optional clock alias name to be assigned to this clock.
194 */
195struct samsung_gate_clock {
196 unsigned int id;
197 const char *dev_name;
198 const char *name;
199 const char *parent_name;
200 unsigned long flags;
201 unsigned long offset;
202 u8 bit_idx;
203 u8 gate_flags;
204 const char *alias;
205};
206
207#define __GATE(_id, dname, cname, pname, o, b, f, gf, a) \
208 { \
209 .id = _id, \
210 .dev_name = dname, \
211 .name = cname, \
212 .parent_name = pname, \
213 .flags = f, \
214 .offset = o, \
215 .bit_idx = b, \
216 .gate_flags = gf, \
217 .alias = a, \
218 }
219
220#define GATE(_id, cname, pname, o, b, f, gf) \
221 __GATE(_id, NULL, cname, pname, o, b, f, gf, NULL)
222
223#define GATE_A(_id, cname, pname, o, b, f, gf, a) \
224 __GATE(_id, NULL, cname, pname, o, b, f, gf, a)
225
226#define GATE_D(_id, dname, cname, pname, o, b, f, gf) \
227 __GATE(_id, dname, cname, pname, o, b, f, gf, NULL)
228
229#define GATE_DA(_id, dname, cname, pname, o, b, f, gf, a) \
230 __GATE(_id, dname, cname, pname, o, b, f, gf, a)
231
232#define PNAME(x) static const char *x[] __initdata
233
234/**
235 * struct samsung_clk_reg_dump: register dump of clock controller registers.
236 * @offset: clock register offset from the controller base address.
237 * @value: the value to be register at offset.
238 */
239struct samsung_clk_reg_dump {
240 u32 offset;
241 u32 value;
242};
243
244extern void __init samsung_clk_init(struct device_node *np, void __iomem *base,
245 unsigned long nr_clks, unsigned long *rdump,
246 unsigned long nr_rdump);
247extern void __init samsung_clk_of_register_fixed_ext(
248 struct samsung_fixed_rate_clock *fixed_rate_clk,
249 unsigned int nr_fixed_rate_clk,
250 struct of_device_id *clk_matches);
251
252extern void samsung_clk_add_lookup(struct clk *clk, unsigned int id);
253
254extern void __init samsung_clk_register_fixed_rate(
255 struct samsung_fixed_rate_clock *clk_list, unsigned int nr_clk);
256extern void __init samsung_clk_register_fixed_factor(
257 struct samsung_fixed_factor_clock *list, unsigned int nr_clk);
258extern void __init samsung_clk_register_mux(struct samsung_mux_clock *clk_list,
259 unsigned int nr_clk);
260extern void __init samsung_clk_register_div(struct samsung_div_clock *clk_list,
261 unsigned int nr_clk);
262extern void __init samsung_clk_register_gate(
263 struct samsung_gate_clock *clk_list, unsigned int nr_clk);
264
265extern unsigned long _get_rate(const char *clk_name);
266
267#endif /* __SAMSUNG_CLK_H */