blob: 74c3d5d936c2a7c83cc643239120d9ce010ce684 [file] [log] [blame]
David Brownell7a4f5112009-05-15 23:47:12 +02001/*
2 * Copyright (C) 2004 Texas Instruments.
3 * Copyright (C) 2009 David Brownell
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
David Brownell7a4f5112009-05-15 23:47:12 +02006 */
7
8#include <common.h>
Ben Warren84535872009-05-26 00:34:07 -07009#include <netdev.h>
David Brownell7a4f5112009-05-15 23:47:12 +020010#include <asm/arch/hardware.h>
Sekhar Nori91172ba2009-11-12 11:07:22 -050011#include <asm/io.h>
David Brownell7a4f5112009-05-15 23:47:12 +020012
Hadli, Manjunath8f5d4682012-02-06 00:30:44 +000013DECLARE_GLOBAL_DATA_PTR;
14
David Brownell7a4f5112009-05-15 23:47:12 +020015/* 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
Sudhakar Rajashekharab7e68432011-09-03 22:18:04 -040027#define PLLC_PLLDIV7 0x16c
David Brownell7a4f5112009-05-15 23:47:12 +020028#define PLLC_PLLDIV8 0x170
29#define PLLC_PLLDIV9 0x174
30
David Brownell7a4f5112009-05-15 23:47:12 +020031/* SOC-specific pll info */
32#ifdef CONFIG_SOC_DM355
33#define ARM_PLLDIV PLLC_PLLDIV1
34#define DDR_PLLDIV PLLC_PLLDIV1
35#endif
36
37#ifdef CONFIG_SOC_DM644X
38#define ARM_PLLDIV PLLC_PLLDIV2
39#define DSP_PLLDIV PLLC_PLLDIV1
40#define DDR_PLLDIV PLLC_PLLDIV2
41#endif
42
Sandeep Paulraj5342a712010-12-29 14:31:26 -050043#ifdef CONFIG_SOC_DM646X
44#define DSP_PLLDIV PLLC_PLLDIV1
45#define ARM_PLLDIV PLLC_PLLDIV2
46#define DDR_PLLDIV PLLC_PLLDIV1
47#endif
48
Sekhar Nori91172ba2009-11-12 11:07:22 -050049#ifdef CONFIG_SOC_DA8XX
Sudhakar Rajashekharab7e68432011-09-03 22:18:04 -040050unsigned int sysdiv[9] = {
51 PLLC_PLLDIV1, PLLC_PLLDIV2, PLLC_PLLDIV3, PLLC_PLLDIV4, PLLC_PLLDIV5,
52 PLLC_PLLDIV6, PLLC_PLLDIV7, PLLC_PLLDIV8, PLLC_PLLDIV9
Sekhar Nori91172ba2009-11-12 11:07:22 -050053};
54
55int clk_get(enum davinci_clk_ids id)
56{
57 int pre_div;
58 int pllm;
59 int post_div;
60 int pll_out;
Sudhakar Rajashekharab7e68432011-09-03 22:18:04 -040061 unsigned int pll_base;
Sekhar Nori91172ba2009-11-12 11:07:22 -050062
63 pll_out = CONFIG_SYS_OSCIN_FREQ;
64
65 if (id == DAVINCI_AUXCLK_CLKID)
66 goto out;
67
Sudhakar Rajashekharab7e68432011-09-03 22:18:04 -040068 if ((id >> 16) == 1)
69 pll_base = (unsigned int)davinci_pllc1_regs;
70 else
71 pll_base = (unsigned int)davinci_pllc0_regs;
72
73 id &= 0xFFFF;
74
Sekhar Nori91172ba2009-11-12 11:07:22 -050075 /*
76 * Lets keep this simple. Combining operations can result in
77 * unexpected approximations
78 */
Sudhakar Rajashekharab7e68432011-09-03 22:18:04 -040079 pre_div = (readl(pll_base + PLLC_PREDIV) &
80 DAVINCI_PLLC_DIV_MASK) + 1;
81 pllm = readl(pll_base + PLLC_PLLM) + 1;
Sekhar Nori91172ba2009-11-12 11:07:22 -050082
83 pll_out /= pre_div;
84 pll_out *= pllm;
85
86 if (id == DAVINCI_PLLM_CLKID)
87 goto out;
88
Sudhakar Rajashekharab7e68432011-09-03 22:18:04 -040089 post_div = (readl(pll_base + PLLC_POSTDIV) &
90 DAVINCI_PLLC_DIV_MASK) + 1;
Sekhar Nori91172ba2009-11-12 11:07:22 -050091
92 pll_out /= post_div;
93
94 if (id == DAVINCI_PLLC_CLKID)
95 goto out;
96
Sudhakar Rajashekharab7e68432011-09-03 22:18:04 -040097 pll_out /= (readl(pll_base + sysdiv[id - 1]) &
98 DAVINCI_PLLC_DIV_MASK) + 1;
Sekhar Nori91172ba2009-11-12 11:07:22 -050099
100out:
101 return pll_out;
102}
Laurence Withersbe7d2572012-07-30 23:30:37 +0000103
104int set_cpu_clk_info(void)
105{
106 gd->bd->bi_arm_freq = clk_get(DAVINCI_ARM_CLKID) / 1000000;
107 /* DDR PHY uses an x2 input clock */
108 gd->bd->bi_ddr_freq = cpu_is_da830() ? 0 :
109 (clk_get(DAVINCI_DDR_CLKID) / 1000000);
110 gd->bd->bi_dsp_freq = 0;
111 return 0;
112}
113
Heiko Schocher0a0522c2011-09-14 19:59:39 +0000114#else /* CONFIG_SOC_DA8XX */
David Brownell7a4f5112009-05-15 23:47:12 +0200115
David Brownell7a4f5112009-05-15 23:47:12 +0200116static unsigned pll_div(volatile void *pllbase, unsigned offset)
117{
118 u32 div;
119
120 div = REG(pllbase + offset);
121 return (div & BIT(15)) ? (1 + (div & 0x1f)) : 1;
122}
123
124static inline unsigned pll_prediv(volatile void *pllbase)
125{
126#ifdef CONFIG_SOC_DM355
127 /* this register read seems to fail on pll0 */
128 if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE)
129 return 8;
130 else
131 return pll_div(pllbase, PLLC_PREDIV);
Heiko Schocher29b0bef2011-11-01 20:00:33 +0000132#elif defined(CONFIG_SOC_DM365)
133 return pll_div(pllbase, PLLC_PREDIV);
David Brownell7a4f5112009-05-15 23:47:12 +0200134#endif
135 return 1;
136}
137
138static inline unsigned pll_postdiv(volatile void *pllbase)
139{
Heiko Schocher29b0bef2011-11-01 20:00:33 +0000140#if defined(CONFIG_SOC_DM355) || defined(CONFIG_SOC_DM365)
David Brownell7a4f5112009-05-15 23:47:12 +0200141 return pll_div(pllbase, PLLC_POSTDIV);
142#elif defined(CONFIG_SOC_DM6446)
143 if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE)
144 return pll_div(pllbase, PLLC_POSTDIV);
145#endif
146 return 1;
147}
148
149static unsigned pll_sysclk_mhz(unsigned pll_addr, unsigned div)
150{
151 volatile void *pllbase = (volatile void *) pll_addr;
Sandeep Paulraj5342a712010-12-29 14:31:26 -0500152#ifdef CONFIG_SOC_DM646X
prabhakar.csengg@gmail.comfda9c202012-02-12 21:38:22 +0000153 unsigned base = CONFIG_REFCLK_FREQ / 1000;
Sandeep Paulraj5342a712010-12-29 14:31:26 -0500154#else
David Brownell7a4f5112009-05-15 23:47:12 +0200155 unsigned base = CONFIG_SYS_HZ_CLOCK / 1000;
Sandeep Paulraj5342a712010-12-29 14:31:26 -0500156#endif
David Brownell7a4f5112009-05-15 23:47:12 +0200157
158 /* the PLL might be bypassed */
Heiko Schocher29b0bef2011-11-01 20:00:33 +0000159 if (readl(pllbase + PLLC_PLLCTL) & BIT(0)) {
David Brownell7a4f5112009-05-15 23:47:12 +0200160 base /= pll_prediv(pllbase);
Heiko Schocher29b0bef2011-11-01 20:00:33 +0000161#if defined(CONFIG_SOC_DM365)
162 base *= 2 * (readl(pllbase + PLLC_PLLM) & 0x0ff);
163#else
David Brownell7a4f5112009-05-15 23:47:12 +0200164 base *= 1 + (REG(pllbase + PLLC_PLLM) & 0x0ff);
Heiko Schocher29b0bef2011-11-01 20:00:33 +0000165#endif
David Brownell7a4f5112009-05-15 23:47:12 +0200166 base /= pll_postdiv(pllbase);
167 }
168 return DIV_ROUND_UP(base, 1000 * pll_div(pllbase, div));
169}
170
Sandeep Paulraj5342a712010-12-29 14:31:26 -0500171#ifdef DAVINCI_DM6467EVM
172unsigned int davinci_arm_clk_get()
173{
174 return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV) * 1000000;
175}
176#endif
Heiko Schocher29b0bef2011-11-01 20:00:33 +0000177
178#if defined(CONFIG_SOC_DM365)
179unsigned int davinci_clk_get(unsigned int div)
180{
181 return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, div) * 1000000;
182}
183#endif
David Brownell7a4f5112009-05-15 23:47:12 +0200184
Hadli, Manjunath8f5d4682012-02-06 00:30:44 +0000185int set_cpu_clk_info(void)
186{
Hadli, Manjunath8f5d4682012-02-06 00:30:44 +0000187 unsigned int pllbase = DAVINCI_PLL_CNTRL0_BASE;
188#if defined(CONFIG_SOC_DM365)
189 pllbase = DAVINCI_PLL_CNTRL1_BASE;
190#endif
191 gd->bd->bi_arm_freq = pll_sysclk_mhz(pllbase, ARM_PLLDIV);
192
193#ifdef DSP_PLLDIV
194 gd->bd->bi_dsp_freq =
195 pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, DSP_PLLDIV);
196#else
197 gd->bd->bi_dsp_freq = 0;
198#endif
199
200 pllbase = DAVINCI_PLL_CNTRL1_BASE;
201#if defined(CONFIG_SOC_DM365)
202 pllbase = DAVINCI_PLL_CNTRL0_BASE;
203#endif
204 gd->bd->bi_ddr_freq = pll_sysclk_mhz(pllbase, DDR_PLLDIV) / 2;
Laurence Withersbe7d2572012-07-30 23:30:37 +0000205
Hadli, Manjunath8f5d4682012-02-06 00:30:44 +0000206 return 0;
207}
208
Laurence Withersbe7d2572012-07-30 23:30:37 +0000209#endif /* !CONFIG_SOC_DA8XX */
210
Ben Warren84535872009-05-26 00:34:07 -0700211/*
212 * Initializes on-chip ethernet controllers.
213 * to override, implement board_eth_init()
214 */
215int cpu_eth_init(bd_t *bis)
216{
217#if defined(CONFIG_DRIVER_TI_EMAC)
218 davinci_emac_initialize();
219#endif
220 return 0;
221}