xref: /rk3399_rockchip-uboot/arch/arm/include/asm/arch-tegra/clock.h (revision dc89ad1438cd8aa8b2cf508b5e839903fe1231a5)
1150c2493STom Warren /*
2150c2493STom Warren  * Copyright (c) 2011 The Chromium OS Authors.
3150c2493STom Warren  * See file CREDITS for list of people who contributed to this
4150c2493STom Warren  * project.
5150c2493STom Warren  *
6150c2493STom Warren  * This program is free software; you can redistribute it and/or
7150c2493STom Warren  * modify it under the terms of the GNU General Public License as
8150c2493STom Warren  * published by the Free Software Foundation; either version 2 of
9150c2493STom Warren  * the License, or (at your option) any later version.
10150c2493STom Warren  *
11150c2493STom Warren  * This program is distributed in the hope that it will be useful,
12150c2493STom Warren  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13150c2493STom Warren  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14150c2493STom Warren  * GNU General Public License for more details.
15150c2493STom Warren  *
16150c2493STom Warren  * You should have received a copy of the GNU General Public License
17150c2493STom Warren  * along with this program; if not, write to the Free Software
18150c2493STom Warren  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19150c2493STom Warren  * MA 02111-1307 USA
20150c2493STom Warren  */
21150c2493STom Warren 
22150c2493STom Warren /* Tegra clock control functions */
23150c2493STom Warren 
24*dc89ad14STom Warren #ifndef _TEGRA_CLOCK_H_
25*dc89ad14STom Warren #define _TEGRA_CLOCK_H_
26150c2493STom Warren 
27150c2493STom Warren /* Set of oscillator frequencies supported in the internal API. */
28150c2493STom Warren enum clock_osc_freq {
29150c2493STom Warren 	/* All in MHz, so 13_0 is 13.0MHz */
30150c2493STom Warren 	CLOCK_OSC_FREQ_13_0,
31150c2493STom Warren 	CLOCK_OSC_FREQ_19_2,
32150c2493STom Warren 	CLOCK_OSC_FREQ_12_0,
33150c2493STom Warren 	CLOCK_OSC_FREQ_26_0,
34150c2493STom Warren 
35150c2493STom Warren 	CLOCK_OSC_FREQ_COUNT,
36150c2493STom Warren };
37150c2493STom Warren 
38150c2493STom Warren #include <asm/arch/clock-tables.h>
39150c2493STom Warren /* PLL stabilization delay in usec */
40150c2493STom Warren #define CLOCK_PLL_STABLE_DELAY_US 300
41150c2493STom Warren 
42150c2493STom Warren /* return the current oscillator clock frequency */
43150c2493STom Warren enum clock_osc_freq clock_get_osc_freq(void);
44150c2493STom Warren 
45150c2493STom Warren /**
46150c2493STom Warren  * Start PLL using the provided configuration parameters.
47150c2493STom Warren  *
48150c2493STom Warren  * @param id	clock id
49150c2493STom Warren  * @param divm	input divider
50150c2493STom Warren  * @param divn	feedback divider
51150c2493STom Warren  * @param divp	post divider 2^n
52150c2493STom Warren  * @param cpcon	charge pump setup control
53150c2493STom Warren  * @param lfcon	loop filter setup control
54150c2493STom Warren  *
55150c2493STom Warren  * @returns monotonic time in us that the PLL will be stable
56150c2493STom Warren  */
57150c2493STom Warren unsigned long clock_start_pll(enum clock_id id, u32 divm, u32 divn,
58150c2493STom Warren 		u32 divp, u32 cpcon, u32 lfcon);
59150c2493STom Warren 
60150c2493STom Warren /**
6165530a84SLucas Stach  * Set PLL output frequency
6265530a84SLucas Stach  *
6365530a84SLucas Stach  * @param clkid	clock id
6465530a84SLucas Stach  * @param pllout	pll output id
6565530a84SLucas Stach  * @param rate		desired output rate
6665530a84SLucas Stach  *
6765530a84SLucas Stach  * @return 0 if ok, -1 on error (invalid clock id or no suitable divider)
6865530a84SLucas Stach  */
6965530a84SLucas Stach int clock_set_pllout(enum clock_id clkid, enum pll_out_id pllout,
7065530a84SLucas Stach 		unsigned rate);
7165530a84SLucas Stach 
7265530a84SLucas Stach /**
73150c2493STom Warren  * Read low-level parameters of a PLL.
74150c2493STom Warren  *
75150c2493STom Warren  * @param id	clock id to read (note: USB is not supported)
76150c2493STom Warren  * @param divm	returns input divider
77150c2493STom Warren  * @param divn	returns feedback divider
78150c2493STom Warren  * @param divp	returns post divider 2^n
79150c2493STom Warren  * @param cpcon	returns charge pump setup control
80150c2493STom Warren  * @param lfcon	returns loop filter setup control
81150c2493STom Warren  *
82150c2493STom Warren  * @returns 0 if ok, -1 on error (invalid clock id)
83150c2493STom Warren  */
84150c2493STom Warren int clock_ll_read_pll(enum clock_id clkid, u32 *divm, u32 *divn,
85150c2493STom Warren 		      u32 *divp, u32 *cpcon, u32 *lfcon);
86150c2493STom Warren 
87150c2493STom Warren /*
88150c2493STom Warren  * Enable a clock
89150c2493STom Warren  *
90150c2493STom Warren  * @param id	clock id
91150c2493STom Warren  */
92150c2493STom Warren void clock_enable(enum periph_id clkid);
93150c2493STom Warren 
94150c2493STom Warren /*
95150c2493STom Warren  * Disable a clock
96150c2493STom Warren  *
97150c2493STom Warren  * @param id	clock id
98150c2493STom Warren  */
99150c2493STom Warren void clock_disable(enum periph_id clkid);
100150c2493STom Warren 
101150c2493STom Warren /*
102150c2493STom Warren  * Set whether a clock is enabled or disabled.
103150c2493STom Warren  *
104150c2493STom Warren  * @param id		clock id
105150c2493STom Warren  * @param enable	1 to enable, 0 to disable
106150c2493STom Warren  */
107150c2493STom Warren void clock_set_enable(enum periph_id clkid, int enable);
108150c2493STom Warren 
109150c2493STom Warren /**
110150c2493STom Warren  * Reset a peripheral. This puts it in reset, waits for a delay, then takes
111150c2493STom Warren  * it out of reset and waits for th delay again.
112150c2493STom Warren  *
113150c2493STom Warren  * @param periph_id	peripheral to reset
114150c2493STom Warren  * @param us_delay	time to delay in microseconds
115150c2493STom Warren  */
116150c2493STom Warren void reset_periph(enum periph_id periph_id, int us_delay);
117150c2493STom Warren 
118150c2493STom Warren /**
119150c2493STom Warren  * Put a peripheral into or out of reset.
120150c2493STom Warren  *
121150c2493STom Warren  * @param periph_id	peripheral to reset
122150c2493STom Warren  * @param enable	1 to put into reset, 0 to take out of reset
123150c2493STom Warren  */
124150c2493STom Warren void reset_set_enable(enum periph_id periph_id, int enable);
125150c2493STom Warren 
126150c2493STom Warren 
127150c2493STom Warren /* CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET/CLR_0 */
128150c2493STom Warren enum crc_reset_id {
129150c2493STom Warren 	/* Things we can hold in reset for each CPU */
130150c2493STom Warren 	crc_rst_cpu = 1,
131150c2493STom Warren 	crc_rst_de = 1 << 2,	/* What is de? */
132150c2493STom Warren 	crc_rst_watchdog = 1 << 3,
133150c2493STom Warren 	crc_rst_debug = 1 << 4,
134150c2493STom Warren };
135150c2493STom Warren 
136150c2493STom Warren /**
137150c2493STom Warren  * Put parts of the CPU complex into or out of reset.\
138150c2493STom Warren  *
139*dc89ad14STom Warren  * @param cpu		cpu number (0 or 1 on Tegra2, 0-3 on Tegra3)
140150c2493STom Warren  * @param which		which parts of the complex to affect (OR of crc_reset_id)
141150c2493STom Warren  * @param reset		1 to assert reset, 0 to de-assert
142150c2493STom Warren  */
143150c2493STom Warren void reset_cmplx_set_enable(int cpu, int which, int reset);
144150c2493STom Warren 
145150c2493STom Warren /**
146150c2493STom Warren  * Set the source for a peripheral clock. This plus the divisor sets the
147150c2493STom Warren  * clock rate. You need to look up the datasheet to see the meaning of the
148150c2493STom Warren  * source parameter as it changes for each peripheral.
149150c2493STom Warren  *
150150c2493STom Warren  * Warning: This function is only for use pre-relocation. Please use
151150c2493STom Warren  * clock_start_periph_pll() instead.
152150c2493STom Warren  *
153150c2493STom Warren  * @param periph_id	peripheral to adjust
154150c2493STom Warren  * @param source	source clock (0, 1, 2 or 3)
155150c2493STom Warren  */
156150c2493STom Warren void clock_ll_set_source(enum periph_id periph_id, unsigned source);
157150c2493STom Warren 
158150c2493STom Warren /**
159150c2493STom Warren  * Set the source and divisor for a peripheral clock. This sets the
160150c2493STom Warren  * clock rate. You need to look up the datasheet to see the meaning of the
161150c2493STom Warren  * source parameter as it changes for each peripheral.
162150c2493STom Warren  *
163150c2493STom Warren  * Warning: This function is only for use pre-relocation. Please use
164150c2493STom Warren  * clock_start_periph_pll() instead.
165150c2493STom Warren  *
166150c2493STom Warren  * @param periph_id	peripheral to adjust
167150c2493STom Warren  * @param source	source clock (0, 1, 2 or 3)
168150c2493STom Warren  * @param divisor	divisor value to use
169150c2493STom Warren  */
170150c2493STom Warren void clock_ll_set_source_divisor(enum periph_id periph_id, unsigned source,
171150c2493STom Warren 		unsigned divisor);
172150c2493STom Warren 
173150c2493STom Warren /**
174150c2493STom Warren  * Start a peripheral PLL clock at the given rate. This also resets the
175150c2493STom Warren  * peripheral.
176150c2493STom Warren  *
177150c2493STom Warren  * @param periph_id	peripheral to start
178150c2493STom Warren  * @param parent	PLL id of required parent clock
179150c2493STom Warren  * @param rate		Required clock rate in Hz
180150c2493STom Warren  * @return rate selected in Hz, or -1U if something went wrong
181150c2493STom Warren  */
182150c2493STom Warren unsigned clock_start_periph_pll(enum periph_id periph_id,
183150c2493STom Warren 		enum clock_id parent, unsigned rate);
184150c2493STom Warren 
185150c2493STom Warren /**
186150c2493STom Warren  * Returns the rate of a peripheral clock in Hz. Since the caller almost
187150c2493STom Warren  * certainly knows the parent clock (having just set it) we require that
188150c2493STom Warren  * this be passed in so we don't need to work it out.
189150c2493STom Warren  *
190150c2493STom Warren  * @param periph_id	peripheral to start
191150c2493STom Warren  * @param parent	PLL id of parent clock (used to calculate rate, you
192150c2493STom Warren  *			must know this!)
193150c2493STom Warren  * @return clock rate of peripheral in Hz
194150c2493STom Warren  */
195150c2493STom Warren unsigned long clock_get_periph_rate(enum periph_id periph_id,
196150c2493STom Warren 		enum clock_id parent);
197150c2493STom Warren 
198150c2493STom Warren /**
199150c2493STom Warren  * Adjust peripheral PLL clock to the given rate. This does not reset the
200150c2493STom Warren  * peripheral. If a second stage divisor is not available, pass NULL for
201150c2493STom Warren  * extra_div. If it is available, then this parameter will return the
202150c2493STom Warren  * divisor selected (which will be a power of 2 from 1 to 256).
203150c2493STom Warren  *
204150c2493STom Warren  * @param periph_id	peripheral to start
205150c2493STom Warren  * @param parent	PLL id of required parent clock
206150c2493STom Warren  * @param rate		Required clock rate in Hz
207150c2493STom Warren  * @param extra_div	value for the second-stage divisor (NULL if one is
208150c2493STom Warren 			not available)
209150c2493STom Warren  * @return rate selected in Hz, or -1U if something went wrong
210150c2493STom Warren  */
211150c2493STom Warren unsigned clock_adjust_periph_pll_div(enum periph_id periph_id,
212150c2493STom Warren 		enum clock_id parent, unsigned rate, int *extra_div);
213150c2493STom Warren 
214150c2493STom Warren /**
215150c2493STom Warren  * Returns the clock rate of a specified clock, in Hz.
216150c2493STom Warren  *
217150c2493STom Warren  * @param parent	PLL id of clock to check
218150c2493STom Warren  * @return rate of clock in Hz
219150c2493STom Warren  */
220150c2493STom Warren unsigned clock_get_rate(enum clock_id clkid);
221150c2493STom Warren 
222150c2493STom Warren /**
223150c2493STom Warren  * Start up a UART using low-level calls
224150c2493STom Warren  *
225150c2493STom Warren  * Prior to relocation clock_start_periph_pll() cannot be called. This
226150c2493STom Warren  * function provides a way to set up a UART using low-level calls which
227150c2493STom Warren  * do not require BSS.
228150c2493STom Warren  *
229150c2493STom Warren  * @param periph_id	Peripheral ID of UART to enable (e,g, PERIPH_ID_UART1)
230150c2493STom Warren  */
231150c2493STom Warren void clock_ll_start_uart(enum periph_id periph_id);
232150c2493STom Warren 
233150c2493STom Warren /**
234150c2493STom Warren  * Decode a peripheral ID from a device tree node.
235150c2493STom Warren  *
236150c2493STom Warren  * This works by looking up the peripheral's 'clocks' node and reading out
237150c2493STom Warren  * the second cell, which is the clock number / peripheral ID.
238150c2493STom Warren  *
239150c2493STom Warren  * @param blob		FDT blob to use
240150c2493STom Warren  * @param node		Node to look at
241150c2493STom Warren  * @return peripheral ID, or PERIPH_ID_NONE if none
242150c2493STom Warren  */
243150c2493STom Warren enum periph_id clock_decode_periph_id(const void *blob, int node);
244150c2493STom Warren 
245150c2493STom Warren /**
246150c2493STom Warren  * Checks if the oscillator bypass is enabled (XOBP bit)
247150c2493STom Warren  *
248150c2493STom Warren  * @return 1 if bypass is enabled, 0 if not
249150c2493STom Warren  */
250150c2493STom Warren int clock_get_osc_bypass(void);
251150c2493STom Warren 
252150c2493STom Warren /*
253150c2493STom Warren  * Checks that clocks are valid and prints a warning if not
254150c2493STom Warren  *
255150c2493STom Warren  * @return 0 if ok, -1 on error
256150c2493STom Warren  */
257150c2493STom Warren int clock_verify(void);
258150c2493STom Warren 
259150c2493STom Warren /* Initialize the clocks */
260150c2493STom Warren void clock_init(void);
261150c2493STom Warren 
262150c2493STom Warren /* Initialize the PLLs */
263150c2493STom Warren void clock_early_init(void);
264150c2493STom Warren 
265*dc89ad14STom Warren #endif	/* _TEGRA_CLOCK_H_ */
266