blob: 73e5283108b146ca2d80d39bddc02aaaee921df4 [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
Tom Rinidec7ea02024-05-20 13:35:03 -06009#include <linux/types.h>
10
Simon Glass3ba929a2020-10-30 21:38:53 -060011struct udevice;
12
Simon Glass932bc4a2015-08-30 16:55:28 -060013/* define pll mode */
14#define RKCLK_PLL_MODE_SLOW 0
15#define RKCLK_PLL_MODE_NORMAL 1
Elaine Zhanga8a2ca82019-10-25 09:42:17 +080016#define RKCLK_PLL_MODE_DEEP 2
Simon Glass932bc4a2015-08-30 16:55:28 -060017
18enum {
19 ROCKCHIP_SYSCON_NOC,
20 ROCKCHIP_SYSCON_GRF,
21 ROCKCHIP_SYSCON_SGRF,
22 ROCKCHIP_SYSCON_PMU,
Kever Yange3eba162016-08-16 17:58:10 +080023 ROCKCHIP_SYSCON_PMUGRF,
Kever Yang62d01dc2017-02-13 17:38:59 +080024 ROCKCHIP_SYSCON_PMUSGRF,
25 ROCKCHIP_SYSCON_CIC,
Kever Yang57d4dbf2017-06-23 17:17:52 +080026 ROCKCHIP_SYSCON_MSCH,
Jagan Teki7d1bf8d2023-01-30 20:27:37 +053027 ROCKCHIP_SYSCON_USBGRF,
28 ROCKCHIP_SYSCON_PCIE30_PHY_GRF,
29 ROCKCHIP_SYSCON_PHP_GRF,
30 ROCKCHIP_SYSCON_PIPE_PHY0_GRF,
31 ROCKCHIP_SYSCON_PIPE_PHY1_GRF,
32 ROCKCHIP_SYSCON_PIPE_PHY2_GRF,
33 ROCKCHIP_SYSCON_VOP_GRF,
34 ROCKCHIP_SYSCON_VO_GRF,
Simon Glass932bc4a2015-08-30 16:55:28 -060035};
36
37/* Standard Rockchip clock numbers */
38enum rk_clk_id {
39 CLK_OSC,
40 CLK_ARM,
41 CLK_DDR,
42 CLK_CODEC,
43 CLK_GENERAL,
44 CLK_NEW,
45
46 CLK_COUNT,
47};
48
Elaine Zhanga8a2ca82019-10-25 09:42:17 +080049#define PLL(_type, _id, _con, _mode, _mshift, \
50 _lshift, _pflags, _rtable) \
51 { \
52 .id = _id, \
53 .type = _type, \
54 .con_offset = _con, \
55 .mode_offset = _mode, \
56 .mode_shift = _mshift, \
57 .lock_shift = _lshift, \
58 .pll_flags = _pflags, \
59 .rate_table = _rtable, \
60 }
61
62#define RK3036_PLL_RATE(_rate, _refdiv, _fbdiv, _postdiv1, \
63 _postdiv2, _dsmpd, _frac) \
64{ \
65 .rate = _rate##U, \
66 .fbdiv = _fbdiv, \
67 .postdiv1 = _postdiv1, \
68 .refdiv = _refdiv, \
69 .postdiv2 = _postdiv2, \
70 .dsmpd = _dsmpd, \
71 .frac = _frac, \
72}
73
Jagan Teki7d1bf8d2023-01-30 20:27:37 +053074#define RK3588_PLL_RATE(_rate, _p, _m, _s, _k) \
75{ \
76 .rate = _rate##U, \
77 .p = _p, \
78 .m = _m, \
79 .s = _s, \
80 .k = _k, \
81}
82
Elaine Zhanga8a2ca82019-10-25 09:42:17 +080083struct rockchip_pll_rate_table {
84 unsigned long rate;
85 unsigned int nr;
86 unsigned int nf;
87 unsigned int no;
88 unsigned int nb;
89 /* for RK3036/RK3399 */
90 unsigned int fbdiv;
91 unsigned int postdiv1;
92 unsigned int refdiv;
93 unsigned int postdiv2;
94 unsigned int dsmpd;
95 unsigned int frac;
Jagan Teki7d1bf8d2023-01-30 20:27:37 +053096 /* for RK3588 */
97 unsigned int m;
98 unsigned int p;
99 unsigned int s;
100 unsigned int k;
Elaine Zhanga8a2ca82019-10-25 09:42:17 +0800101};
102
103enum rockchip_pll_type {
104 pll_rk3036,
105 pll_rk3066,
106 pll_rk3328,
107 pll_rk3366,
108 pll_rk3399,
Jagan Teki7d1bf8d2023-01-30 20:27:37 +0530109 pll_rk3588,
Elaine Zhanga8a2ca82019-10-25 09:42:17 +0800110};
111
112struct rockchip_pll_clock {
113 unsigned int id;
114 unsigned int con_offset;
115 unsigned int mode_offset;
116 unsigned int mode_shift;
117 unsigned int lock_shift;
118 enum rockchip_pll_type type;
119 unsigned int pll_flags;
120 struct rockchip_pll_rate_table *rate_table;
121 unsigned int mode_mask;
122};
123
124struct rockchip_cpu_rate_table {
125 unsigned long rate;
126 unsigned int aclk_div;
127 unsigned int pclk_div;
128};
129
130int rockchip_pll_set_rate(struct rockchip_pll_clock *pll,
131 void __iomem *base, ulong clk_id,
132 ulong drate);
133ulong rockchip_pll_get_rate(struct rockchip_pll_clock *pll,
134 void __iomem *base, ulong clk_id);
135const struct rockchip_cpu_rate_table *
136rockchip_get_cpu_settings(struct rockchip_cpu_rate_table *cpu_table,
137 ulong rate);
138
Simon Glass932bc4a2015-08-30 16:55:28 -0600139static inline int rk_pll_id(enum rk_clk_id clk_id)
140{
141 return clk_id - 1;
142}
143
Kever Yang536dea82017-11-03 15:16:12 +0800144struct sysreset_reg {
145 unsigned int glb_srst_fst_value;
146 unsigned int glb_srst_snd_value;
147};
148
Simon Glass932bc4a2015-08-30 16:55:28 -0600149/**
Simon Glassd1c13772015-09-01 19:19:37 -0600150 * clk_get_divisor() - Calculate the required clock divisior
151 *
152 * Given an input rate and a required output_rate, calculate the Rockchip
153 * divisor needed to achieve this.
154 *
155 * @input_rate: Input clock rate in Hz
156 * @output_rate: Output clock rate in Hz
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100157 * Return: divisor register value to use
Simon Glassd1c13772015-09-01 19:19:37 -0600158 */
159static inline u32 clk_get_divisor(ulong input_rate, uint output_rate)
160{
161 uint clk_div;
162
163 clk_div = input_rate / output_rate;
164 clk_div = (clk_div + 1) & 0xfffe;
165
166 return clk_div;
167}
168
169/**
Simon Glass932bc4a2015-08-30 16:55:28 -0600170 * rockchip_get_cru() - get a pointer to the clock/reset unit registers
171 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100172 * Return: pointer to registers, or -ve error on error
Simon Glass932bc4a2015-08-30 16:55:28 -0600173 */
174void *rockchip_get_cru(void);
175
Kever Yange1980532017-02-13 17:38:56 +0800176/**
177 * rockchip_get_pmucru() - get a pointer to the clock/reset unit registers
178 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100179 * Return: pointer to registers, or -ve error on error
Kever Yange1980532017-02-13 17:38:56 +0800180 */
181void *rockchip_get_pmucru(void);
182
Jagan Teki783acfd2020-01-09 14:22:17 +0530183struct rockchip_cru;
Simon Glass94906e42016-01-21 19:45:17 -0700184struct rk3288_grf;
185
Jagan Teki783acfd2020-01-09 14:22:17 +0530186void rk3288_clk_configure_cpu(struct rockchip_cru *cru, struct rk3288_grf *grf);
Simon Glass94906e42016-01-21 19:45:17 -0700187
Simon Glass156b9602016-07-17 15:23:16 -0600188int rockchip_get_clk(struct udevice **devp);
189
Elaine Zhang432976f2017-12-19 18:22:38 +0800190/*
191 * rockchip_reset_bind() - Bind soft reset device as child of clock device
192 *
193 * @pdev: clock udevice
194 * @reg_offset: the first offset in cru for softreset registers
195 * @reg_number: the reg numbers of softreset registers
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100196 * Return: 0 success, or error value
Elaine Zhang432976f2017-12-19 18:22:38 +0800197 */
198int rockchip_reset_bind(struct udevice *pdev, u32 reg_offset, u32 reg_number);
Eugen Hristev2f550822023-05-15 13:55:04 +0300199/*
200 * rockchip_reset_bind_lut() - Bind soft reset device as child of clock device
201 * using a dedicated SoC lookup table
202 * @pdev: clock udevice
203 * @lookup_table: register lookup_table dedicated to SoC
204 * @reg_offset: the first offset in cru for softreset registers
205 * @reg_number: the reg numbers of softreset registers
206 * Return: 0 success, or error value
207 */
208int rockchip_reset_bind_lut(struct udevice *pdev, const int *lookup_table,
209 u32 reg_offset, u32 reg_number);
210/*
211 * rk3588_reset_bind_lut() - Bind soft reset device as child of clock device
212 * using dedicated RK3588 lookup table
213 *
214 * @pdev: clock udevice
215 * @reg_offset: the first offset in cru for softreset registers
216 * @reg_number: the reg numbers of softreset registers
217 * Return: 0 success, or error value
218 */
219int rk3588_reset_bind_lut(struct udevice *pdev, u32 reg_offset, u32 reg_number);
Elaine Zhang432976f2017-12-19 18:22:38 +0800220
Simon Glass932bc4a2015-08-30 16:55:28 -0600221#endif