blob: 22de0aef8dc0c11c677565eb327bb86e507f72e3 [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
9/* define pll mode */
10#define RKCLK_PLL_MODE_SLOW 0
11#define RKCLK_PLL_MODE_NORMAL 1
Elaine Zhanga8a2ca82019-10-25 09:42:17 +080012#define RKCLK_PLL_MODE_DEEP 2
Simon Glass932bc4a2015-08-30 16:55:28 -060013
14enum {
15 ROCKCHIP_SYSCON_NOC,
16 ROCKCHIP_SYSCON_GRF,
17 ROCKCHIP_SYSCON_SGRF,
18 ROCKCHIP_SYSCON_PMU,
Kever Yange3eba162016-08-16 17:58:10 +080019 ROCKCHIP_SYSCON_PMUGRF,
Kever Yang62d01dc2017-02-13 17:38:59 +080020 ROCKCHIP_SYSCON_PMUSGRF,
21 ROCKCHIP_SYSCON_CIC,
Kever Yang57d4dbf2017-06-23 17:17:52 +080022 ROCKCHIP_SYSCON_MSCH,
Simon Glass932bc4a2015-08-30 16:55:28 -060023};
24
25/* Standard Rockchip clock numbers */
26enum rk_clk_id {
27 CLK_OSC,
28 CLK_ARM,
29 CLK_DDR,
30 CLK_CODEC,
31 CLK_GENERAL,
32 CLK_NEW,
33
34 CLK_COUNT,
35};
36
Elaine Zhanga8a2ca82019-10-25 09:42:17 +080037#define PLL(_type, _id, _con, _mode, _mshift, \
38 _lshift, _pflags, _rtable) \
39 { \
40 .id = _id, \
41 .type = _type, \
42 .con_offset = _con, \
43 .mode_offset = _mode, \
44 .mode_shift = _mshift, \
45 .lock_shift = _lshift, \
46 .pll_flags = _pflags, \
47 .rate_table = _rtable, \
48 }
49
50#define RK3036_PLL_RATE(_rate, _refdiv, _fbdiv, _postdiv1, \
51 _postdiv2, _dsmpd, _frac) \
52{ \
53 .rate = _rate##U, \
54 .fbdiv = _fbdiv, \
55 .postdiv1 = _postdiv1, \
56 .refdiv = _refdiv, \
57 .postdiv2 = _postdiv2, \
58 .dsmpd = _dsmpd, \
59 .frac = _frac, \
60}
61
62struct rockchip_pll_rate_table {
63 unsigned long rate;
64 unsigned int nr;
65 unsigned int nf;
66 unsigned int no;
67 unsigned int nb;
68 /* for RK3036/RK3399 */
69 unsigned int fbdiv;
70 unsigned int postdiv1;
71 unsigned int refdiv;
72 unsigned int postdiv2;
73 unsigned int dsmpd;
74 unsigned int frac;
75};
76
77enum rockchip_pll_type {
78 pll_rk3036,
79 pll_rk3066,
80 pll_rk3328,
81 pll_rk3366,
82 pll_rk3399,
83};
84
85struct rockchip_pll_clock {
86 unsigned int id;
87 unsigned int con_offset;
88 unsigned int mode_offset;
89 unsigned int mode_shift;
90 unsigned int lock_shift;
91 enum rockchip_pll_type type;
92 unsigned int pll_flags;
93 struct rockchip_pll_rate_table *rate_table;
94 unsigned int mode_mask;
95};
96
97struct rockchip_cpu_rate_table {
98 unsigned long rate;
99 unsigned int aclk_div;
100 unsigned int pclk_div;
101};
102
103int rockchip_pll_set_rate(struct rockchip_pll_clock *pll,
104 void __iomem *base, ulong clk_id,
105 ulong drate);
106ulong rockchip_pll_get_rate(struct rockchip_pll_clock *pll,
107 void __iomem *base, ulong clk_id);
108const struct rockchip_cpu_rate_table *
109rockchip_get_cpu_settings(struct rockchip_cpu_rate_table *cpu_table,
110 ulong rate);
111
Simon Glass932bc4a2015-08-30 16:55:28 -0600112static inline int rk_pll_id(enum rk_clk_id clk_id)
113{
114 return clk_id - 1;
115}
116
Kever Yang536dea82017-11-03 15:16:12 +0800117struct sysreset_reg {
118 unsigned int glb_srst_fst_value;
119 unsigned int glb_srst_snd_value;
120};
121
Simon Glass932bc4a2015-08-30 16:55:28 -0600122/**
Simon Glassd1c13772015-09-01 19:19:37 -0600123 * clk_get_divisor() - Calculate the required clock divisior
124 *
125 * Given an input rate and a required output_rate, calculate the Rockchip
126 * divisor needed to achieve this.
127 *
128 * @input_rate: Input clock rate in Hz
129 * @output_rate: Output clock rate in Hz
130 * @return divisor register value to use
131 */
132static inline u32 clk_get_divisor(ulong input_rate, uint output_rate)
133{
134 uint clk_div;
135
136 clk_div = input_rate / output_rate;
137 clk_div = (clk_div + 1) & 0xfffe;
138
139 return clk_div;
140}
141
142/**
Simon Glass932bc4a2015-08-30 16:55:28 -0600143 * rockchip_get_cru() - get a pointer to the clock/reset unit registers
144 *
145 * @return pointer to registers, or -ve error on error
146 */
147void *rockchip_get_cru(void);
148
Kever Yange1980532017-02-13 17:38:56 +0800149/**
150 * rockchip_get_pmucru() - get a pointer to the clock/reset unit registers
151 *
152 * @return pointer to registers, or -ve error on error
153 */
154void *rockchip_get_pmucru(void);
155
Jagan Teki783acfd2020-01-09 14:22:17 +0530156struct rockchip_cru;
Simon Glass94906e42016-01-21 19:45:17 -0700157struct rk3288_grf;
158
Jagan Teki783acfd2020-01-09 14:22:17 +0530159void rk3288_clk_configure_cpu(struct rockchip_cru *cru, struct rk3288_grf *grf);
Simon Glass94906e42016-01-21 19:45:17 -0700160
Simon Glass156b9602016-07-17 15:23:16 -0600161int rockchip_get_clk(struct udevice **devp);
162
Elaine Zhang432976f2017-12-19 18:22:38 +0800163/*
164 * rockchip_reset_bind() - Bind soft reset device as child of clock device
165 *
166 * @pdev: clock udevice
167 * @reg_offset: the first offset in cru for softreset registers
168 * @reg_number: the reg numbers of softreset registers
169 * @return 0 success, or error value
170 */
171int rockchip_reset_bind(struct udevice *pdev, u32 reg_offset, u32 reg_number);
172
Simon Glass932bc4a2015-08-30 16:55:28 -0600173#endif