blob: adb66cc9492901ccb377027c4fec718c05047e49 [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Heiko Stübnera245fec2014-07-03 01:58:39 +02002/*
3 * Copyright (c) 2014 MundoReader S.L.
4 * Author: Heiko Stuebner <heiko@sntech.de>
5 *
Xing Zheng9c4d6e552015-11-05 15:33:57 +08006 * Copyright (c) 2015 Rockchip Electronics Co. Ltd.
7 * Author: Xing Zheng <zhengxing@rock-chips.com>
8 *
Heiko Stübnera245fec2014-07-03 01:58:39 +02009 * based on
10 *
11 * samsung/clk.h
12 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
13 * Copyright (c) 2013 Linaro Ltd.
14 * Author: Thomas Abraham <thomas.ab@samsung.com>
Heiko Stübnera245fec2014-07-03 01:58:39 +020015 */
16
17#ifndef CLK_ROCKCHIP_CLK_H
18#define CLK_ROCKCHIP_CLK_H
19
20#include <linux/io.h>
Xing Zhengef1d9fe2016-03-09 10:37:04 +080021#include <linux/clk-provider.h>
Stephen Boydf684ff82015-06-19 15:00:46 -070022
23struct clk;
Heiko Stübnera245fec2014-07-03 01:58:39 +020024
25#define HIWORD_UPDATE(val, mask, shift) \
26 ((val) << (shift) | (mask) << ((shift) + 16))
27
Elaine Zhang243229b2018-06-15 10:16:51 +080028/* register positions shared by PX30, RV1108, RK2928, RK3036, RK3066, RK3188 and RK3228 */
29#define BOOST_PLL_H_CON(x) ((x) * 0x4)
30#define BOOST_CLK_CON 0x0008
31#define BOOST_BOOST_CON 0x000c
32#define BOOST_SWITCH_CNT 0x0010
33#define BOOST_HIGH_PERF_CNT0 0x0014
34#define BOOST_HIGH_PERF_CNT1 0x0018
35#define BOOST_STATIS_THRESHOLD 0x001c
36#define BOOST_SHORT_SWITCH_CNT 0x0020
37#define BOOST_SWITCH_THRESHOLD 0x0024
38#define BOOST_FSM_STATUS 0x0028
39#define BOOST_PLL_L_CON(x) ((x) * 0x4 + 0x2c)
40#define BOOST_RECOVERY_MASK 0x1
41#define BOOST_RECOVERY_SHIFT 1
42#define BOOST_SW_CTRL_MASK 0x1
43#define BOOST_SW_CTRL_SHIFT 2
44#define BOOST_LOW_FREQ_EN_MASK 0x1
45#define BOOST_LOW_FREQ_EN_SHIFT 3
46#define BOOST_BUSY_STATE BIT(8)
47
48#define PX30_PLL_CON(x) ((x) * 0x4)
49#define PX30_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
50#define PX30_CLKGATE_CON(x) ((x) * 0x4 + 0x200)
51#define PX30_GLB_SRST_FST 0xb8
52#define PX30_GLB_SRST_SND 0xbc
53#define PX30_SOFTRST_CON(x) ((x) * 0x4 + 0x300)
54#define PX30_MODE_CON 0xa0
55#define PX30_MISC_CON 0xa4
56#define PX30_SDMMC_CON0 0x380
57#define PX30_SDMMC_CON1 0x384
58#define PX30_SDIO_CON0 0x388
59#define PX30_SDIO_CON1 0x38c
60#define PX30_EMMC_CON0 0x390
61#define PX30_EMMC_CON1 0x394
62
63#define PX30_PMU_PLL_CON(x) ((x) * 0x4)
64#define PX30_PMU_CLKSEL_CON(x) ((x) * 0x4 + 0x40)
65#define PX30_PMU_CLKGATE_CON(x) ((x) * 0x4 + 0x80)
66#define PX30_PMU_MODE 0x0020
67
Andy Yan7e2a9032017-03-17 18:18:38 +010068#define RV1108_PLL_CON(x) ((x) * 0x4)
69#define RV1108_CLKSEL_CON(x) ((x) * 0x4 + 0x60)
70#define RV1108_CLKGATE_CON(x) ((x) * 0x4 + 0x120)
71#define RV1108_SOFTRST_CON(x) ((x) * 0x4 + 0x180)
72#define RV1108_GLB_SRST_FST 0x1c0
73#define RV1108_GLB_SRST_SND 0x1c4
74#define RV1108_MISC_CON 0x1cc
75#define RV1108_SDMMC_CON0 0x1d8
76#define RV1108_SDMMC_CON1 0x1dc
77#define RV1108_SDIO_CON0 0x1e0
78#define RV1108_SDIO_CON1 0x1e4
79#define RV1108_EMMC_CON0 0x1e8
80#define RV1108_EMMC_CON1 0x1ec
Shawn Line44dde22016-11-16 16:49:23 +080081
Heiko Stuebner2d7884a2015-06-18 16:18:30 +020082#define RK2928_PLL_CON(x) ((x) * 0x4)
Heiko Stübnera245fec2014-07-03 01:58:39 +020083#define RK2928_MODE_CON 0x40
Heiko Stuebner2d7884a2015-06-18 16:18:30 +020084#define RK2928_CLKSEL_CON(x) ((x) * 0x4 + 0x44)
85#define RK2928_CLKGATE_CON(x) ((x) * 0x4 + 0xd0)
Heiko Stübnera245fec2014-07-03 01:58:39 +020086#define RK2928_GLB_SRST_FST 0x100
87#define RK2928_GLB_SRST_SND 0x104
Heiko Stuebner2d7884a2015-06-18 16:18:30 +020088#define RK2928_SOFTRST_CON(x) ((x) * 0x4 + 0x110)
Heiko Stübnera245fec2014-07-03 01:58:39 +020089#define RK2928_MISC_CON 0x134
90
Xing Zheng5190c082015-11-05 15:33:58 +080091#define RK3036_SDMMC_CON0 0x144
92#define RK3036_SDMMC_CON1 0x148
93#define RK3036_SDIO_CON0 0x14c
94#define RK3036_SDIO_CON1 0x150
95#define RK3036_EMMC_CON0 0x154
96#define RK3036_EMMC_CON1 0x158
97
Jeffy Chen307a2e92015-12-11 09:30:50 +080098#define RK3228_GLB_SRST_FST 0x1f0
99#define RK3228_GLB_SRST_SND 0x1f4
100#define RK3228_SDMMC_CON0 0x1c0
101#define RK3228_SDMMC_CON1 0x1c4
102#define RK3228_SDIO_CON0 0x1c8
103#define RK3228_SDIO_CON1 0x1cc
104#define RK3228_EMMC_CON0 0x1d8
105#define RK3228_EMMC_CON1 0x1dc
106
Heiko Stübnerb9e4ba52014-07-03 02:02:37 +0200107#define RK3288_PLL_CON(x) RK2928_PLL_CON(x)
108#define RK3288_MODE_CON 0x50
Heiko Stuebner2d7884a2015-06-18 16:18:30 +0200109#define RK3288_CLKSEL_CON(x) ((x) * 0x4 + 0x60)
110#define RK3288_CLKGATE_CON(x) ((x) * 0x4 + 0x160)
Heiko Stübnerb9e4ba52014-07-03 02:02:37 +0200111#define RK3288_GLB_SRST_FST 0x1b0
112#define RK3288_GLB_SRST_SND 0x1b4
Heiko Stuebner2d7884a2015-06-18 16:18:30 +0200113#define RK3288_SOFTRST_CON(x) ((x) * 0x4 + 0x1b8)
Heiko Stübnerb9e4ba52014-07-03 02:02:37 +0200114#define RK3288_MISC_CON 0x1e8
Alexandru M Stan89bf26c2014-11-26 17:30:27 -0800115#define RK3288_SDMMC_CON0 0x200
116#define RK3288_SDMMC_CON1 0x204
117#define RK3288_SDIO0_CON0 0x208
118#define RK3288_SDIO0_CON1 0x20c
119#define RK3288_SDIO1_CON0 0x210
120#define RK3288_SDIO1_CON1 0x214
121#define RK3288_EMMC_CON0 0x218
122#define RK3288_EMMC_CON1 0x21c
Heiko Stübnerb9e4ba52014-07-03 02:02:37 +0200123
Elaine Zhangfe3511a2016-12-29 10:45:11 +0800124#define RK3328_PLL_CON(x) RK2928_PLL_CON(x)
125#define RK3328_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
126#define RK3328_CLKGATE_CON(x) ((x) * 0x4 + 0x200)
127#define RK3328_GRFCLKSEL_CON(x) ((x) * 0x4 + 0x100)
128#define RK3328_GLB_SRST_FST 0x9c
129#define RK3328_GLB_SRST_SND 0x98
130#define RK3328_SOFTRST_CON(x) ((x) * 0x4 + 0x300)
131#define RK3328_MODE_CON 0x80
132#define RK3328_MISC_CON 0x84
133#define RK3328_SDMMC_CON0 0x380
134#define RK3328_SDMMC_CON1 0x384
135#define RK3328_SDIO_CON0 0x388
136#define RK3328_SDIO_CON1 0x38c
137#define RK3328_EMMC_CON0 0x390
138#define RK3328_EMMC_CON1 0x394
139#define RK3328_SDMMC_EXT_CON0 0x398
140#define RK3328_SDMMC_EXT_CON1 0x39C
141
Heiko Stuebner3536c972015-07-05 11:00:20 +0200142#define RK3368_PLL_CON(x) RK2928_PLL_CON(x)
143#define RK3368_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
144#define RK3368_CLKGATE_CON(x) ((x) * 0x4 + 0x200)
145#define RK3368_GLB_SRST_FST 0x280
146#define RK3368_GLB_SRST_SND 0x284
147#define RK3368_SOFTRST_CON(x) ((x) * 0x4 + 0x300)
148#define RK3368_MISC_CON 0x380
149#define RK3368_SDMMC_CON0 0x400
150#define RK3368_SDMMC_CON1 0x404
151#define RK3368_SDIO0_CON0 0x408
152#define RK3368_SDIO0_CON1 0x40c
153#define RK3368_SDIO1_CON0 0x410
154#define RK3368_SDIO1_CON1 0x414
155#define RK3368_EMMC_CON0 0x418
156#define RK3368_EMMC_CON1 0x41c
157
Xing Zheng11551002016-03-28 17:51:37 +0800158#define RK3399_PLL_CON(x) RK2928_PLL_CON(x)
159#define RK3399_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
160#define RK3399_CLKGATE_CON(x) ((x) * 0x4 + 0x300)
161#define RK3399_SOFTRST_CON(x) ((x) * 0x4 + 0x400)
162#define RK3399_GLB_SRST_FST 0x500
163#define RK3399_GLB_SRST_SND 0x504
164#define RK3399_GLB_CNT_TH 0x508
165#define RK3399_MISC_CON 0x50c
166#define RK3399_RST_CON 0x510
167#define RK3399_RST_ST 0x514
168#define RK3399_SDMMC_CON0 0x580
169#define RK3399_SDMMC_CON1 0x584
170#define RK3399_SDIO_CON0 0x588
171#define RK3399_SDIO_CON1 0x58c
172
173#define RK3399_PMU_PLL_CON(x) RK2928_PLL_CON(x)
174#define RK3399_PMU_CLKSEL_CON(x) ((x) * 0x4 + 0x80)
175#define RK3399_PMU_CLKGATE_CON(x) ((x) * 0x4 + 0x100)
176#define RK3399_PMU_SOFTRST_CON(x) ((x) * 0x4 + 0x110)
177
Heiko Stübner90c59022014-07-03 01:59:10 +0200178enum rockchip_pll_type {
Xing Zheng9c4d6e552015-11-05 15:33:57 +0800179 pll_rk3036,
Heiko Stübner90c59022014-07-03 01:59:10 +0200180 pll_rk3066,
Elaine Zhang7bed9242016-12-29 10:45:10 +0800181 pll_rk3328,
Xing Zhengb40bacc2016-03-10 11:47:01 +0800182 pll_rk3399,
Heiko Stübner90c59022014-07-03 01:59:10 +0200183};
184
Xing Zheng9c4d6e552015-11-05 15:33:57 +0800185#define RK3036_PLL_RATE(_rate, _refdiv, _fbdiv, _postdiv1, \
186 _postdiv2, _dsmpd, _frac) \
187{ \
188 .rate = _rate##U, \
189 .fbdiv = _fbdiv, \
190 .postdiv1 = _postdiv1, \
191 .refdiv = _refdiv, \
192 .postdiv2 = _postdiv2, \
193 .dsmpd = _dsmpd, \
194 .frac = _frac, \
195}
196
Heiko Stübner90c59022014-07-03 01:59:10 +0200197#define RK3066_PLL_RATE(_rate, _nr, _nf, _no) \
198{ \
199 .rate = _rate##U, \
200 .nr = _nr, \
201 .nf = _nf, \
202 .no = _no, \
Douglas Anderson2bbfe002015-07-21 13:41:23 -0700203 .nb = ((_nf) < 2) ? 1 : (_nf) >> 1, \
Heiko Stübner90c59022014-07-03 01:59:10 +0200204}
205
Douglas Anderson2bbfe002015-07-21 13:41:23 -0700206#define RK3066_PLL_RATE_NB(_rate, _nr, _nf, _no, _nb) \
Kever Yang49ed9ee2014-10-09 22:23:57 -0700207{ \
208 .rate = _rate##U, \
209 .nr = _nr, \
210 .nf = _nf, \
211 .no = _no, \
Douglas Anderson2bbfe002015-07-21 13:41:23 -0700212 .nb = _nb, \
Kever Yang49ed9ee2014-10-09 22:23:57 -0700213}
214
Xing Zhengef1d9fe2016-03-09 10:37:04 +0800215/**
Shawn Lin2af25442016-03-13 00:25:14 +0800216 * struct rockchip_clk_provider - information about clock provider
Xing Zhengef1d9fe2016-03-09 10:37:04 +0800217 * @reg_base: virtual address for the register base.
218 * @clk_data: holds clock related data like clk* and number of clocks.
219 * @cru_node: device-node of the clock-provider
220 * @grf: regmap of the general-register-files syscon
221 * @lock: maintains exclusion between callbacks for a given clock-provider.
222 */
223struct rockchip_clk_provider {
224 void __iomem *reg_base;
225 struct clk_onecell_data clk_data;
226 struct device_node *cru_node;
227 struct regmap *grf;
228 spinlock_t lock;
229};
230
Heiko Stübner90c59022014-07-03 01:59:10 +0200231struct rockchip_pll_rate_table {
232 unsigned long rate;
233 unsigned int nr;
234 unsigned int nf;
235 unsigned int no;
Douglas Anderson2bbfe002015-07-21 13:41:23 -0700236 unsigned int nb;
Xing Zhengb40bacc2016-03-10 11:47:01 +0800237 /* for RK3036/RK3399 */
Xing Zheng9c4d6e552015-11-05 15:33:57 +0800238 unsigned int fbdiv;
239 unsigned int postdiv1;
240 unsigned int refdiv;
241 unsigned int postdiv2;
242 unsigned int dsmpd;
243 unsigned int frac;
Heiko Stübner90c59022014-07-03 01:59:10 +0200244};
245
246/**
Shawn Lin2af25442016-03-13 00:25:14 +0800247 * struct rockchip_pll_clock - information about pll clock
Heiko Stübner90c59022014-07-03 01:59:10 +0200248 * @id: platform specific id of the clock.
249 * @name: name of this pll clock.
Shawn Lin2af25442016-03-13 00:25:14 +0800250 * @parent_names: name of the parent clock.
251 * @num_parents: number of parents
Heiko Stübner90c59022014-07-03 01:59:10 +0200252 * @flags: optional flags for basic clock.
253 * @con_offset: offset of the register for configuring the PLL.
254 * @mode_offset: offset of the register for configuring the PLL-mode.
255 * @mode_shift: offset inside the mode-register for the mode of this pll.
256 * @lock_shift: offset inside the lock register for the lock status.
257 * @type: Type of PLL to be registered.
Heiko Stuebner4f8a7c52014-11-20 20:38:50 +0100258 * @pll_flags: hardware-specific flags
Heiko Stübner90c59022014-07-03 01:59:10 +0200259 * @rate_table: Table of usable pll rates
Heiko Stuebner0bb66d32014-11-20 20:38:52 +0100260 *
261 * Flags:
262 * ROCKCHIP_PLL_SYNC_RATE - check rate parameters to match against the
263 * rate_table parameters and ajust them if necessary.
Heiko Stübner90c59022014-07-03 01:59:10 +0200264 */
265struct rockchip_pll_clock {
266 unsigned int id;
267 const char *name;
Uwe Kleine-König4a1caed2015-05-28 10:45:51 +0200268 const char *const *parent_names;
Heiko Stübner90c59022014-07-03 01:59:10 +0200269 u8 num_parents;
270 unsigned long flags;
271 int con_offset;
272 int mode_offset;
273 int mode_shift;
274 int lock_shift;
275 enum rockchip_pll_type type;
Heiko Stuebner4f8a7c52014-11-20 20:38:50 +0100276 u8 pll_flags;
Heiko Stübner90c59022014-07-03 01:59:10 +0200277 struct rockchip_pll_rate_table *rate_table;
278};
279
Heiko Stuebner0bb66d32014-11-20 20:38:52 +0100280#define ROCKCHIP_PLL_SYNC_RATE BIT(0)
281
Heiko Stübner90c59022014-07-03 01:59:10 +0200282#define PLL(_type, _id, _name, _pnames, _flags, _con, _mode, _mshift, \
Heiko Stuebner4f8a7c52014-11-20 20:38:50 +0100283 _lshift, _pflags, _rtable) \
Heiko Stübner90c59022014-07-03 01:59:10 +0200284 { \
285 .id = _id, \
286 .type = _type, \
287 .name = _name, \
288 .parent_names = _pnames, \
289 .num_parents = ARRAY_SIZE(_pnames), \
290 .flags = CLK_GET_RATE_NOCACHE | _flags, \
291 .con_offset = _con, \
292 .mode_offset = _mode, \
293 .mode_shift = _mshift, \
294 .lock_shift = _lshift, \
Heiko Stuebner4f8a7c52014-11-20 20:38:50 +0100295 .pll_flags = _pflags, \
Heiko Stübner90c59022014-07-03 01:59:10 +0200296 .rate_table = _rtable, \
297 }
298
Xing Zhengef1d9fe2016-03-09 10:37:04 +0800299struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
300 enum rockchip_pll_type pll_type,
Uwe Kleine-König4a1caed2015-05-28 10:45:51 +0200301 const char *name, const char *const *parent_names,
Xing Zhengef1d9fe2016-03-09 10:37:04 +0800302 u8 num_parents, int con_offset, int grf_lock_offset,
303 int lock_shift, int mode_offset, int mode_shift,
304 struct rockchip_pll_rate_table *rate_table,
Heiko Stübnere6cebc72016-07-29 15:56:55 +0800305 unsigned long flags, u8 clk_pll_flags);
Heiko Stübner90c59022014-07-03 01:59:10 +0200306
Heiko Stuebnerf6fba5f2014-09-04 22:10:43 +0200307struct rockchip_cpuclk_clksel {
308 int reg;
309 u32 val;
310};
311
312#define ROCKCHIP_CPUCLK_NUM_DIVIDERS 2
313struct rockchip_cpuclk_rate_table {
314 unsigned long prate;
315 struct rockchip_cpuclk_clksel divs[ROCKCHIP_CPUCLK_NUM_DIVIDERS];
316};
317
318/**
Heiko Stuebner03ae1742016-04-19 21:29:27 +0200319 * struct rockchip_cpuclk_reg_data - register offsets and masks of the cpuclock
Heiko Stuebnerf6fba5f2014-09-04 22:10:43 +0200320 * @core_reg: register offset of the core settings register
321 * @div_core_shift: core divider offset used to divide the pll value
322 * @div_core_mask: core divider mask
Xing Zheng268aeba2016-03-09 10:37:03 +0800323 * @mux_core_alt: mux value to select alternate parent
324 * @mux_core_main: mux value to select main parent of core
Heiko Stuebnerf6fba5f2014-09-04 22:10:43 +0200325 * @mux_core_shift: offset of the core multiplexer
Xing Zheng268aeba2016-03-09 10:37:03 +0800326 * @mux_core_mask: core multiplexer mask
Heiko Stuebnerf6fba5f2014-09-04 22:10:43 +0200327 */
328struct rockchip_cpuclk_reg_data {
329 int core_reg;
330 u8 div_core_shift;
331 u32 div_core_mask;
Xing Zheng268aeba2016-03-09 10:37:03 +0800332 u8 mux_core_alt;
333 u8 mux_core_main;
Heiko Stuebnerf6fba5f2014-09-04 22:10:43 +0200334 u8 mux_core_shift;
Xing Zheng268aeba2016-03-09 10:37:03 +0800335 u32 mux_core_mask;
Heiko Stuebnerf6fba5f2014-09-04 22:10:43 +0200336};
337
338struct clk *rockchip_clk_register_cpuclk(const char *name,
Uwe Kleine-König4a1caed2015-05-28 10:45:51 +0200339 const char *const *parent_names, u8 num_parents,
Heiko Stuebnerf6fba5f2014-09-04 22:10:43 +0200340 const struct rockchip_cpuclk_reg_data *reg_data,
341 const struct rockchip_cpuclk_rate_table *rates,
342 int nrates, void __iomem *reg_base, spinlock_t *lock);
343
Alexandru M Stan89bf26c2014-11-26 17:30:27 -0800344struct clk *rockchip_clk_register_mmc(const char *name,
Uwe Kleine-König4a1caed2015-05-28 10:45:51 +0200345 const char *const *parent_names, u8 num_parents,
Alexandru M Stan89bf26c2014-11-26 17:30:27 -0800346 void __iomem *reg, int shift);
347
Lin Huanga4f182b2016-08-22 11:36:17 +0800348/*
349 * DDRCLK flags, including method of setting the rate
350 * ROCKCHIP_DDRCLK_SIP: use SIP call to bl31 to change ddrclk rate.
351 */
352#define ROCKCHIP_DDRCLK_SIP BIT(0)
353
354struct clk *rockchip_clk_register_ddrclk(const char *name, int flags,
355 const char *const *parent_names,
356 u8 num_parents, int mux_offset,
357 int mux_shift, int mux_width,
358 int div_shift, int div_width,
359 int ddr_flags, void __iomem *reg_base,
360 spinlock_t *lock);
361
Heiko Stuebner8a76f442015-07-05 11:00:14 +0200362#define ROCKCHIP_INVERTER_HIWORD_MASK BIT(0)
363
364struct clk *rockchip_clk_register_inverter(const char *name,
365 const char *const *parent_names, u8 num_parents,
366 void __iomem *reg, int shift, int flags,
367 spinlock_t *lock);
368
Heiko Stuebnercb1d9f62016-12-27 00:00:38 +0100369struct clk *rockchip_clk_register_muxgrf(const char *name,
370 const char *const *parent_names, u8 num_parents,
371 int flags, struct regmap *grf, int reg,
372 int shift, int width, int mux_flags);
373
Uwe Kleine-König4a1caed2015-05-28 10:45:51 +0200374#define PNAME(x) static const char *const x[] __initconst
Heiko Stübnera245fec2014-07-03 01:58:39 +0200375
376enum rockchip_clk_branch_type {
377 branch_composite,
378 branch_mux,
Heiko Stuebnercb1d9f62016-12-27 00:00:38 +0100379 branch_muxgrf,
Heiko Stübnera245fec2014-07-03 01:58:39 +0200380 branch_divider,
381 branch_fraction_divider,
382 branch_gate,
Alexandru M Stan89bf26c2014-11-26 17:30:27 -0800383 branch_mmc,
Heiko Stuebner8a76f442015-07-05 11:00:14 +0200384 branch_inverter,
Heiko Stuebner29a30c22015-06-20 13:08:57 +0200385 branch_factor,
Lin Huanga4f182b2016-08-22 11:36:17 +0800386 branch_ddrclk,
Elaine Zhang956060a2018-06-15 10:16:50 +0800387 branch_half_divider,
Heiko Stübnera245fec2014-07-03 01:58:39 +0200388};
389
390struct rockchip_clk_branch {
391 unsigned int id;
392 enum rockchip_clk_branch_type branch_type;
393 const char *name;
Uwe Kleine-König4a1caed2015-05-28 10:45:51 +0200394 const char *const *parent_names;
Heiko Stübnera245fec2014-07-03 01:58:39 +0200395 u8 num_parents;
396 unsigned long flags;
397 int muxdiv_offset;
398 u8 mux_shift;
399 u8 mux_width;
400 u8 mux_flags;
Finley Xiao1f55660ff2019-04-03 17:42:26 +0800401 int div_offset;
Heiko Stübnera245fec2014-07-03 01:58:39 +0200402 u8 div_shift;
403 u8 div_width;
404 u8 div_flags;
405 struct clk_div_table *div_table;
406 int gate_offset;
407 u8 gate_shift;
408 u8 gate_flags;
Heiko Stuebner8ca1ca82015-12-22 22:27:59 +0100409 struct rockchip_clk_branch *child;
Heiko Stübnera245fec2014-07-03 01:58:39 +0200410};
411
412#define COMPOSITE(_id, cname, pnames, f, mo, ms, mw, mf, ds, dw,\
413 df, go, gs, gf) \
414 { \
415 .id = _id, \
416 .branch_type = branch_composite, \
417 .name = cname, \
418 .parent_names = pnames, \
419 .num_parents = ARRAY_SIZE(pnames), \
420 .flags = f, \
421 .muxdiv_offset = mo, \
422 .mux_shift = ms, \
423 .mux_width = mw, \
424 .mux_flags = mf, \
425 .div_shift = ds, \
426 .div_width = dw, \
427 .div_flags = df, \
428 .gate_offset = go, \
429 .gate_shift = gs, \
430 .gate_flags = gf, \
431 }
432
Finley Xiao1f55660ff2019-04-03 17:42:26 +0800433#define COMPOSITE_DIV_OFFSET(_id, cname, pnames, f, mo, ms, mw, \
434 mf, do, ds, dw, df, go, gs, gf) \
435 { \
436 .id = _id, \
437 .branch_type = branch_composite, \
438 .name = cname, \
439 .parent_names = pnames, \
440 .num_parents = ARRAY_SIZE(pnames), \
441 .flags = f, \
442 .muxdiv_offset = mo, \
443 .mux_shift = ms, \
444 .mux_width = mw, \
445 .mux_flags = mf, \
446 .div_offset = do, \
447 .div_shift = ds, \
448 .div_width = dw, \
449 .div_flags = df, \
450 .gate_offset = go, \
451 .gate_shift = gs, \
452 .gate_flags = gf, \
453 }
454
Heiko Stübnera245fec2014-07-03 01:58:39 +0200455#define COMPOSITE_NOMUX(_id, cname, pname, f, mo, ds, dw, df, \
456 go, gs, gf) \
457 { \
458 .id = _id, \
459 .branch_type = branch_composite, \
460 .name = cname, \
461 .parent_names = (const char *[]){ pname }, \
462 .num_parents = 1, \
463 .flags = f, \
464 .muxdiv_offset = mo, \
465 .div_shift = ds, \
466 .div_width = dw, \
467 .div_flags = df, \
468 .gate_offset = go, \
469 .gate_shift = gs, \
470 .gate_flags = gf, \
471 }
472
473#define COMPOSITE_NOMUX_DIVTBL(_id, cname, pname, f, mo, ds, dw,\
474 df, dt, go, gs, gf) \
475 { \
476 .id = _id, \
477 .branch_type = branch_composite, \
478 .name = cname, \
479 .parent_names = (const char *[]){ pname }, \
480 .num_parents = 1, \
481 .flags = f, \
482 .muxdiv_offset = mo, \
483 .div_shift = ds, \
484 .div_width = dw, \
485 .div_flags = df, \
486 .div_table = dt, \
487 .gate_offset = go, \
488 .gate_shift = gs, \
489 .gate_flags = gf, \
490 }
491
492#define COMPOSITE_NODIV(_id, cname, pnames, f, mo, ms, mw, mf, \
493 go, gs, gf) \
494 { \
495 .id = _id, \
496 .branch_type = branch_composite, \
497 .name = cname, \
498 .parent_names = pnames, \
499 .num_parents = ARRAY_SIZE(pnames), \
500 .flags = f, \
501 .muxdiv_offset = mo, \
502 .mux_shift = ms, \
503 .mux_width = mw, \
504 .mux_flags = mf, \
505 .gate_offset = go, \
506 .gate_shift = gs, \
507 .gate_flags = gf, \
508 }
509
510#define COMPOSITE_NOGATE(_id, cname, pnames, f, mo, ms, mw, mf, \
511 ds, dw, df) \
512 { \
513 .id = _id, \
514 .branch_type = branch_composite, \
515 .name = cname, \
516 .parent_names = pnames, \
517 .num_parents = ARRAY_SIZE(pnames), \
518 .flags = f, \
519 .muxdiv_offset = mo, \
520 .mux_shift = ms, \
521 .mux_width = mw, \
522 .mux_flags = mf, \
523 .div_shift = ds, \
524 .div_width = dw, \
525 .div_flags = df, \
526 .gate_offset = -1, \
527 }
528
Heiko Stuebner6f085072015-06-18 16:18:31 +0200529#define COMPOSITE_NOGATE_DIVTBL(_id, cname, pnames, f, mo, ms, \
530 mw, mf, ds, dw, df, dt) \
531 { \
532 .id = _id, \
533 .branch_type = branch_composite, \
534 .name = cname, \
535 .parent_names = pnames, \
536 .num_parents = ARRAY_SIZE(pnames), \
537 .flags = f, \
538 .muxdiv_offset = mo, \
539 .mux_shift = ms, \
540 .mux_width = mw, \
541 .mux_flags = mf, \
542 .div_shift = ds, \
543 .div_width = dw, \
544 .div_flags = df, \
545 .div_table = dt, \
546 .gate_offset = -1, \
547 }
548
Heiko Stübnera245fec2014-07-03 01:58:39 +0200549#define COMPOSITE_FRAC(_id, cname, pname, f, mo, df, go, gs, gf)\
550 { \
551 .id = _id, \
552 .branch_type = branch_fraction_divider, \
553 .name = cname, \
554 .parent_names = (const char *[]){ pname }, \
555 .num_parents = 1, \
556 .flags = f, \
557 .muxdiv_offset = mo, \
558 .div_shift = 16, \
559 .div_width = 16, \
560 .div_flags = df, \
561 .gate_offset = go, \
562 .gate_shift = gs, \
563 .gate_flags = gf, \
564 }
565
Heiko Stuebner8ca1ca82015-12-22 22:27:59 +0100566#define COMPOSITE_FRACMUX(_id, cname, pname, f, mo, df, go, gs, gf, ch) \
567 { \
568 .id = _id, \
569 .branch_type = branch_fraction_divider, \
570 .name = cname, \
571 .parent_names = (const char *[]){ pname }, \
572 .num_parents = 1, \
573 .flags = f, \
574 .muxdiv_offset = mo, \
575 .div_shift = 16, \
576 .div_width = 16, \
577 .div_flags = df, \
578 .gate_offset = go, \
579 .gate_shift = gs, \
580 .gate_flags = gf, \
Heiko Stübner5b738402015-12-26 14:07:15 +0100581 .child = ch, \
Heiko Stuebner8ca1ca82015-12-22 22:27:59 +0100582 }
583
Xing Zheng9387bfd2016-03-09 10:43:31 +0800584#define COMPOSITE_FRACMUX_NOGATE(_id, cname, pname, f, mo, df, ch) \
585 { \
586 .id = _id, \
587 .branch_type = branch_fraction_divider, \
588 .name = cname, \
589 .parent_names = (const char *[]){ pname }, \
590 .num_parents = 1, \
591 .flags = f, \
592 .muxdiv_offset = mo, \
593 .div_shift = 16, \
594 .div_width = 16, \
595 .div_flags = df, \
596 .gate_offset = -1, \
597 .child = ch, \
598 }
599
Lin Huanga4f182b2016-08-22 11:36:17 +0800600#define COMPOSITE_DDRCLK(_id, cname, pnames, f, mo, ms, mw, \
601 ds, dw, df) \
602 { \
603 .id = _id, \
604 .branch_type = branch_ddrclk, \
605 .name = cname, \
606 .parent_names = pnames, \
607 .num_parents = ARRAY_SIZE(pnames), \
608 .flags = f, \
609 .muxdiv_offset = mo, \
610 .mux_shift = ms, \
611 .mux_width = mw, \
612 .div_shift = ds, \
613 .div_width = dw, \
614 .div_flags = df, \
615 .gate_offset = -1, \
616 }
617
Heiko Stübnera245fec2014-07-03 01:58:39 +0200618#define MUX(_id, cname, pnames, f, o, s, w, mf) \
619 { \
620 .id = _id, \
621 .branch_type = branch_mux, \
622 .name = cname, \
623 .parent_names = pnames, \
624 .num_parents = ARRAY_SIZE(pnames), \
625 .flags = f, \
626 .muxdiv_offset = o, \
627 .mux_shift = s, \
628 .mux_width = w, \
629 .mux_flags = mf, \
630 .gate_offset = -1, \
631 }
632
Heiko Stuebnercb1d9f62016-12-27 00:00:38 +0100633#define MUXGRF(_id, cname, pnames, f, o, s, w, mf) \
634 { \
635 .id = _id, \
636 .branch_type = branch_muxgrf, \
637 .name = cname, \
638 .parent_names = pnames, \
639 .num_parents = ARRAY_SIZE(pnames), \
640 .flags = f, \
641 .muxdiv_offset = o, \
642 .mux_shift = s, \
643 .mux_width = w, \
644 .mux_flags = mf, \
645 .gate_offset = -1, \
646 }
647
Heiko Stübnera245fec2014-07-03 01:58:39 +0200648#define DIV(_id, cname, pname, f, o, s, w, df) \
649 { \
650 .id = _id, \
651 .branch_type = branch_divider, \
652 .name = cname, \
653 .parent_names = (const char *[]){ pname }, \
654 .num_parents = 1, \
655 .flags = f, \
656 .muxdiv_offset = o, \
657 .div_shift = s, \
658 .div_width = w, \
659 .div_flags = df, \
660 .gate_offset = -1, \
661 }
662
663#define DIVTBL(_id, cname, pname, f, o, s, w, df, dt) \
664 { \
665 .id = _id, \
666 .branch_type = branch_divider, \
667 .name = cname, \
668 .parent_names = (const char *[]){ pname }, \
669 .num_parents = 1, \
670 .flags = f, \
671 .muxdiv_offset = o, \
672 .div_shift = s, \
673 .div_width = w, \
674 .div_flags = df, \
675 .div_table = dt, \
676 }
677
678#define GATE(_id, cname, pname, f, o, b, gf) \
679 { \
680 .id = _id, \
681 .branch_type = branch_gate, \
682 .name = cname, \
683 .parent_names = (const char *[]){ pname }, \
684 .num_parents = 1, \
685 .flags = f, \
686 .gate_offset = o, \
687 .gate_shift = b, \
688 .gate_flags = gf, \
689 }
690
Alexandru M Stan89bf26c2014-11-26 17:30:27 -0800691#define MMC(_id, cname, pname, offset, shift) \
692 { \
693 .id = _id, \
694 .branch_type = branch_mmc, \
695 .name = cname, \
696 .parent_names = (const char *[]){ pname }, \
697 .num_parents = 1, \
698 .muxdiv_offset = offset, \
699 .div_shift = shift, \
700 }
Heiko Stübnera245fec2014-07-03 01:58:39 +0200701
Heiko Stuebner8a76f442015-07-05 11:00:14 +0200702#define INVERTER(_id, cname, pname, io, is, if) \
703 { \
704 .id = _id, \
705 .branch_type = branch_inverter, \
706 .name = cname, \
707 .parent_names = (const char *[]){ pname }, \
708 .num_parents = 1, \
709 .muxdiv_offset = io, \
710 .div_shift = is, \
711 .div_flags = if, \
712 }
713
Heiko Stuebner29a30c22015-06-20 13:08:57 +0200714#define FACTOR(_id, cname, pname, f, fm, fd) \
715 { \
716 .id = _id, \
717 .branch_type = branch_factor, \
718 .name = cname, \
719 .parent_names = (const char *[]){ pname }, \
720 .num_parents = 1, \
721 .flags = f, \
722 .div_shift = fm, \
723 .div_width = fd, \
724 }
725
726#define FACTOR_GATE(_id, cname, pname, f, fm, fd, go, gb, gf) \
727 { \
728 .id = _id, \
729 .branch_type = branch_factor, \
730 .name = cname, \
731 .parent_names = (const char *[]){ pname }, \
732 .num_parents = 1, \
733 .flags = f, \
734 .div_shift = fm, \
735 .div_width = fd, \
736 .gate_offset = go, \
737 .gate_shift = gb, \
738 .gate_flags = gf, \
739 }
740
Elaine Zhang956060a2018-06-15 10:16:50 +0800741#define COMPOSITE_HALFDIV(_id, cname, pnames, f, mo, ms, mw, mf, ds, dw,\
742 df, go, gs, gf) \
743 { \
744 .id = _id, \
745 .branch_type = branch_half_divider, \
746 .name = cname, \
747 .parent_names = pnames, \
748 .num_parents = ARRAY_SIZE(pnames), \
749 .flags = f, \
750 .muxdiv_offset = mo, \
751 .mux_shift = ms, \
752 .mux_width = mw, \
753 .mux_flags = mf, \
754 .div_shift = ds, \
755 .div_width = dw, \
756 .div_flags = df, \
757 .gate_offset = go, \
758 .gate_shift = gs, \
759 .gate_flags = gf, \
760 }
761
762#define COMPOSITE_NOGATE_HALFDIV(_id, cname, pnames, f, mo, ms, mw, mf, \
763 ds, dw, df) \
764 { \
765 .id = _id, \
766 .branch_type = branch_half_divider, \
767 .name = cname, \
768 .parent_names = pnames, \
769 .num_parents = ARRAY_SIZE(pnames), \
770 .flags = f, \
771 .muxdiv_offset = mo, \
772 .mux_shift = ms, \
773 .mux_width = mw, \
774 .mux_flags = mf, \
775 .div_shift = ds, \
776 .div_width = dw, \
777 .div_flags = df, \
778 .gate_offset = -1, \
779 }
780
781#define COMPOSITE_NOMUX_HALFDIV(_id, cname, pname, f, mo, ds, dw, df, \
782 go, gs, gf) \
783 { \
784 .id = _id, \
785 .branch_type = branch_half_divider, \
786 .name = cname, \
787 .parent_names = (const char *[]){ pname }, \
788 .num_parents = 1, \
789 .flags = f, \
790 .muxdiv_offset = mo, \
791 .div_shift = ds, \
792 .div_width = dw, \
793 .div_flags = df, \
794 .gate_offset = go, \
795 .gate_shift = gs, \
796 .gate_flags = gf, \
797 }
798
799#define DIV_HALF(_id, cname, pname, f, o, s, w, df) \
800 { \
801 .id = _id, \
802 .branch_type = branch_half_divider, \
803 .name = cname, \
804 .parent_names = (const char *[]){ pname }, \
805 .num_parents = 1, \
806 .flags = f, \
807 .muxdiv_offset = o, \
808 .div_shift = s, \
809 .div_width = w, \
810 .div_flags = df, \
811 .gate_offset = -1, \
812 }
813
Xing Zhengef1d9fe2016-03-09 10:37:04 +0800814struct rockchip_clk_provider *rockchip_clk_init(struct device_node *np,
815 void __iomem *base, unsigned long nr_clks);
816void rockchip_clk_of_add_provider(struct device_node *np,
817 struct rockchip_clk_provider *ctx);
Xing Zhengef1d9fe2016-03-09 10:37:04 +0800818void rockchip_clk_add_lookup(struct rockchip_clk_provider *ctx,
819 struct clk *clk, unsigned int id);
820void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx,
821 struct rockchip_clk_branch *list,
Heiko Stübnera245fec2014-07-03 01:58:39 +0200822 unsigned int nr_clk);
Xing Zhengef1d9fe2016-03-09 10:37:04 +0800823void rockchip_clk_register_plls(struct rockchip_clk_provider *ctx,
824 struct rockchip_pll_clock *pll_list,
Heiko Stübner90c59022014-07-03 01:59:10 +0200825 unsigned int nr_pll, int grf_lock_offset);
Xing Zhengef1d9fe2016-03-09 10:37:04 +0800826void rockchip_clk_register_armclk(struct rockchip_clk_provider *ctx,
827 unsigned int lookup_id, const char *name,
Uwe Kleine-König4a1caed2015-05-28 10:45:51 +0200828 const char *const *parent_names, u8 num_parents,
Heiko Stuebnerf6fba5f2014-09-04 22:10:43 +0200829 const struct rockchip_cpuclk_reg_data *reg_data,
830 const struct rockchip_cpuclk_rate_table *rates,
831 int nrates);
Uwe Kleine-König692d8322015-02-18 10:59:45 +0100832void rockchip_clk_protect_critical(const char *const clocks[], int nclocks);
Xing Zhengef1d9fe2016-03-09 10:37:04 +0800833void rockchip_register_restart_notifier(struct rockchip_clk_provider *ctx,
834 unsigned int reg, void (*cb)(void));
Heiko Stübnera245fec2014-07-03 01:58:39 +0200835
Heiko Stübner85fa0c72014-07-03 01:59:39 +0200836#define ROCKCHIP_SOFTRST_HIWORD_MASK BIT(0)
837
Elaine Zhang956060a2018-06-15 10:16:50 +0800838struct clk *rockchip_clk_register_halfdiv(const char *name,
839 const char *const *parent_names,
840 u8 num_parents, void __iomem *base,
841 int muxdiv_offset, u8 mux_shift,
842 u8 mux_width, u8 mux_flags,
843 u8 div_shift, u8 div_width,
844 u8 div_flags, int gate_offset,
845 u8 gate_shift, u8 gate_flags,
846 unsigned long flags,
847 spinlock_t *lock);
848
Heiko Stübner85fa0c72014-07-03 01:59:39 +0200849#ifdef CONFIG_RESET_CONTROLLER
850void rockchip_register_softrst(struct device_node *np,
851 unsigned int num_regs,
852 void __iomem *base, u8 flags);
853#else
854static inline void rockchip_register_softrst(struct device_node *np,
855 unsigned int num_regs,
856 void __iomem *base, u8 flags)
857{
858}
859#endif
860
Heiko Stübnera245fec2014-07-03 01:58:39 +0200861#endif