]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/cpu/arm926ejs/davinci/cpu.c
2 * Copyright (C) 2004 Texas Instruments.
3 * Copyright (C) 2009 David Brownell
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/arch/hardware.h>
13 DECLARE_GLOBAL_DATA_PTR
;
15 /* offsets from PLL controller base */
16 #define PLLC_PLLCTL 0x100
17 #define PLLC_PLLM 0x110
18 #define PLLC_PREDIV 0x114
19 #define PLLC_PLLDIV1 0x118
20 #define PLLC_PLLDIV2 0x11c
21 #define PLLC_PLLDIV3 0x120
22 #define PLLC_POSTDIV 0x128
23 #define PLLC_BPDIV 0x12c
24 #define PLLC_PLLDIV4 0x160
25 #define PLLC_PLLDIV5 0x164
26 #define PLLC_PLLDIV6 0x168
27 #define PLLC_PLLDIV7 0x16c
28 #define PLLC_PLLDIV8 0x170
29 #define PLLC_PLLDIV9 0x174
31 #define BIT(x) (1 << (x))
33 /* SOC-specific pll info */
34 #ifdef CONFIG_SOC_DM355
35 #define ARM_PLLDIV PLLC_PLLDIV1
36 #define DDR_PLLDIV PLLC_PLLDIV1
39 #ifdef CONFIG_SOC_DM644X
40 #define ARM_PLLDIV PLLC_PLLDIV2
41 #define DSP_PLLDIV PLLC_PLLDIV1
42 #define DDR_PLLDIV PLLC_PLLDIV2
45 #ifdef CONFIG_SOC_DM646X
46 #define DSP_PLLDIV PLLC_PLLDIV1
47 #define ARM_PLLDIV PLLC_PLLDIV2
48 #define DDR_PLLDIV PLLC_PLLDIV1
51 #ifdef CONFIG_SOC_DA8XX
52 unsigned int sysdiv
[9] = {
53 PLLC_PLLDIV1
, PLLC_PLLDIV2
, PLLC_PLLDIV3
, PLLC_PLLDIV4
, PLLC_PLLDIV5
,
54 PLLC_PLLDIV6
, PLLC_PLLDIV7
, PLLC_PLLDIV8
, PLLC_PLLDIV9
57 int clk_get(enum davinci_clk_ids id
)
63 unsigned int pll_base
;
65 pll_out
= CONFIG_SYS_OSCIN_FREQ
;
67 if (id
== DAVINCI_AUXCLK_CLKID
)
71 pll_base
= (unsigned int)davinci_pllc1_regs
;
73 pll_base
= (unsigned int)davinci_pllc0_regs
;
78 * Lets keep this simple. Combining operations can result in
79 * unexpected approximations
81 pre_div
= (readl(pll_base
+ PLLC_PREDIV
) &
82 DAVINCI_PLLC_DIV_MASK
) + 1;
83 pllm
= readl(pll_base
+ PLLC_PLLM
) + 1;
88 if (id
== DAVINCI_PLLM_CLKID
)
91 post_div
= (readl(pll_base
+ PLLC_POSTDIV
) &
92 DAVINCI_PLLC_DIV_MASK
) + 1;
96 if (id
== DAVINCI_PLLC_CLKID
)
99 pll_out
/= (readl(pll_base
+ sysdiv
[id
- 1]) &
100 DAVINCI_PLLC_DIV_MASK
) + 1;
106 int set_cpu_clk_info(void)
108 gd
->bd
->bi_arm_freq
= clk_get(DAVINCI_ARM_CLKID
) / 1000000;
109 /* DDR PHY uses an x2 input clock */
110 gd
->bd
->bi_ddr_freq
= cpu_is_da830() ? 0 :
111 (clk_get(DAVINCI_DDR_CLKID
) / 1000000);
112 gd
->bd
->bi_dsp_freq
= 0;
116 #else /* CONFIG_SOC_DA8XX */
118 static unsigned pll_div(volatile void *pllbase
, unsigned offset
)
122 div
= REG(pllbase
+ offset
);
123 return (div
& BIT(15)) ? (1 + (div
& 0x1f)) : 1;
126 static inline unsigned pll_prediv(volatile void *pllbase
)
128 #ifdef CONFIG_SOC_DM355
129 /* this register read seems to fail on pll0 */
130 if (pllbase
== (volatile void *)DAVINCI_PLL_CNTRL0_BASE
)
133 return pll_div(pllbase
, PLLC_PREDIV
);
134 #elif defined(CONFIG_SOC_DM365)
135 return pll_div(pllbase
, PLLC_PREDIV
);
140 static inline unsigned pll_postdiv(volatile void *pllbase
)
142 #if defined(CONFIG_SOC_DM355) || defined(CONFIG_SOC_DM365)
143 return pll_div(pllbase
, PLLC_POSTDIV
);
144 #elif defined(CONFIG_SOC_DM6446)
145 if (pllbase
== (volatile void *)DAVINCI_PLL_CNTRL0_BASE
)
146 return pll_div(pllbase
, PLLC_POSTDIV
);
151 static unsigned pll_sysclk_mhz(unsigned pll_addr
, unsigned div
)
153 volatile void *pllbase
= (volatile void *) pll_addr
;
154 #ifdef CONFIG_SOC_DM646X
155 unsigned base
= CONFIG_REFCLK_FREQ
/ 1000;
157 unsigned base
= CONFIG_SYS_HZ_CLOCK
/ 1000;
160 /* the PLL might be bypassed */
161 if (readl(pllbase
+ PLLC_PLLCTL
) & BIT(0)) {
162 base
/= pll_prediv(pllbase
);
163 #if defined(CONFIG_SOC_DM365)
164 base
*= 2 * (readl(pllbase
+ PLLC_PLLM
) & 0x0ff);
166 base
*= 1 + (REG(pllbase
+ PLLC_PLLM
) & 0x0ff);
168 base
/= pll_postdiv(pllbase
);
170 return DIV_ROUND_UP(base
, 1000 * pll_div(pllbase
, div
));
173 #ifdef DAVINCI_DM6467EVM
174 unsigned int davinci_arm_clk_get()
176 return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE
, ARM_PLLDIV
) * 1000000;
180 #if defined(CONFIG_SOC_DM365)
181 unsigned int davinci_clk_get(unsigned int div
)
183 return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE
, div
) * 1000000;
187 int set_cpu_clk_info(void)
189 unsigned int pllbase
= DAVINCI_PLL_CNTRL0_BASE
;
190 #if defined(CONFIG_SOC_DM365)
191 pllbase
= DAVINCI_PLL_CNTRL1_BASE
;
193 gd
->bd
->bi_arm_freq
= pll_sysclk_mhz(pllbase
, ARM_PLLDIV
);
196 gd
->bd
->bi_dsp_freq
=
197 pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE
, DSP_PLLDIV
);
199 gd
->bd
->bi_dsp_freq
= 0;
202 pllbase
= DAVINCI_PLL_CNTRL1_BASE
;
203 #if defined(CONFIG_SOC_DM365)
204 pllbase
= DAVINCI_PLL_CNTRL0_BASE
;
206 gd
->bd
->bi_ddr_freq
= pll_sysclk_mhz(pllbase
, DDR_PLLDIV
) / 2;
211 #endif /* !CONFIG_SOC_DA8XX */
214 * Initializes on-chip ethernet controllers.
215 * to override, implement board_eth_init()
217 int cpu_eth_init(bd_t
*bis
)
219 #if defined(CONFIG_DRIVER_TI_EMAC)
220 davinci_emac_initialize();