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,
183 /* Converts a clock number to a clock register: 0=L, 1=H, 2=U */
184 #define PERIPH_REG(id) ((id) >> 5)
186 /* Mask value for a clock (within PERIPH_REG(id)) */
187 #define PERIPH_MASK(id) (1 << ((id) & 0x1f))
189 /* return 1 if a PLL ID is in range, and not a simple PLL */
190 #define clock_id_is_pll(id) ((id) >= CLOCK_ID_FIRST && \
191 (id) < CLOCK_ID_FIRST_SIMPLE)
193 /* PLL stabilization delay in usec */
194 #define CLOCK_PLL_STABLE_DELAY_US 300
196 /* return the current oscillator clock frequency */
197 enum clock_osc_freq clock_get_osc_freq(void);
200 * Start PLL using the provided configuration parameters.
203 * @param divm input divider
204 * @param divn feedback divider
205 * @param divp post divider 2^n
206 * @param cpcon charge pump setup control
207 * @param lfcon loop filter setup control
209 * @returns monotonic time in us that the PLL will be stable
211 unsigned long clock_start_pll(enum clock_id id, u32 divm, u32 divn,
212 u32 divp, u32 cpcon, u32 lfcon);
215 * Read low-level parameters of a PLL.
217 * @param id clock id to read (note: USB is not supported)
218 * @param divm returns input divider
219 * @param divn returns feedback divider
220 * @param divp returns post divider 2^n
221 * @param cpcon returns charge pump setup control
222 * @param lfcon returns loop filter setup control
224 * @returns 0 if ok, -1 on error (invalid clock id)
226 int clock_ll_read_pll(enum clock_id clkid, u32 *divm, u32 *divn,
227 u32 *divp, u32 *cpcon, u32 *lfcon);
234 void clock_enable(enum periph_id clkid);
241 void clock_disable(enum periph_id clkid);
244 * Set whether a clock is enabled or disabled.
247 * @param enable 1 to enable, 0 to disable
249 void clock_set_enable(enum periph_id clkid, int enable);
252 * Reset a peripheral. This puts it in reset, waits for a delay, then takes
253 * it out of reset and waits for th delay again.
255 * @param periph_id peripheral to reset
256 * @param us_delay time to delay in microseconds
258 void reset_periph(enum periph_id periph_id, int us_delay);
261 * Put a peripheral into or out of reset.
263 * @param periph_id peripheral to reset
264 * @param enable 1 to put into reset, 0 to take out of reset
266 void reset_set_enable(enum periph_id periph_id, int enable);
269 /* CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET/CLR_0 */
271 /* Things we can hold in reset for each CPU */
273 crc_rst_de = 1 << 2, /* What is de? */
274 crc_rst_watchdog = 1 << 3,
275 crc_rst_debug = 1 << 4,
279 * Put parts of the CPU complex into or out of reset.\
281 * @param cpu cpu number (0 or 1 on Tegra2)
282 * @param which which parts of the complex to affect (OR of crc_reset_id)
283 * @param reset 1 to assert reset, 0 to de-assert
285 void reset_cmplx_set_enable(int cpu, int which, int reset);
288 * Set the source for a peripheral clock. This plus the divisor sets the
289 * clock rate. You need to look up the datasheet to see the meaning of the
290 * source parameter as it changes for each peripheral.
292 * Warning: This function is only for use pre-relocation. Please use
293 * clock_start_periph_pll() instead.
295 * @param periph_id peripheral to adjust
296 * @param source source clock (0, 1, 2 or 3)
298 void clock_ll_set_source(enum periph_id periph_id, unsigned source);
301 * Set the source and divisor for a peripheral clock. This sets the
302 * clock rate. You need to look up the datasheet to see the meaning of the
303 * source parameter as it changes for each peripheral.
305 * Warning: This function is only for use pre-relocation. Please use
306 * clock_start_periph_pll() instead.
308 * @param periph_id peripheral to adjust
309 * @param source source clock (0, 1, 2 or 3)
310 * @param divisor divisor value to use
312 void clock_ll_set_source_divisor(enum periph_id periph_id, unsigned source,
316 * Start a peripheral PLL clock at the given rate. This also resets the
319 * @param periph_id peripheral to start
320 * @param parent PLL id of required parent clock
321 * @param rate Required clock rate in Hz
322 * @return rate selected in Hz, or -1U if something went wrong
324 unsigned clock_start_periph_pll(enum periph_id periph_id,
325 enum clock_id parent, unsigned rate);
328 * Returns the rate of a peripheral clock in Hz. Since the caller almost
329 * certainly knows the parent clock (having just set it) we require that
330 * this be passed in so we don't need to work it out.
332 * @param periph_id peripheral to start
333 * @param parent PLL id of parent clock (used to calculate rate, you
335 * @return clock rate of peripheral in Hz
337 unsigned long clock_get_periph_rate(enum periph_id periph_id,
338 enum clock_id parent);
341 * Adjust peripheral PLL clock to the given rate. This does not reset the
342 * peripheral. If a second stage divisor is not available, pass NULL for
343 * extra_div. If it is available, then this parameter will return the
344 * divisor selected (which will be a power of 2 from 1 to 256).
346 * @param periph_id peripheral to start
347 * @param parent PLL id of required parent clock
348 * @param rate Required clock rate in Hz
349 * @param extra_div value for the second-stage divisor (NULL if one is
351 * @return rate selected in Hz, or -1U if something went wrong
353 unsigned clock_adjust_periph_pll_div(enum periph_id periph_id,
354 enum clock_id parent, unsigned rate, int *extra_div);
357 * Returns the clock rate of a specified clock, in Hz.
359 * @param parent PLL id of clock to check
360 * @return rate of clock in Hz
362 unsigned clock_get_rate(enum clock_id clkid);
365 * Start up a UART using low-level calls
367 * Prior to relocation clock_start_periph_pll() cannot be called. This
368 * function provides a way to set up a UART using low-level calls which
369 * do not require BSS.
371 * @param periph_id Peripheral ID of UART to enable (e,g, PERIPH_ID_UART1)
373 void clock_ll_start_uart(enum periph_id periph_id);
376 * Decode a peripheral ID from a device tree node.
378 * This works by looking up the peripheral's 'clocks' node and reading out
379 * the second cell, which is the clock number / peripheral ID.
381 * @param blob FDT blob to use
382 * @param node Node to look at
383 * @return peripheral ID, or PERIPH_ID_NONE if none
385 enum periph_id clock_decode_periph_id(const void *blob, int node);
388 * Checks if the oscillator bypass is enabled (XOBP bit)
390 * @return 1 if bypass is enabled, 0 if not
392 int clock_get_osc_bypass(void);
395 * Checks that clocks are valid and prints a warning if not
397 * @return 0 if ok, -1 on error
399 int clock_verify(void);
401 /* Initialize the clocks */
402 void clock_init(void);
404 /* Initialize the PLLs */
405 void clock_early_init(void);