2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2015-08-30 22:55:28 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2015 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ASM_ARCH_CLOCK_H
|
|
|
|
#define _ASM_ARCH_CLOCK_H
|
|
|
|
|
|
|
|
/* define pll mode */
|
|
|
|
#define RKCLK_PLL_MODE_SLOW 0
|
|
|
|
#define RKCLK_PLL_MODE_NORMAL 1
|
2019-10-25 01:42:17 +00:00
|
|
|
#define RKCLK_PLL_MODE_DEEP 2
|
2015-08-30 22:55:28 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
ROCKCHIP_SYSCON_NOC,
|
|
|
|
ROCKCHIP_SYSCON_GRF,
|
|
|
|
ROCKCHIP_SYSCON_SGRF,
|
|
|
|
ROCKCHIP_SYSCON_PMU,
|
2016-08-16 09:58:10 +00:00
|
|
|
ROCKCHIP_SYSCON_PMUGRF,
|
2017-02-13 09:38:59 +00:00
|
|
|
ROCKCHIP_SYSCON_PMUSGRF,
|
|
|
|
ROCKCHIP_SYSCON_CIC,
|
2017-06-23 09:17:52 +00:00
|
|
|
ROCKCHIP_SYSCON_MSCH,
|
2015-08-30 22:55:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Standard Rockchip clock numbers */
|
|
|
|
enum rk_clk_id {
|
|
|
|
CLK_OSC,
|
|
|
|
CLK_ARM,
|
|
|
|
CLK_DDR,
|
|
|
|
CLK_CODEC,
|
|
|
|
CLK_GENERAL,
|
|
|
|
CLK_NEW,
|
|
|
|
|
|
|
|
CLK_COUNT,
|
|
|
|
};
|
|
|
|
|
2019-10-25 01:42:17 +00:00
|
|
|
#define PLL(_type, _id, _con, _mode, _mshift, \
|
|
|
|
_lshift, _pflags, _rtable) \
|
|
|
|
{ \
|
|
|
|
.id = _id, \
|
|
|
|
.type = _type, \
|
|
|
|
.con_offset = _con, \
|
|
|
|
.mode_offset = _mode, \
|
|
|
|
.mode_shift = _mshift, \
|
|
|
|
.lock_shift = _lshift, \
|
|
|
|
.pll_flags = _pflags, \
|
|
|
|
.rate_table = _rtable, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RK3036_PLL_RATE(_rate, _refdiv, _fbdiv, _postdiv1, \
|
|
|
|
_postdiv2, _dsmpd, _frac) \
|
|
|
|
{ \
|
|
|
|
.rate = _rate##U, \
|
|
|
|
.fbdiv = _fbdiv, \
|
|
|
|
.postdiv1 = _postdiv1, \
|
|
|
|
.refdiv = _refdiv, \
|
|
|
|
.postdiv2 = _postdiv2, \
|
|
|
|
.dsmpd = _dsmpd, \
|
|
|
|
.frac = _frac, \
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rockchip_pll_rate_table {
|
|
|
|
unsigned long rate;
|
|
|
|
unsigned int nr;
|
|
|
|
unsigned int nf;
|
|
|
|
unsigned int no;
|
|
|
|
unsigned int nb;
|
|
|
|
/* for RK3036/RK3399 */
|
|
|
|
unsigned int fbdiv;
|
|
|
|
unsigned int postdiv1;
|
|
|
|
unsigned int refdiv;
|
|
|
|
unsigned int postdiv2;
|
|
|
|
unsigned int dsmpd;
|
|
|
|
unsigned int frac;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum rockchip_pll_type {
|
|
|
|
pll_rk3036,
|
|
|
|
pll_rk3066,
|
|
|
|
pll_rk3328,
|
|
|
|
pll_rk3366,
|
|
|
|
pll_rk3399,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rockchip_pll_clock {
|
|
|
|
unsigned int id;
|
|
|
|
unsigned int con_offset;
|
|
|
|
unsigned int mode_offset;
|
|
|
|
unsigned int mode_shift;
|
|
|
|
unsigned int lock_shift;
|
|
|
|
enum rockchip_pll_type type;
|
|
|
|
unsigned int pll_flags;
|
|
|
|
struct rockchip_pll_rate_table *rate_table;
|
|
|
|
unsigned int mode_mask;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rockchip_cpu_rate_table {
|
|
|
|
unsigned long rate;
|
|
|
|
unsigned int aclk_div;
|
|
|
|
unsigned int pclk_div;
|
|
|
|
};
|
|
|
|
|
|
|
|
int rockchip_pll_set_rate(struct rockchip_pll_clock *pll,
|
|
|
|
void __iomem *base, ulong clk_id,
|
|
|
|
ulong drate);
|
|
|
|
ulong rockchip_pll_get_rate(struct rockchip_pll_clock *pll,
|
|
|
|
void __iomem *base, ulong clk_id);
|
|
|
|
const struct rockchip_cpu_rate_table *
|
|
|
|
rockchip_get_cpu_settings(struct rockchip_cpu_rate_table *cpu_table,
|
|
|
|
ulong rate);
|
|
|
|
|
2015-08-30 22:55:28 +00:00
|
|
|
static inline int rk_pll_id(enum rk_clk_id clk_id)
|
|
|
|
{
|
|
|
|
return clk_id - 1;
|
|
|
|
}
|
|
|
|
|
2017-11-03 07:16:12 +00:00
|
|
|
struct sysreset_reg {
|
|
|
|
unsigned int glb_srst_fst_value;
|
|
|
|
unsigned int glb_srst_snd_value;
|
|
|
|
};
|
|
|
|
|
2015-09-02 01:19:37 +00:00
|
|
|
/**
|
|
|
|
* clk_get_divisor() - Calculate the required clock divisior
|
|
|
|
*
|
|
|
|
* Given an input rate and a required output_rate, calculate the Rockchip
|
|
|
|
* divisor needed to achieve this.
|
|
|
|
*
|
|
|
|
* @input_rate: Input clock rate in Hz
|
|
|
|
* @output_rate: Output clock rate in Hz
|
|
|
|
* @return divisor register value to use
|
|
|
|
*/
|
|
|
|
static inline u32 clk_get_divisor(ulong input_rate, uint output_rate)
|
|
|
|
{
|
|
|
|
uint clk_div;
|
|
|
|
|
|
|
|
clk_div = input_rate / output_rate;
|
|
|
|
clk_div = (clk_div + 1) & 0xfffe;
|
|
|
|
|
|
|
|
return clk_div;
|
|
|
|
}
|
|
|
|
|
2015-08-30 22:55:28 +00:00
|
|
|
/**
|
|
|
|
* rockchip_get_cru() - get a pointer to the clock/reset unit registers
|
|
|
|
*
|
|
|
|
* @return pointer to registers, or -ve error on error
|
|
|
|
*/
|
|
|
|
void *rockchip_get_cru(void);
|
|
|
|
|
2017-02-13 09:38:56 +00:00
|
|
|
/**
|
|
|
|
* rockchip_get_pmucru() - get a pointer to the clock/reset unit registers
|
|
|
|
*
|
|
|
|
* @return pointer to registers, or -ve error on error
|
|
|
|
*/
|
|
|
|
void *rockchip_get_pmucru(void);
|
|
|
|
|
2020-01-09 08:52:17 +00:00
|
|
|
struct rockchip_cru;
|
2016-01-22 02:45:17 +00:00
|
|
|
struct rk3288_grf;
|
|
|
|
|
2020-01-09 08:52:17 +00:00
|
|
|
void rk3288_clk_configure_cpu(struct rockchip_cru *cru, struct rk3288_grf *grf);
|
2016-01-22 02:45:17 +00:00
|
|
|
|
2016-07-17 21:23:16 +00:00
|
|
|
int rockchip_get_clk(struct udevice **devp);
|
|
|
|
|
2017-12-19 10:22:38 +00:00
|
|
|
/*
|
|
|
|
* rockchip_reset_bind() - Bind soft reset device as child of clock device
|
|
|
|
*
|
|
|
|
* @pdev: clock udevice
|
|
|
|
* @reg_offset: the first offset in cru for softreset registers
|
|
|
|
* @reg_number: the reg numbers of softreset registers
|
|
|
|
* @return 0 success, or error value
|
|
|
|
*/
|
|
|
|
int rockchip_reset_bind(struct udevice *pdev, u32 reg_offset, u32 reg_number);
|
|
|
|
|
2015-08-30 22:55:28 +00:00
|
|
|
#endif
|