blob: d66b26f18ef32369b1475204617f468d578856cc [file] [log] [blame]
Simon Glass932bc4a2015-08-30 16:55:28 -06001/*
2 * (C) Copyright 2015 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0
5 */
6
7#ifndef _ASM_ARCH_CLOCK_H
8#define _ASM_ARCH_CLOCK_H
9
10/* define pll mode */
11#define RKCLK_PLL_MODE_SLOW 0
12#define RKCLK_PLL_MODE_NORMAL 1
13
14enum {
15 ROCKCHIP_SYSCON_NOC,
16 ROCKCHIP_SYSCON_GRF,
17 ROCKCHIP_SYSCON_SGRF,
18 ROCKCHIP_SYSCON_PMU,
19};
20
21/* Standard Rockchip clock numbers */
22enum rk_clk_id {
23 CLK_OSC,
24 CLK_ARM,
25 CLK_DDR,
26 CLK_CODEC,
27 CLK_GENERAL,
28 CLK_NEW,
29
30 CLK_COUNT,
31};
32
33static inline int rk_pll_id(enum rk_clk_id clk_id)
34{
35 return clk_id - 1;
36}
37
38/**
Simon Glassd1c13772015-09-01 19:19:37 -060039 * clk_get_divisor() - Calculate the required clock divisior
40 *
41 * Given an input rate and a required output_rate, calculate the Rockchip
42 * divisor needed to achieve this.
43 *
44 * @input_rate: Input clock rate in Hz
45 * @output_rate: Output clock rate in Hz
46 * @return divisor register value to use
47 */
48static inline u32 clk_get_divisor(ulong input_rate, uint output_rate)
49{
50 uint clk_div;
51
52 clk_div = input_rate / output_rate;
53 clk_div = (clk_div + 1) & 0xfffe;
54
55 return clk_div;
56}
57
58/**
Simon Glass932bc4a2015-08-30 16:55:28 -060059 * rockchip_get_cru() - get a pointer to the clock/reset unit registers
60 *
61 * @return pointer to registers, or -ve error on error
62 */
63void *rockchip_get_cru(void);
64
Simon Glass344f3662016-01-21 19:43:41 -070065/**
66 * rkclk_get_clk() - get a pointer to a given clock
67 *
68 * This is an internal function - use outside the clock subsystem indicates
69 * that work is needed!
70 *
71 * @clk_id: Clock requested
72 * @devp: Returns a pointer to that clock
73 * @return 0 if OK, -ve on error
74 */
75int rkclk_get_clk(enum rk_clk_id clk_id, struct udevice **devp);
76
Simon Glass94906e42016-01-21 19:45:17 -070077struct rk3288_cru;
78struct rk3288_grf;
79
80void rkclk_configure_cpu(struct rk3288_cru *cru, struct rk3288_grf *grf);
81
Simon Glass932bc4a2015-08-30 16:55:28 -060082#endif