1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 * Copyright (c) 2013 Linaro Ltd.
5 * Author: Thomas Abraham <thomas.ab@samsung.com>
7 * Common Clock Framework support for all Samsung platforms
10 #ifndef __SAMSUNG_CLK_H
11 #define __SAMSUNG_CLK_H
13 #include <linux/clk-provider.h>
18 * struct samsung_clk_provider - information about clock provider
19 * @reg_base: virtual address for the register base
20 * @dev: clock provider device needed for runtime PM
21 * @lock: maintains exclusion between callbacks for a given clock-provider
22 * @clk_data: holds clock related data like clk_hw* and number of clocks
24 struct samsung_clk_provider
{
25 void __iomem
*reg_base
;
28 /* clk_data must be the last entry due to variable length 'hws' array */
29 struct clk_hw_onecell_data clk_data
;
33 * struct samsung_clock_alias - information about mux clock
34 * @id: platform specific id of the clock
35 * @dev_name: name of the device to which this clock belongs
36 * @alias: optional clock alias name to be assigned to this clock
38 struct samsung_clock_alias
{
44 #define ALIAS(_id, dname, a) \
51 #define MHZ (1000 * 1000)
54 * struct samsung_fixed_rate_clock - information about fixed-rate clock
55 * @id: platform specific id of the clock
56 * @name: name of this fixed-rate clock
57 * @parent_name: optional parent clock name
58 * @flags: optional fixed-rate clock flags
59 * @fixed_rate: fixed clock rate of this clock
61 struct samsung_fixed_rate_clock
{
64 const char *parent_name
;
66 unsigned long fixed_rate
;
69 #define FRATE(_id, cname, pname, f, frate) \
73 .parent_name = pname, \
75 .fixed_rate = frate, \
79 * struct samsung_fixed_factor_clock - information about fixed-factor clock
80 * @id: platform specific id of the clock
81 * @name: name of this fixed-factor clock
82 * @parent_name: parent clock name
83 * @mult: fixed multiplication factor
84 * @div: fixed division factor
85 * @flags: optional fixed-factor clock flags
87 struct samsung_fixed_factor_clock
{
90 const char *parent_name
;
96 #define FFACTOR(_id, cname, pname, m, d, f) \
100 .parent_name = pname, \
107 * struct samsung_mux_clock - information about mux clock
108 * @id: platform specific id of the clock
109 * @name: name of this mux clock
110 * @parent_names: array of pointer to parent clock names
111 * @num_parents: number of parents listed in @parent_names
112 * @flags: optional flags for basic clock
113 * @offset: offset of the register for configuring the mux
114 * @shift: starting bit location of the mux control bit-field in @reg
115 * @width: width of the mux control bit-field in @reg
116 * @mux_flags: flags for mux-type clock
118 struct samsung_mux_clock
{
121 const char *const *parent_names
;
124 unsigned long offset
;
130 #define __MUX(_id, cname, pnames, o, s, w, f, mf) \
134 .parent_names = pnames, \
135 .num_parents = ARRAY_SIZE(pnames), \
143 #define MUX(_id, cname, pnames, o, s, w) \
144 __MUX(_id, cname, pnames, o, s, w, CLK_SET_RATE_NO_REPARENT, 0)
146 #define MUX_F(_id, cname, pnames, o, s, w, f, mf) \
147 __MUX(_id, cname, pnames, o, s, w, (f) | CLK_SET_RATE_NO_REPARENT, mf)
149 /* Used by MUX clocks where reparenting on clock rate change is allowed. */
150 #define nMUX(_id, cname, pnames, o, s, w) \
151 __MUX(_id, cname, pnames, o, s, w, 0, 0)
153 #define nMUX_F(_id, cname, pnames, o, s, w, f, mf) \
154 __MUX(_id, cname, pnames, o, s, w, f, mf)
157 * struct samsung_div_clock - information about div clock
158 * @id: platform specific id of the clock
159 * @name: name of this div clock
160 * @parent_name: name of the parent clock
161 * @flags: optional flags for basic clock
162 * @offset: offset of the register for configuring the div
163 * @shift: starting bit location of the div control bit-field in @reg
164 * @width: width of the bitfield
165 * @div_flags: flags for div-type clock
166 * @table: array of divider/value pairs ending with a div set to 0
168 struct samsung_div_clock
{
171 const char *parent_name
;
173 unsigned long offset
;
177 struct clk_div_table
*table
;
180 #define __DIV(_id, cname, pname, o, s, w, f, df, t) \
184 .parent_name = pname, \
193 #define DIV(_id, cname, pname, o, s, w) \
194 __DIV(_id, cname, pname, o, s, w, 0, 0, NULL)
196 #define DIV_F(_id, cname, pname, o, s, w, f, df) \
197 __DIV(_id, cname, pname, o, s, w, f, df, NULL)
199 #define DIV_T(_id, cname, pname, o, s, w, t) \
200 __DIV(_id, cname, pname, o, s, w, 0, 0, t)
203 * struct samsung_gate_clock - information about gate clock
204 * @id: platform specific id of the clock
205 * @name: name of this gate clock
206 * @parent_name: name of the parent clock
207 * @flags: optional flags for basic clock
208 * @offset: offset of the register for configuring the gate
209 * @bit_idx: bit index of the gate control bit-field in @reg
210 * @gate_flags: flags for gate-type clock
212 struct samsung_gate_clock
{
215 const char *parent_name
;
217 unsigned long offset
;
222 #define __GATE(_id, cname, pname, o, b, f, gf) \
226 .parent_name = pname, \
233 #define GATE(_id, cname, pname, o, b, f, gf) \
234 __GATE(_id, cname, pname, o, b, f, gf)
236 #define PNAME(x) static const char * const x[] __initconst
239 * struct samsung_clk_reg_dump - register dump of clock controller registers
240 * @offset: clock register offset from the controller base address
241 * @value: the value to be register at offset
243 struct samsung_clk_reg_dump
{
249 * struct samsung_pll_clock - information about pll clock
250 * @id: platform specific id of the clock
251 * @name: name of this pll clock
252 * @parent_name: name of the parent clock
253 * @flags: optional flags for basic clock
254 * @con_offset: offset of the register for configuring the PLL
255 * @lock_offset: offset of the register for locking the PLL
256 * @type: type of PLL to be registered
257 * @rate_table: array of PLL settings for possible PLL rates
259 struct samsung_pll_clock
{
262 const char *parent_name
;
266 enum samsung_pll_type type
;
267 const struct samsung_pll_rate_table
*rate_table
;
270 #define __PLL(_typ, _id, _name, _pname, _flags, _lock, _con, _rtable) \
275 .parent_name = _pname, \
277 .con_offset = _con, \
278 .lock_offset = _lock, \
279 .rate_table = _rtable, \
282 #define PLL(_typ, _id, _name, _pname, _lock, _con, _rtable) \
283 __PLL(_typ, _id, _name, _pname, CLK_GET_RATE_NOCACHE, _lock, \
286 struct samsung_cpu_clock
{
289 unsigned int parent_id
;
290 unsigned int alt_parent_id
;
293 enum exynos_cpuclk_layout reg_layout
;
294 const struct exynos_cpuclk_cfg_data
*cfg
;
297 #define CPU_CLK(_id, _name, _pid, _apid, _flags, _offset, _layout, _cfg) \
302 .alt_parent_id = _apid, \
305 .reg_layout = _layout, \
309 struct samsung_clock_reg_cache
{
310 struct list_head node
;
311 void __iomem
*reg_base
;
312 struct samsung_clk_reg_dump
*rdump
;
314 const struct samsung_clk_reg_dump
*rsuspend
;
315 unsigned int rsuspend_num
;
319 * struct samsung_cmu_info - all clocks information needed for CMU registration
320 * @pll_clks: list of PLL clocks
321 * @nr_pll_clks: count of clocks in @pll_clks
322 * @mux_clks: list of mux clocks
323 * @nr_mux_clks: count of clocks in @mux_clks
324 * @div_clks: list of div clocks
325 * @nr_div_clks: count of clocks in @div_clks
326 * @gate_clks: list of gate clocks
327 * @nr_gate_clks: count of clocks in @gate_clks
328 * @fixed_clks: list of fixed clocks
329 * @nr_fixed_clks: count clocks in @fixed_clks
330 * @fixed_factor_clks: list of fixed factor clocks
331 * @nr_fixed_factor_clks: count of clocks in @fixed_factor_clks
332 * @nr_clk_ids: total number of clocks with IDs assigned
333 * @cpu_clks: list of CPU clocks
334 * @nr_cpu_clks: count of clocks in @cpu_clks
335 * @clk_regs: list of clock registers
336 * @nr_clk_regs: count of clock registers in @clk_regs
337 * @suspend_regs: list of clock registers to set before suspend
338 * @nr_suspend_regs: count of clock registers in @suspend_regs
339 * @clk_name: name of the parent clock needed for CMU register access
340 * @manual_plls: Enable manual control for PLL clocks
342 struct samsung_cmu_info
{
343 const struct samsung_pll_clock
*pll_clks
;
344 unsigned int nr_pll_clks
;
345 const struct samsung_mux_clock
*mux_clks
;
346 unsigned int nr_mux_clks
;
347 const struct samsung_div_clock
*div_clks
;
348 unsigned int nr_div_clks
;
349 const struct samsung_gate_clock
*gate_clks
;
350 unsigned int nr_gate_clks
;
351 const struct samsung_fixed_rate_clock
*fixed_clks
;
352 unsigned int nr_fixed_clks
;
353 const struct samsung_fixed_factor_clock
*fixed_factor_clks
;
354 unsigned int nr_fixed_factor_clks
;
355 unsigned int nr_clk_ids
;
356 const struct samsung_cpu_clock
*cpu_clks
;
357 unsigned int nr_cpu_clks
;
359 const unsigned long *clk_regs
;
360 unsigned int nr_clk_regs
;
362 const struct samsung_clk_reg_dump
*suspend_regs
;
363 unsigned int nr_suspend_regs
;
364 const char *clk_name
;
366 /* ARM64 Exynos CMUs */
370 struct samsung_clk_provider
*samsung_clk_init(struct device
*dev
,
371 void __iomem
*base
, unsigned long nr_clks
);
372 void samsung_clk_of_add_provider(struct device_node
*np
,
373 struct samsung_clk_provider
*ctx
);
374 void samsung_clk_of_register_fixed_ext(
375 struct samsung_clk_provider
*ctx
,
376 struct samsung_fixed_rate_clock
*fixed_rate_clk
,
377 unsigned int nr_fixed_rate_clk
,
378 const struct of_device_id
*clk_matches
);
380 void samsung_clk_add_lookup(struct samsung_clk_provider
*ctx
,
381 struct clk_hw
*clk_hw
, unsigned int id
);
383 void samsung_clk_register_alias(struct samsung_clk_provider
*ctx
,
384 const struct samsung_clock_alias
*list
,
385 unsigned int nr_clk
);
386 void samsung_clk_register_fixed_rate(
387 struct samsung_clk_provider
*ctx
,
388 const struct samsung_fixed_rate_clock
*clk_list
,
389 unsigned int nr_clk
);
390 void samsung_clk_register_fixed_factor(
391 struct samsung_clk_provider
*ctx
,
392 const struct samsung_fixed_factor_clock
*list
,
393 unsigned int nr_clk
);
394 void samsung_clk_register_mux(struct samsung_clk_provider
*ctx
,
395 const struct samsung_mux_clock
*clk_list
,
396 unsigned int nr_clk
);
397 void samsung_clk_register_div(struct samsung_clk_provider
*ctx
,
398 const struct samsung_div_clock
*clk_list
,
399 unsigned int nr_clk
);
400 void samsung_clk_register_gate(struct samsung_clk_provider
*ctx
,
401 const struct samsung_gate_clock
*clk_list
,
402 unsigned int nr_clk
);
403 void samsung_clk_register_pll(struct samsung_clk_provider
*ctx
,
404 const struct samsung_pll_clock
*pll_list
,
405 unsigned int nr_clk
);
406 void samsung_clk_register_cpu(struct samsung_clk_provider
*ctx
,
407 const struct samsung_cpu_clock
*list
, unsigned int nr_clk
);
409 void samsung_cmu_register_clocks(struct samsung_clk_provider
*ctx
,
410 const struct samsung_cmu_info
*cmu
);
411 struct samsung_clk_provider
*samsung_cmu_register_one(
412 struct device_node
*,
413 const struct samsung_cmu_info
*);
415 #ifdef CONFIG_PM_SLEEP
416 void samsung_clk_extended_sleep_init(void __iomem
*reg_base
,
417 const unsigned long *rdump
,
418 unsigned long nr_rdump
,
419 const struct samsung_clk_reg_dump
*rsuspend
,
420 unsigned long nr_rsuspend
);
422 static inline void samsung_clk_extended_sleep_init(void __iomem
*reg_base
,
423 const unsigned long *rdump
,
424 unsigned long nr_rdump
,
425 const struct samsung_clk_reg_dump
*rsuspend
,
426 unsigned long nr_rsuspend
) {}
428 #define samsung_clk_sleep_init(reg_base, rdump, nr_rdump) \
429 samsung_clk_extended_sleep_init(reg_base, rdump, nr_rdump, NULL, 0)
431 void samsung_clk_save(void __iomem
*base
,
432 struct samsung_clk_reg_dump
*rd
,
433 unsigned int num_regs
);
434 void samsung_clk_restore(void __iomem
*base
,
435 const struct samsung_clk_reg_dump
*rd
,
436 unsigned int num_regs
);
437 struct samsung_clk_reg_dump
*samsung_clk_alloc_reg_dump(
438 const unsigned long *rdump
,
439 unsigned long nr_rdump
);
441 #endif /* __SAMSUNG_CLK_H */