2 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
3 * Copyright (c) 2013 Linaro Ltd.
4 * Author: Thomas Abraham <thomas.ab@samsung.com>
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.
10 * Common Clock Framework support for all Samsung platforms
13 #ifndef __SAMSUNG_CLK_H
14 #define __SAMSUNG_CLK_H
16 #include <linux/clk-provider.h>
20 * struct samsung_clk_provider: information about clock provider
21 * @reg_base: virtual address for the register base.
22 * @lock: maintains exclusion between callbacks for a given clock-provider.
23 * @clk_data: holds clock related data like clk_hw* and number of clocks.
25 struct samsung_clk_provider
{
26 void __iomem
*reg_base
;
29 /* clk_data must be the last entry due to variable lenght 'hws' array */
30 struct clk_hw_onecell_data clk_data
;
34 * struct samsung_clock_alias: information about mux clock
35 * @id: platform specific id of the clock.
36 * @dev_name: name of the device to which this clock belongs.
37 * @alias: optional clock alias name to be assigned to this clock.
39 struct samsung_clock_alias
{
45 #define ALIAS(_id, dname, a) \
52 #define MHZ (1000 * 1000)
55 * struct samsung_fixed_rate_clock: information about fixed-rate clock
56 * @id: platform specific id of the clock.
57 * @name: name of this fixed-rate clock.
58 * @parent_name: optional parent clock name.
59 * @flags: optional fixed-rate clock flags.
60 * @fixed-rate: fixed clock rate of this clock.
62 struct samsung_fixed_rate_clock
{
65 const char *parent_name
;
67 unsigned long fixed_rate
;
70 #define FRATE(_id, cname, pname, f, frate) \
74 .parent_name = pname, \
76 .fixed_rate = frate, \
80 * struct samsung_fixed_factor_clock: information about fixed-factor clock
81 * @id: platform specific id of the clock.
82 * @name: name of this fixed-factor clock.
83 * @parent_name: parent clock name.
84 * @mult: fixed multiplication factor.
85 * @div: fixed division factor.
86 * @flags: optional fixed-factor clock flags.
88 struct samsung_fixed_factor_clock
{
91 const char *parent_name
;
97 #define FFACTOR(_id, cname, pname, m, d, f) \
101 .parent_name = pname, \
108 * struct samsung_mux_clock: information about mux clock
109 * @id: platform specific id of the clock.
110 * @name: name of this mux clock.
111 * @parent_names: array of pointer to parent clock names.
112 * @num_parents: number of parents listed in @parent_names.
113 * @flags: optional flags for basic clock.
114 * @offset: offset of the register for configuring the mux.
115 * @shift: starting bit location of the mux control bit-field in @reg.
116 * @width: width of the mux control bit-field in @reg.
117 * @mux_flags: flags for mux-type clock.
119 struct samsung_mux_clock
{
122 const char *const *parent_names
;
125 unsigned long offset
;
131 #define __MUX(_id, cname, pnames, o, s, w, f, mf) \
135 .parent_names = pnames, \
136 .num_parents = ARRAY_SIZE(pnames), \
137 .flags = (f) | CLK_SET_RATE_NO_REPARENT, \
144 #define MUX(_id, cname, pnames, o, s, w) \
145 __MUX(_id, cname, pnames, o, s, w, 0, 0)
147 #define MUX_F(_id, cname, pnames, o, s, w, f, mf) \
148 __MUX(_id, cname, pnames, o, s, w, f, mf)
151 * @id: platform specific id of the clock.
152 * struct samsung_div_clock: information about div clock
153 * @name: name of this div clock.
154 * @parent_name: name of the parent clock.
155 * @flags: optional flags for basic clock.
156 * @offset: offset of the register for configuring the div.
157 * @shift: starting bit location of the div control bit-field in @reg.
158 * @div_flags: flags for div-type clock.
160 struct samsung_div_clock
{
163 const char *parent_name
;
165 unsigned long offset
;
169 struct clk_div_table
*table
;
172 #define __DIV(_id, cname, pname, o, s, w, f, df, t) \
176 .parent_name = pname, \
185 #define DIV(_id, cname, pname, o, s, w) \
186 __DIV(_id, cname, pname, o, s, w, 0, 0, NULL)
188 #define DIV_F(_id, cname, pname, o, s, w, f, df) \
189 __DIV(_id, cname, pname, o, s, w, f, df, NULL)
191 #define DIV_T(_id, cname, pname, o, s, w, t) \
192 __DIV(_id, cname, pname, o, s, w, 0, 0, t)
195 * struct samsung_gate_clock: information about gate clock
196 * @id: platform specific id of the clock.
197 * @name: name of this gate clock.
198 * @parent_name: name of the parent clock.
199 * @flags: optional flags for basic clock.
200 * @offset: offset of the register for configuring the gate.
201 * @bit_idx: bit index of the gate control bit-field in @reg.
202 * @gate_flags: flags for gate-type clock.
204 struct samsung_gate_clock
{
207 const char *parent_name
;
209 unsigned long offset
;
214 #define __GATE(_id, cname, pname, o, b, f, gf) \
218 .parent_name = pname, \
225 #define GATE(_id, cname, pname, o, b, f, gf) \
226 __GATE(_id, cname, pname, o, b, f, gf)
228 #define PNAME(x) static const char * const x[] __initconst
231 * struct samsung_clk_reg_dump: register dump of clock controller registers.
232 * @offset: clock register offset from the controller base address.
233 * @value: the value to be register at offset.
235 struct samsung_clk_reg_dump
{
241 * struct samsung_pll_clock: information about pll clock
242 * @id: platform specific id of the clock.
243 * @name: name of this pll clock.
244 * @parent_name: name of the parent clock.
245 * @flags: optional flags for basic clock.
246 * @con_offset: offset of the register for configuring the PLL.
247 * @lock_offset: offset of the register for locking the PLL.
248 * @type: Type of PLL to be registered.
250 struct samsung_pll_clock
{
253 const char *parent_name
;
257 enum samsung_pll_type type
;
258 const struct samsung_pll_rate_table
*rate_table
;
261 #define __PLL(_typ, _id, _name, _pname, _flags, _lock, _con, _rtable) \
266 .parent_name = _pname, \
268 .con_offset = _con, \
269 .lock_offset = _lock, \
270 .rate_table = _rtable, \
273 #define PLL(_typ, _id, _name, _pname, _lock, _con, _rtable) \
274 __PLL(_typ, _id, _name, _pname, CLK_GET_RATE_NOCACHE, _lock, \
277 struct samsung_clock_reg_cache
{
278 struct list_head node
;
279 void __iomem
*reg_base
;
280 struct samsung_clk_reg_dump
*rdump
;
282 const struct samsung_clk_reg_dump
*rsuspend
;
283 unsigned int rsuspend_num
;
286 struct samsung_cmu_info
{
287 /* list of pll clocks and respective count */
288 const struct samsung_pll_clock
*pll_clks
;
289 unsigned int nr_pll_clks
;
290 /* list of mux clocks and respective count */
291 const struct samsung_mux_clock
*mux_clks
;
292 unsigned int nr_mux_clks
;
293 /* list of div clocks and respective count */
294 const struct samsung_div_clock
*div_clks
;
295 unsigned int nr_div_clks
;
296 /* list of gate clocks and respective count */
297 const struct samsung_gate_clock
*gate_clks
;
298 unsigned int nr_gate_clks
;
299 /* list of fixed clocks and respective count */
300 const struct samsung_fixed_rate_clock
*fixed_clks
;
301 unsigned int nr_fixed_clks
;
302 /* list of fixed factor clocks and respective count */
303 const struct samsung_fixed_factor_clock
*fixed_factor_clks
;
304 unsigned int nr_fixed_factor_clks
;
305 /* total number of clocks with IDs assigned*/
306 unsigned int nr_clk_ids
;
308 /* list and number of clocks registers */
309 const unsigned long *clk_regs
;
310 unsigned int nr_clk_regs
;
312 /* list and number of clocks registers to set before suspend */
313 const struct samsung_clk_reg_dump
*suspend_regs
;
314 unsigned int nr_suspend_regs
;
315 /* name of the parent clock needed for CMU register access */
316 const char *clk_name
;
319 extern struct samsung_clk_provider
*__init
samsung_clk_init(
320 struct device_node
*np
, void __iomem
*base
,
321 unsigned long nr_clks
);
322 extern void __init
samsung_clk_of_add_provider(struct device_node
*np
,
323 struct samsung_clk_provider
*ctx
);
324 extern void __init
samsung_clk_of_register_fixed_ext(
325 struct samsung_clk_provider
*ctx
,
326 struct samsung_fixed_rate_clock
*fixed_rate_clk
,
327 unsigned int nr_fixed_rate_clk
,
328 const struct of_device_id
*clk_matches
);
330 extern void samsung_clk_add_lookup(struct samsung_clk_provider
*ctx
,
331 struct clk_hw
*clk_hw
, unsigned int id
);
333 extern void __init
samsung_clk_register_alias(struct samsung_clk_provider
*ctx
,
334 const struct samsung_clock_alias
*list
,
335 unsigned int nr_clk
);
336 extern void __init
samsung_clk_register_fixed_rate(
337 struct samsung_clk_provider
*ctx
,
338 const struct samsung_fixed_rate_clock
*clk_list
,
339 unsigned int nr_clk
);
340 extern void __init
samsung_clk_register_fixed_factor(
341 struct samsung_clk_provider
*ctx
,
342 const struct samsung_fixed_factor_clock
*list
,
343 unsigned int nr_clk
);
344 extern void __init
samsung_clk_register_mux(struct samsung_clk_provider
*ctx
,
345 const struct samsung_mux_clock
*clk_list
,
346 unsigned int nr_clk
);
347 extern void __init
samsung_clk_register_div(struct samsung_clk_provider
*ctx
,
348 const struct samsung_div_clock
*clk_list
,
349 unsigned int nr_clk
);
350 extern void __init
samsung_clk_register_gate(struct samsung_clk_provider
*ctx
,
351 const struct samsung_gate_clock
*clk_list
,
352 unsigned int nr_clk
);
353 extern void __init
samsung_clk_register_pll(struct samsung_clk_provider
*ctx
,
354 const struct samsung_pll_clock
*pll_list
,
355 unsigned int nr_clk
, void __iomem
*base
);
357 extern struct samsung_clk_provider __init
*samsung_cmu_register_one(
358 struct device_node
*,
359 const struct samsung_cmu_info
*);
361 extern unsigned long _get_rate(const char *clk_name
);
363 #ifdef CONFIG_PM_SLEEP
364 extern void samsung_clk_extended_sleep_init(void __iomem
*reg_base
,
365 const unsigned long *rdump
,
366 unsigned long nr_rdump
,
367 const struct samsung_clk_reg_dump
*rsuspend
,
368 unsigned long nr_rsuspend
);
370 static inline void samsung_clk_extended_sleep_init(void __iomem
*reg_base
,
371 const unsigned long *rdump
,
372 unsigned long nr_rdump
,
373 const struct samsung_clk_reg_dump
*rsuspend
,
374 unsigned long nr_rsuspend
) {}
376 #define samsung_clk_sleep_init(reg_base, rdump, nr_rdump) \
377 samsung_clk_extended_sleep_init(reg_base, rdump, nr_rdump, NULL, 0)
379 extern void samsung_clk_save(void __iomem
*base
,
380 struct samsung_clk_reg_dump
*rd
,
381 unsigned int num_regs
);
382 extern void samsung_clk_restore(void __iomem
*base
,
383 const struct samsung_clk_reg_dump
*rd
,
384 unsigned int num_regs
);
385 extern struct samsung_clk_reg_dump
*samsung_clk_alloc_reg_dump(
386 const unsigned long *rdump
,
387 unsigned long nr_rdump
);
389 #endif /* __SAMSUNG_CLK_H */