blob: c19206ac39a72ef98c02ce5806c7e42d7e02d8ab [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk7ac16102004-08-01 22:48:16 +00002/*
3 *
4 * (c) 2004 Sascha Hauer <sascha@saschahauer.de>
wdenk7ac16102004-08-01 22:48:16 +00005 */
6
7
8#include <common.h>
9#if defined (CONFIG_IMX)
Tom Rini8c70baa2021-12-14 13:36:40 -050010#include <clock_legacy.h>
wdenk7ac16102004-08-01 22:48:16 +000011
12#include <asm/arch/imx-regs.h>
13
14/* ------------------------------------------------------------------------- */
15/* NOTE: This describes the proper use of this file.
16 *
Tom Rini8c70baa2021-12-14 13:36:40 -050017 * get_board_sys_clk() should be defined as the input frequency of the PLL.
wdenk7ac16102004-08-01 22:48:16 +000018 * SH FIXME: 16780000 in our case
19 * get_FCLK(), get_HCLK(), get_PCLK() and get_UCLK() return the clock of
20 * the specified bus in HZ.
21 */
22/* ------------------------------------------------------------------------- */
23
24ulong get_systemPLLCLK(void)
25{
26 /* FIXME: We assume System_SEL = 0 here */
27 u32 spctl0 = SPCTL0;
28 u32 mfi = (spctl0 >> 10) & 0xf;
29 u32 mfn = spctl0 & 0x3f;
30 u32 mfd = (spctl0 >> 16) & 0x3f;
31 u32 pd = (spctl0 >> 26) & 0xf;
32
33 mfi = mfi<=5 ? 5 : mfi;
34
35 return (2*(CONFIG_SYSPLL_CLK_FREQ>>10)*( (mfi<<10) + (mfn<<10)/(mfd+1)))/(pd+1);
36}
37
38ulong get_mcuPLLCLK(void)
39{
40 /* FIXME: We assume System_SEL = 0 here */
41 u32 mpctl0 = MPCTL0;
42 u32 mfi = (mpctl0 >> 10) & 0xf;
43 u32 mfn = mpctl0 & 0x3f;
44 u32 mfd = (mpctl0 >> 16) & 0x3f;
45 u32 pd = (mpctl0 >> 26) & 0xf;
46
47 mfi = mfi<=5 ? 5 : mfi;
48
Tom Rini8c70baa2021-12-14 13:36:40 -050049 return (2*(get_board_sys_clk()>>10)*( (mfi<<10) + (mfn<<10)/(mfd+1)))/(pd+1);
wdenk7ac16102004-08-01 22:48:16 +000050}
51
52ulong get_FCLK(void)
53{
54 return (( CSCR>>15)&1) ? get_mcuPLLCLK()>>1 : get_mcuPLLCLK();
55}
56
57/* return HCLK frequency */
58ulong get_HCLK(void)
59{
60 u32 bclkdiv = (( CSCR >> 10 ) & 0xf) + 1;
61 printf("bclkdiv: %d\n", bclkdiv);
62 return get_systemPLLCLK() / bclkdiv;
63}
64
65/* return BCLK frequency */
66ulong get_BCLK(void)
67{
68 return get_HCLK();
69}
70
71ulong get_PERCLK1(void)
72{
73 return get_systemPLLCLK() / (((PCDR) & 0xf)+1);
74}
75
76ulong get_PERCLK2(void)
77{
78 return get_systemPLLCLK() / (((PCDR>>4) & 0xf)+1);
79}
80
81ulong get_PERCLK3(void)
82{
83 return get_systemPLLCLK() / (((PCDR>>16) & 0x7f)+1);
84}
85
86#endif /* defined (CONFIG_IMX) */