2 * Copyright (c) 2011 The Chromium OS Authors.
3 * See file CREDITS for list of people who contributed to this
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 /* Tegra2 clock control functions */
27 /* Set of oscillator frequencies supported in the internal API. */
29 /* All in MHz, so 13_0 is 13.0MHz */
38 /* The PLLs supported by the hardware */
41 CLOCK_ID_CGENERAL = CLOCK_ID_FIRST,
48 /* now the simple ones */
49 CLOCK_ID_FIRST_SIMPLE,
50 CLOCK_ID_XCPU = CLOCK_ID_FIRST_SIMPLE,
54 /* These are the base clocks (inputs to the Tegra SOC) */
58 CLOCK_ID_COUNT, /* number of clocks */
62 /* The clocks supported by the hardware */
67 PERIPH_ID_CPU = PERIPH_ID_FIRST,
103 PERIPH_ID_RESERVED30,
106 /* Middle word: 63:32 */
110 PERIPH_ID_RESERVED35,
137 PERIPH_ID_RESERVED56,
146 /* Upper word 95:64 */
159 PERIPH_ID_RESERVED74,
161 PERIPH_ID_RESERVED76,
162 PERIPH_ID_RESERVED77,
163 PERIPH_ID_RESERVED78,
164 PERIPH_ID_RESERVED79,
167 PERIPH_ID_RESERVED80,
168 PERIPH_ID_RESERVED81,
169 PERIPH_ID_RESERVED82,
170 PERIPH_ID_RESERVED83,
182 /* Converts a clock number to a clock register: 0=L, 1=H, 2=U */
183 #define PERIPH_REG(id) ((id) >> 5)
185 /* Mask value for a clock (within PERIPH_REG(id)) */
186 #define PERIPH_MASK(id) (1 << ((id) & 0x1f))
188 /* return 1 if a PLL ID is in range */
189 #define clock_id_isvalid(id) ((id) >= CLOCK_ID_FIRST && (id) < CLOCK_ID_COUNT)
191 /* PLL stabilization delay in usec */
192 #define CLOCK_PLL_STABLE_DELAY_US 300
194 /* return the current oscillator clock frequency */
195 enum clock_osc_freq clock_get_osc_freq(void);
198 * Start PLL using the provided configuration parameters.
201 * @param divm input divider
202 * @param divn feedback divider
203 * @param divp post divider 2^n
204 * @param cpcon charge pump setup control
205 * @param lfcon loop filter setup control
207 * @returns monotonic time in us that the PLL will be stable
209 unsigned long clock_start_pll(enum clock_id id, u32 divm, u32 divn,
210 u32 divp, u32 cpcon, u32 lfcon);
217 void clock_enable(enum periph_id clkid);
224 void clock_disable(enum periph_id clkid);
227 * Set whether a clock is enabled or disabled.
230 * @param enable 1 to enable, 0 to disable
232 void clock_set_enable(enum periph_id clkid, int enable);
235 * Reset a peripheral. This puts it in reset, waits for a delay, then takes
236 * it out of reset and waits for th delay again.
238 * @param periph_id peripheral to reset
239 * @param us_delay time to delay in microseconds
241 void reset_periph(enum periph_id periph_id, int us_delay);
244 * Put a peripheral into or out of reset.
246 * @param periph_id peripheral to reset
247 * @param enable 1 to put into reset, 0 to take out of reset
249 void reset_set_enable(enum periph_id periph_id, int enable);
252 /* CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET/CLR_0 */
254 /* Things we can hold in reset for each CPU */
256 crc_rst_de = 1 << 2, /* What is de? */
257 crc_rst_watchdog = 1 << 3,
258 crc_rst_debug = 1 << 4,
262 * Put parts of the CPU complex into or out of reset.\
264 * @param cpu cpu number (0 or 1 on Tegra2)
265 * @param which which parts of the complex to affect (OR of crc_reset_id)
266 * @param reset 1 to assert reset, 0 to de-assert
268 void reset_cmplx_set_enable(int cpu, int which, int reset);
271 * Set the source for a peripheral clock. This plus the divisor sets the
272 * clock rate. You need to look up the datasheet to see the meaning of the
273 * source parameter as it changes for each peripheral.
275 * Warning: This function is only for use pre-relocation. Please use
276 * clock_start_periph_pll() instead.
278 * @param periph_id peripheral to adjust
279 * @param source source clock (0, 1, 2 or 3)
281 void clock_ll_set_source(enum periph_id periph_id, unsigned source);
284 * Set the source and divisor for a peripheral clock. This sets the
285 * clock rate. You need to look up the datasheet to see the meaning of the
286 * source parameter as it changes for each peripheral.
288 * Warning: This function is only for use pre-relocation. Please use
289 * clock_start_periph_pll() instead.
291 * @param periph_id peripheral to adjust
292 * @param source source clock (0, 1, 2 or 3)
293 * @param divisor divisor value to use
295 void clock_ll_set_source_divisor(enum periph_id periph_id, unsigned source,
299 * Start a peripheral PLL clock at the given rate. This also resets the
302 * @param periph_id peripheral to start
303 * @param parent PLL id of required parent clock
304 * @param rate Required clock rate in Hz
305 * @return rate selected in Hz, or -1U if something went wrong
307 unsigned clock_start_periph_pll(enum periph_id periph_id,
308 enum clock_id parent, unsigned rate);
311 * Returns the rate of a peripheral clock in Hz. Since the caller almost
312 * certainly knows the parent clock (having just set it) we require that
313 * this be passed in so we don't need to work it out.
315 * @param periph_id peripheral to start
316 * @param parent PLL id of parent clock (used to calculate rate, you
318 * @return clock rate of peripheral in Hz
320 unsigned long clock_get_periph_rate(enum periph_id periph_id,
321 enum clock_id parent);
324 * Adjust peripheral PLL clock to the given rate. This does not reset the
325 * peripheral. If a second stage divisor is not available, pass NULL for
326 * extra_div. If it is available, then this parameter will return the
327 * divisor selected (which will be a power of 2 from 1 to 256).
329 * @param periph_id peripheral to start
330 * @param parent PLL id of required parent clock
331 * @param rate Required clock rate in Hz
332 * @param extra_div value for the second-stage divisor (NULL if one is
334 * @return rate selected in Hz, or -1U if something went wrong
336 unsigned clock_adjust_periph_pll_div(enum periph_id periph_id,
337 enum clock_id parent, unsigned rate, int *extra_div);
340 * Returns the clock rate of a specified clock, in Hz.
342 * @param parent PLL id of clock to check
343 * @return rate of clock in Hz
345 unsigned clock_get_rate(enum clock_id clkid);
348 * Start up a UART using low-level calls
350 * Prior to relocation clock_start_periph_pll() cannot be called. This
351 * function provides a way to set up a UART using low-level calls which
352 * do not require BSS.
354 * @param periph_id Peripheral ID of UART to enable (e,g, PERIPH_ID_UART1)
356 void clock_ll_start_uart(enum periph_id periph_id);
359 * Checks that clocks are valid and prints a warning if not
361 * @return 0 if ok, -1 on error
363 int clock_verify(void);
365 /* Initialize the clocks */
366 void clock_init(void);
368 /* Initialize the PLLs */
369 void clock_early_init(void);