blob: f01c5aeb71cb5de24a0ba6ca455565cdc7b199c7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Simon Glass932bc4a2015-08-30 16:55:28 -06002/*
3 * (C) Copyright 2015 Google, Inc
Simon Glass932bc4a2015-08-30 16:55:28 -06004 */
5
6#ifndef _ASM_ARCH_CLOCK_H
7#define _ASM_ARCH_CLOCK_H
8
Simon Glass3ba929a2020-10-30 21:38:53 -06009struct udevice;
10
Simon Glass932bc4a2015-08-30 16:55:28 -060011/* define pll mode */
12#define RKCLK_PLL_MODE_SLOW 0
13#define RKCLK_PLL_MODE_NORMAL 1
Elaine Zhanga8a2ca82019-10-25 09:42:17 +080014#define RKCLK_PLL_MODE_DEEP 2
Simon Glass932bc4a2015-08-30 16:55:28 -060015
16enum {
17 ROCKCHIP_SYSCON_NOC,
18 ROCKCHIP_SYSCON_GRF,
19 ROCKCHIP_SYSCON_SGRF,
20 ROCKCHIP_SYSCON_PMU,
Kever Yange3eba162016-08-16 17:58:10 +080021 ROCKCHIP_SYSCON_PMUGRF,
Kever Yang62d01dc2017-02-13 17:38:59 +080022 ROCKCHIP_SYSCON_PMUSGRF,
23 ROCKCHIP_SYSCON_CIC,
Kever Yang57d4dbf2017-06-23 17:17:52 +080024 ROCKCHIP_SYSCON_MSCH,
Jagan Teki7d1bf8d2023-01-30 20:27:37 +053025 ROCKCHIP_SYSCON_USBGRF,
26 ROCKCHIP_SYSCON_PCIE30_PHY_GRF,
27 ROCKCHIP_SYSCON_PHP_GRF,
28 ROCKCHIP_SYSCON_PIPE_PHY0_GRF,
29 ROCKCHIP_SYSCON_PIPE_PHY1_GRF,
30 ROCKCHIP_SYSCON_PIPE_PHY2_GRF,
31 ROCKCHIP_SYSCON_VOP_GRF,
32 ROCKCHIP_SYSCON_VO_GRF,
Simon Glass932bc4a2015-08-30 16:55:28 -060033};
34
35/* Standard Rockchip clock numbers */
36enum rk_clk_id {
37 CLK_OSC,
38 CLK_ARM,
39 CLK_DDR,
40 CLK_CODEC,
41 CLK_GENERAL,
42 CLK_NEW,
43
44 CLK_COUNT,
45};
46
Elaine Zhanga8a2ca82019-10-25 09:42:17 +080047#define PLL(_type, _id, _con, _mode, _mshift, \
48 _lshift, _pflags, _rtable) \
49 { \
50 .id = _id, \
51 .type = _type, \
52 .con_offset = _con, \
53 .mode_offset = _mode, \
54 .mode_shift = _mshift, \
55 .lock_shift = _lshift, \
56 .pll_flags = _pflags, \
57 .rate_table = _rtable, \
58 }
59
60#define RK3036_PLL_RATE(_rate, _refdiv, _fbdiv, _postdiv1, \
61 _postdiv2, _dsmpd, _frac) \
62{ \
63 .rate = _rate##U, \
64 .fbdiv = _fbdiv, \
65 .postdiv1 = _postdiv1, \
66 .refdiv = _refdiv, \
67 .postdiv2 = _postdiv2, \
68 .dsmpd = _dsmpd, \
69 .frac = _frac, \
70}
71
Jagan Teki7d1bf8d2023-01-30 20:27:37 +053072#define RK3588_PLL_RATE(_rate, _p, _m, _s, _k) \
73{ \
74 .rate = _rate##U, \
75 .p = _p, \
76 .m = _m, \
77 .s = _s, \
78 .k = _k, \
79}
80
Elaine Zhanga8a2ca82019-10-25 09:42:17 +080081struct rockchip_pll_rate_table {
82 unsigned long rate;
83 unsigned int nr;
84 unsigned int nf;
85 unsigned int no;
86 unsigned int nb;
87 /* for RK3036/RK3399 */
88 unsigned int fbdiv;
89 unsigned int postdiv1;
90 unsigned int refdiv;
91 unsigned int postdiv2;
92 unsigned int dsmpd;
93 unsigned int frac;
Jagan Teki7d1bf8d2023-01-30 20:27:37 +053094 /* for RK3588 */
95 unsigned int m;
96 unsigned int p;
97 unsigned int s;
98 unsigned int k;
Elaine Zhanga8a2ca82019-10-25 09:42:17 +080099};
100
101enum rockchip_pll_type {
102 pll_rk3036,
103 pll_rk3066,
104 pll_rk3328,
105 pll_rk3366,
106 pll_rk3399,
Jagan Teki7d1bf8d2023-01-30 20:27:37 +0530107 pll_rk3588,
Elaine Zhanga8a2ca82019-10-25 09:42:17 +0800108};
109
110struct rockchip_pll_clock {
111 unsigned int id;
112 unsigned int con_offset;
113 unsigned int mode_offset;
114 unsigned int mode_shift;
115 unsigned int lock_shift;
116 enum rockchip_pll_type type;
117 unsigned int pll_flags;
118 struct rockchip_pll_rate_table *rate_table;
119 unsigned int mode_mask;
120};
121
122struct rockchip_cpu_rate_table {
123 unsigned long rate;
124 unsigned int aclk_div;
125 unsigned int pclk_div;
126};
127
128int rockchip_pll_set_rate(struct rockchip_pll_clock *pll,
129 void __iomem *base, ulong clk_id,
130 ulong drate);
131ulong rockchip_pll_get_rate(struct rockchip_pll_clock *pll,
132 void __iomem *base, ulong clk_id);
133const struct rockchip_cpu_rate_table *
134rockchip_get_cpu_settings(struct rockchip_cpu_rate_table *cpu_table,
135 ulong rate);
136
Simon Glass932bc4a2015-08-30 16:55:28 -0600137static inline int rk_pll_id(enum rk_clk_id clk_id)
138{
139 return clk_id - 1;
140}
141
Kever Yang536dea82017-11-03 15:16:12 +0800142struct sysreset_reg {
143 unsigned int glb_srst_fst_value;
144 unsigned int glb_srst_snd_value;
145};
146
Simon Glass932bc4a2015-08-30 16:55:28 -0600147/**
Simon Glassd1c13772015-09-01 19:19:37 -0600148 * clk_get_divisor() - Calculate the required clock divisior
149 *
150 * Given an input rate and a required output_rate, calculate the Rockchip
151 * divisor needed to achieve this.
152 *
153 * @input_rate: Input clock rate in Hz
154 * @output_rate: Output clock rate in Hz
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100155 * Return: divisor register value to use
Simon Glassd1c13772015-09-01 19:19:37 -0600156 */
157static inline u32 clk_get_divisor(ulong input_rate, uint output_rate)
158{
159 uint clk_div;
160
161 clk_div = input_rate / output_rate;
162 clk_div = (clk_div + 1) & 0xfffe;
163
164 return clk_div;
165}
166
167/**
Simon Glass932bc4a2015-08-30 16:55:28 -0600168 * rockchip_get_cru() - get a pointer to the clock/reset unit registers
169 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100170 * Return: pointer to registers, or -ve error on error
Simon Glass932bc4a2015-08-30 16:55:28 -0600171 */
172void *rockchip_get_cru(void);
173
Kever Yange1980532017-02-13 17:38:56 +0800174/**
175 * rockchip_get_pmucru() - get a pointer to the clock/reset unit registers
176 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100177 * Return: pointer to registers, or -ve error on error
Kever Yange1980532017-02-13 17:38:56 +0800178 */
179void *rockchip_get_pmucru(void);
180
Jagan Teki783acfd2020-01-09 14:22:17 +0530181struct rockchip_cru;
Simon Glass94906e42016-01-21 19:45:17 -0700182struct rk3288_grf;
183
Jagan Teki783acfd2020-01-09 14:22:17 +0530184void rk3288_clk_configure_cpu(struct rockchip_cru *cru, struct rk3288_grf *grf);
Simon Glass94906e42016-01-21 19:45:17 -0700185
Simon Glass156b9602016-07-17 15:23:16 -0600186int rockchip_get_clk(struct udevice **devp);
187
Elaine Zhang432976f2017-12-19 18:22:38 +0800188/*
189 * rockchip_reset_bind() - Bind soft reset device as child of clock device
190 *
191 * @pdev: clock udevice
192 * @reg_offset: the first offset in cru for softreset registers
193 * @reg_number: the reg numbers of softreset registers
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100194 * Return: 0 success, or error value
Elaine Zhang432976f2017-12-19 18:22:38 +0800195 */
196int rockchip_reset_bind(struct udevice *pdev, u32 reg_offset, u32 reg_number);
Eugen Hristev2f550822023-05-15 13:55:04 +0300197/*
198 * rockchip_reset_bind_lut() - Bind soft reset device as child of clock device
199 * using a dedicated SoC lookup table
200 * @pdev: clock udevice
201 * @lookup_table: register lookup_table dedicated to SoC
202 * @reg_offset: the first offset in cru for softreset registers
203 * @reg_number: the reg numbers of softreset registers
204 * Return: 0 success, or error value
205 */
206int rockchip_reset_bind_lut(struct udevice *pdev, const int *lookup_table,
207 u32 reg_offset, u32 reg_number);
208/*
209 * rk3588_reset_bind_lut() - Bind soft reset device as child of clock device
210 * using dedicated RK3588 lookup table
211 *
212 * @pdev: clock udevice
213 * @reg_offset: the first offset in cru for softreset registers
214 * @reg_number: the reg numbers of softreset registers
215 * Return: 0 success, or error value
216 */
217int rk3588_reset_bind_lut(struct udevice *pdev, u32 reg_offset, u32 reg_number);
Elaine Zhang432976f2017-12-19 18:22:38 +0800218
Simon Glass932bc4a2015-08-30 16:55:28 -0600219#endif