1 /* SPDX-License-Identifier: GPL-2.0 */
3 * (C) Copyright 2015 Google, Inc
6 #ifndef _ASM_ARCH_CLOCK_H
7 #define _ASM_ARCH_CLOCK_H
12 #define RKCLK_PLL_MODE_SLOW 0
13 #define RKCLK_PLL_MODE_NORMAL 1
14 #define RKCLK_PLL_MODE_DEEP 2
21 ROCKCHIP_SYSCON_PMUGRF,
22 ROCKCHIP_SYSCON_PMUSGRF,
27 /* Standard Rockchip clock numbers */
39 #define PLL(_type, _id, _con, _mode, _mshift, \
40 _lshift, _pflags, _rtable) \
45 .mode_offset = _mode, \
46 .mode_shift = _mshift, \
47 .lock_shift = _lshift, \
48 .pll_flags = _pflags, \
49 .rate_table = _rtable, \
52 #define RK3036_PLL_RATE(_rate, _refdiv, _fbdiv, _postdiv1, \
53 _postdiv2, _dsmpd, _frac) \
57 .postdiv1 = _postdiv1, \
59 .postdiv2 = _postdiv2, \
64 struct rockchip_pll_rate_table {
70 /* for RK3036/RK3399 */
72 unsigned int postdiv1;
74 unsigned int postdiv2;
79 enum rockchip_pll_type {
87 struct rockchip_pll_clock {
89 unsigned int con_offset;
90 unsigned int mode_offset;
91 unsigned int mode_shift;
92 unsigned int lock_shift;
93 enum rockchip_pll_type type;
94 unsigned int pll_flags;
95 struct rockchip_pll_rate_table *rate_table;
96 unsigned int mode_mask;
99 struct rockchip_cpu_rate_table {
101 unsigned int aclk_div;
102 unsigned int pclk_div;
105 int rockchip_pll_set_rate(struct rockchip_pll_clock *pll,
106 void __iomem *base, ulong clk_id,
108 ulong rockchip_pll_get_rate(struct rockchip_pll_clock *pll,
109 void __iomem *base, ulong clk_id);
110 const struct rockchip_cpu_rate_table *
111 rockchip_get_cpu_settings(struct rockchip_cpu_rate_table *cpu_table,
114 static inline int rk_pll_id(enum rk_clk_id clk_id)
119 struct sysreset_reg {
120 unsigned int glb_srst_fst_value;
121 unsigned int glb_srst_snd_value;
125 * clk_get_divisor() - Calculate the required clock divisior
127 * Given an input rate and a required output_rate, calculate the Rockchip
128 * divisor needed to achieve this.
130 * @input_rate: Input clock rate in Hz
131 * @output_rate: Output clock rate in Hz
132 * @return divisor register value to use
134 static inline u32 clk_get_divisor(ulong input_rate, uint output_rate)
138 clk_div = input_rate / output_rate;
139 clk_div = (clk_div + 1) & 0xfffe;
145 * rockchip_get_cru() - get a pointer to the clock/reset unit registers
147 * @return pointer to registers, or -ve error on error
149 void *rockchip_get_cru(void);
152 * rockchip_get_pmucru() - get a pointer to the clock/reset unit registers
154 * @return pointer to registers, or -ve error on error
156 void *rockchip_get_pmucru(void);
161 void rk3288_clk_configure_cpu(struct rockchip_cru *cru, struct rk3288_grf *grf);
163 int rockchip_get_clk(struct udevice **devp);
166 * rockchip_reset_bind() - Bind soft reset device as child of clock device
168 * @pdev: clock udevice
169 * @reg_offset: the first offset in cru for softreset registers
170 * @reg_number: the reg numbers of softreset registers
171 * @return 0 success, or error value
173 int rockchip_reset_bind(struct udevice *pdev, u32 reg_offset, u32 reg_number);