2 * Copyright (c) 2014 MundoReader S.L.
3 * Author: Heiko Stuebner <heiko@sntech.de>
8 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
9 * Copyright (c) 2013 Linaro Ltd.
10 * Author: Thomas Abraham <thomas.ab@samsung.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
23 #ifndef CLK_ROCKCHIP_CLK_H
24 #define CLK_ROCKCHIP_CLK_H
27 #include <linux/clk.h>
28 #include <linux/clk-provider.h>
30 #define HIWORD_UPDATE(val, mask, shift) \
31 ((val) << (shift) | (mask) << ((shift) + 16))
33 /* register positions shared by RK2928, RK3066 and RK3188 */
34 #define RK2928_PLL_CON(x) (x * 0x4)
35 #define RK2928_MODE_CON 0x40
36 #define RK2928_CLKSEL_CON(x) (x * 0x4 + 0x44)
37 #define RK2928_CLKGATE_CON(x) (x * 0x4 + 0xd0)
38 #define RK2928_GLB_SRST_FST 0x100
39 #define RK2928_GLB_SRST_SND 0x104
40 #define RK2928_SOFTRST_CON(x) (x * 0x4 + 0x110)
41 #define RK2928_MISC_CON 0x134
43 #define RK3288_PLL_CON(x) RK2928_PLL_CON(x)
44 #define RK3288_MODE_CON 0x50
45 #define RK3288_CLKSEL_CON(x) (x * 0x4 + 0x60)
46 #define RK3288_CLKGATE_CON(x) (x * 0x4 + 0x160)
47 #define RK3288_GLB_SRST_FST 0x1b0
48 #define RK3288_GLB_SRST_SND 0x1b4
49 #define RK3288_SOFTRST_CON(x) (x * 0x4 + 0x1b8)
50 #define RK3288_MISC_CON 0x1e8
52 enum rockchip_pll_type {
56 #define RK3066_PLL_RATE(_rate, _nr, _nf, _no) \
62 .bwadj = (_nf >> 1), \
65 struct rockchip_pll_rate_table {
74 * struct rockchip_pll_clock: information about pll clock
75 * @id: platform specific id of the clock.
76 * @name: name of this pll clock.
77 * @parent_name: name of the parent clock.
78 * @flags: optional flags for basic clock.
79 * @con_offset: offset of the register for configuring the PLL.
80 * @mode_offset: offset of the register for configuring the PLL-mode.
81 * @mode_shift: offset inside the mode-register for the mode of this pll.
82 * @lock_shift: offset inside the lock register for the lock status.
83 * @type: Type of PLL to be registered.
84 * @rate_table: Table of usable pll rates
86 struct rockchip_pll_clock {
89 const char **parent_names;
96 enum rockchip_pll_type type;
97 struct rockchip_pll_rate_table *rate_table;
100 #define PLL(_type, _id, _name, _pnames, _flags, _con, _mode, _mshift, \
106 .parent_names = _pnames, \
107 .num_parents = ARRAY_SIZE(_pnames), \
108 .flags = CLK_GET_RATE_NOCACHE | _flags, \
109 .con_offset = _con, \
110 .mode_offset = _mode, \
111 .mode_shift = _mshift, \
112 .lock_shift = _lshift, \
113 .rate_table = _rtable, \
116 struct clk *rockchip_clk_register_pll(enum rockchip_pll_type pll_type,
117 const char *name, const char **parent_names, u8 num_parents,
118 void __iomem *base, int con_offset, int grf_lock_offset,
119 int lock_shift, int reg_mode, int mode_shift,
120 struct rockchip_pll_rate_table *rate_table,
123 struct rockchip_cpuclk_clksel {
128 #define ROCKCHIP_CPUCLK_NUM_DIVIDERS 2
129 struct rockchip_cpuclk_rate_table {
131 struct rockchip_cpuclk_clksel divs[ROCKCHIP_CPUCLK_NUM_DIVIDERS];
135 * struct rockchip_cpuclk_reg_data: describes register offsets and masks of the cpuclock
136 * @core_reg: register offset of the core settings register
137 * @div_core_shift: core divider offset used to divide the pll value
138 * @div_core_mask: core divider mask
139 * @mux_core_shift: offset of the core multiplexer
141 struct rockchip_cpuclk_reg_data {
149 struct clk *rockchip_clk_register_cpuclk(const char *name,
150 const char **parent_names, u8 num_parents,
151 const struct rockchip_cpuclk_reg_data *reg_data,
152 const struct rockchip_cpuclk_rate_table *rates,
153 int nrates, void __iomem *reg_base, spinlock_t *lock);
155 #define PNAME(x) static const char *x[] __initconst
157 enum rockchip_clk_branch_type {
161 branch_fraction_divider,
165 struct rockchip_clk_branch {
167 enum rockchip_clk_branch_type branch_type;
169 const char **parent_names;
179 struct clk_div_table *div_table;
185 #define COMPOSITE(_id, cname, pnames, f, mo, ms, mw, mf, ds, dw,\
189 .branch_type = branch_composite, \
191 .parent_names = pnames, \
192 .num_parents = ARRAY_SIZE(pnames), \
194 .muxdiv_offset = mo, \
206 #define COMPOSITE_NOMUX(_id, cname, pname, f, mo, ds, dw, df, \
210 .branch_type = branch_composite, \
212 .parent_names = (const char *[]){ pname }, \
215 .muxdiv_offset = mo, \
224 #define COMPOSITE_NOMUX_DIVTBL(_id, cname, pname, f, mo, ds, dw,\
225 df, dt, go, gs, gf) \
228 .branch_type = branch_composite, \
230 .parent_names = (const char *[]){ pname }, \
233 .muxdiv_offset = mo, \
243 #define COMPOSITE_NODIV(_id, cname, pnames, f, mo, ms, mw, mf, \
247 .branch_type = branch_composite, \
249 .parent_names = pnames, \
250 .num_parents = ARRAY_SIZE(pnames), \
252 .muxdiv_offset = mo, \
261 #define COMPOSITE_NOGATE(_id, cname, pnames, f, mo, ms, mw, mf, \
265 .branch_type = branch_composite, \
267 .parent_names = pnames, \
268 .num_parents = ARRAY_SIZE(pnames), \
270 .muxdiv_offset = mo, \
280 #define COMPOSITE_FRAC(_id, cname, pname, f, mo, df, go, gs, gf)\
283 .branch_type = branch_fraction_divider, \
285 .parent_names = (const char *[]){ pname }, \
288 .muxdiv_offset = mo, \
297 #define MUX(_id, cname, pnames, f, o, s, w, mf) \
300 .branch_type = branch_mux, \
302 .parent_names = pnames, \
303 .num_parents = ARRAY_SIZE(pnames), \
305 .muxdiv_offset = o, \
312 #define DIV(_id, cname, pname, f, o, s, w, df) \
315 .branch_type = branch_divider, \
317 .parent_names = (const char *[]){ pname }, \
320 .muxdiv_offset = o, \
327 #define DIVTBL(_id, cname, pname, f, o, s, w, df, dt) \
330 .branch_type = branch_divider, \
332 .parent_names = (const char *[]){ pname }, \
335 .muxdiv_offset = o, \
342 #define GATE(_id, cname, pname, f, o, b, gf) \
345 .branch_type = branch_gate, \
347 .parent_names = (const char *[]){ pname }, \
356 void rockchip_clk_init(struct device_node *np, void __iomem *base,
357 unsigned long nr_clks);
358 struct regmap *rockchip_clk_get_grf(void);
359 void rockchip_clk_add_lookup(struct clk *clk, unsigned int id);
360 void rockchip_clk_register_branches(struct rockchip_clk_branch *clk_list,
361 unsigned int nr_clk);
362 void rockchip_clk_register_plls(struct rockchip_pll_clock *pll_list,
363 unsigned int nr_pll, int grf_lock_offset);
364 void rockchip_clk_register_armclk(unsigned int lookup_id, const char *name,
365 const char **parent_names, u8 num_parents,
366 const struct rockchip_cpuclk_reg_data *reg_data,
367 const struct rockchip_cpuclk_rate_table *rates,
369 void rockchip_clk_protect_critical(const char *clocks[], int nclocks);
370 void rockchip_register_restart_notifier(unsigned int reg);
372 #define ROCKCHIP_SOFTRST_HIWORD_MASK BIT(0)
374 #ifdef CONFIG_RESET_CONTROLLER
375 void rockchip_register_softrst(struct device_node *np,
376 unsigned int num_regs,
377 void __iomem *base, u8 flags);
379 static inline void rockchip_register_softrst(struct device_node *np,
380 unsigned int num_regs,
381 void __iomem *base, u8 flags)