Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Simon Glass | 932bc4a | 2015-08-30 16:55:28 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 Google, Inc |
Simon Glass | 932bc4a | 2015-08-30 16:55:28 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _ASM_ARCH_CLOCK_H |
| 7 | #define _ASM_ARCH_CLOCK_H |
| 8 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 9 | #include <linux/types.h> |
| 10 | |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | struct udevice; |
| 12 | |
Simon Glass | 932bc4a | 2015-08-30 16:55:28 -0600 | [diff] [blame] | 13 | /* define pll mode */ |
| 14 | #define RKCLK_PLL_MODE_SLOW 0 |
| 15 | #define RKCLK_PLL_MODE_NORMAL 1 |
Elaine Zhang | a8a2ca8 | 2019-10-25 09:42:17 +0800 | [diff] [blame] | 16 | #define RKCLK_PLL_MODE_DEEP 2 |
Simon Glass | 932bc4a | 2015-08-30 16:55:28 -0600 | [diff] [blame] | 17 | |
| 18 | enum { |
| 19 | ROCKCHIP_SYSCON_NOC, |
| 20 | ROCKCHIP_SYSCON_GRF, |
| 21 | ROCKCHIP_SYSCON_SGRF, |
| 22 | ROCKCHIP_SYSCON_PMU, |
Kever Yang | e3eba16 | 2016-08-16 17:58:10 +0800 | [diff] [blame] | 23 | ROCKCHIP_SYSCON_PMUGRF, |
Kever Yang | 62d01dc | 2017-02-13 17:38:59 +0800 | [diff] [blame] | 24 | ROCKCHIP_SYSCON_PMUSGRF, |
| 25 | ROCKCHIP_SYSCON_CIC, |
Kever Yang | 57d4dbf | 2017-06-23 17:17:52 +0800 | [diff] [blame] | 26 | ROCKCHIP_SYSCON_MSCH, |
Jagan Teki | 7d1bf8d | 2023-01-30 20:27:37 +0530 | [diff] [blame] | 27 | 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 Glass | 932bc4a | 2015-08-30 16:55:28 -0600 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | /* Standard Rockchip clock numbers */ |
| 38 | enum 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 Zhang | a8a2ca8 | 2019-10-25 09:42:17 +0800 | [diff] [blame] | 49 | #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 Teki | 7d1bf8d | 2023-01-30 20:27:37 +0530 | [diff] [blame] | 74 | #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 Zhang | a8a2ca8 | 2019-10-25 09:42:17 +0800 | [diff] [blame] | 83 | struct 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 Teki | 7d1bf8d | 2023-01-30 20:27:37 +0530 | [diff] [blame] | 96 | /* for RK3588 */ |
| 97 | unsigned int m; |
| 98 | unsigned int p; |
| 99 | unsigned int s; |
| 100 | unsigned int k; |
Elaine Zhang | a8a2ca8 | 2019-10-25 09:42:17 +0800 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | enum rockchip_pll_type { |
| 104 | pll_rk3036, |
| 105 | pll_rk3066, |
| 106 | pll_rk3328, |
| 107 | pll_rk3366, |
| 108 | pll_rk3399, |
Jagan Teki | 7d1bf8d | 2023-01-30 20:27:37 +0530 | [diff] [blame] | 109 | pll_rk3588, |
Elaine Zhang | a8a2ca8 | 2019-10-25 09:42:17 +0800 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | struct 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 | |
| 124 | struct rockchip_cpu_rate_table { |
| 125 | unsigned long rate; |
| 126 | unsigned int aclk_div; |
| 127 | unsigned int pclk_div; |
| 128 | }; |
| 129 | |
| 130 | int rockchip_pll_set_rate(struct rockchip_pll_clock *pll, |
| 131 | void __iomem *base, ulong clk_id, |
| 132 | ulong drate); |
| 133 | ulong rockchip_pll_get_rate(struct rockchip_pll_clock *pll, |
| 134 | void __iomem *base, ulong clk_id); |
| 135 | const struct rockchip_cpu_rate_table * |
| 136 | rockchip_get_cpu_settings(struct rockchip_cpu_rate_table *cpu_table, |
| 137 | ulong rate); |
| 138 | |
Simon Glass | 932bc4a | 2015-08-30 16:55:28 -0600 | [diff] [blame] | 139 | static inline int rk_pll_id(enum rk_clk_id clk_id) |
| 140 | { |
| 141 | return clk_id - 1; |
| 142 | } |
| 143 | |
Kever Yang | 536dea8 | 2017-11-03 15:16:12 +0800 | [diff] [blame] | 144 | struct sysreset_reg { |
| 145 | unsigned int glb_srst_fst_value; |
| 146 | unsigned int glb_srst_snd_value; |
| 147 | }; |
| 148 | |
Simon Glass | 932bc4a | 2015-08-30 16:55:28 -0600 | [diff] [blame] | 149 | /** |
Simon Glass | d1c1377 | 2015-09-01 19:19:37 -0600 | [diff] [blame] | 150 | * 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 Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 157 | * Return: divisor register value to use |
Simon Glass | d1c1377 | 2015-09-01 19:19:37 -0600 | [diff] [blame] | 158 | */ |
| 159 | static 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 Glass | 932bc4a | 2015-08-30 16:55:28 -0600 | [diff] [blame] | 170 | * rockchip_get_cru() - get a pointer to the clock/reset unit registers |
| 171 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 172 | * Return: pointer to registers, or -ve error on error |
Simon Glass | 932bc4a | 2015-08-30 16:55:28 -0600 | [diff] [blame] | 173 | */ |
| 174 | void *rockchip_get_cru(void); |
| 175 | |
Kever Yang | e198053 | 2017-02-13 17:38:56 +0800 | [diff] [blame] | 176 | /** |
| 177 | * rockchip_get_pmucru() - get a pointer to the clock/reset unit registers |
| 178 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 179 | * Return: pointer to registers, or -ve error on error |
Kever Yang | e198053 | 2017-02-13 17:38:56 +0800 | [diff] [blame] | 180 | */ |
| 181 | void *rockchip_get_pmucru(void); |
| 182 | |
Jagan Teki | 783acfd | 2020-01-09 14:22:17 +0530 | [diff] [blame] | 183 | struct rockchip_cru; |
Simon Glass | 94906e4 | 2016-01-21 19:45:17 -0700 | [diff] [blame] | 184 | struct rk3288_grf; |
| 185 | |
Jagan Teki | 783acfd | 2020-01-09 14:22:17 +0530 | [diff] [blame] | 186 | void rk3288_clk_configure_cpu(struct rockchip_cru *cru, struct rk3288_grf *grf); |
Simon Glass | 94906e4 | 2016-01-21 19:45:17 -0700 | [diff] [blame] | 187 | |
Simon Glass | 156b960 | 2016-07-17 15:23:16 -0600 | [diff] [blame] | 188 | int rockchip_get_clk(struct udevice **devp); |
| 189 | |
Elaine Zhang | 432976f | 2017-12-19 18:22:38 +0800 | [diff] [blame] | 190 | /* |
| 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 Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 196 | * Return: 0 success, or error value |
Elaine Zhang | 432976f | 2017-12-19 18:22:38 +0800 | [diff] [blame] | 197 | */ |
| 198 | int rockchip_reset_bind(struct udevice *pdev, u32 reg_offset, u32 reg_number); |
Eugen Hristev | 2f55082 | 2023-05-15 13:55:04 +0300 | [diff] [blame] | 199 | /* |
| 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 | */ |
| 208 | int 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 | */ |
| 219 | int rk3588_reset_bind_lut(struct udevice *pdev, u32 reg_offset, u32 reg_number); |
Elaine Zhang | 432976f | 2017-12-19 18:22:38 +0800 | [diff] [blame] | 220 | |
Simon Glass | 932bc4a | 2015-08-30 16:55:28 -0600 | [diff] [blame] | 221 | #endif |