davinci: display correct clock info
[oweals/u-boot.git] / cpu / arm926ejs / davinci / cpu.c
1 /*
2  * Copyright (C) 2004 Texas Instruments.
3  * Copyright (C) 2009 David Brownell
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <common.h>
24 #include <asm/arch/hardware.h>
25
26
27 /* offsets from PLL controller base */
28 #define PLLC_PLLCTL     0x100
29 #define PLLC_PLLM       0x110
30 #define PLLC_PREDIV     0x114
31 #define PLLC_PLLDIV1    0x118
32 #define PLLC_PLLDIV2    0x11c
33 #define PLLC_PLLDIV3    0x120
34 #define PLLC_POSTDIV    0x128
35 #define PLLC_BPDIV      0x12c
36 #define PLLC_PLLDIV4    0x160
37 #define PLLC_PLLDIV5    0x164
38 #define PLLC_PLLDIV6    0x168
39 #define PLLC_PLLDIV8    0x170
40 #define PLLC_PLLDIV9    0x174
41
42 #define BIT(x)          (1 << (x))
43
44 /* SOC-specific pll info */
45 #ifdef CONFIG_SOC_DM355
46 #define ARM_PLLDIV      PLLC_PLLDIV1
47 #define DDR_PLLDIV      PLLC_PLLDIV1
48 #endif
49
50 #ifdef CONFIG_SOC_DM644X
51 #define ARM_PLLDIV      PLLC_PLLDIV2
52 #define DSP_PLLDIV      PLLC_PLLDIV1
53 #define DDR_PLLDIV      PLLC_PLLDIV2
54 #endif
55
56 #ifdef CONFIG_SOC_DM6447
57 #define ARM_PLLDIV      PLLC_PLLDIV2
58 #define DSP_PLLDIV      PLLC_PLLDIV1
59 #define DDR_PLLDIV      PLLC_PLLDIV1
60 #endif
61
62
63 #ifdef CONFIG_DISPLAY_CPUINFO
64
65 static unsigned pll_div(volatile void *pllbase, unsigned offset)
66 {
67         u32     div;
68
69         div = REG(pllbase + offset);
70         return (div & BIT(15)) ? (1 + (div & 0x1f)) : 1;
71 }
72
73 static inline unsigned pll_prediv(volatile void *pllbase)
74 {
75 #ifdef CONFIG_SOC_DM355
76         /* this register read seems to fail on pll0 */
77         if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE)
78                 return 8;
79         else
80                 return pll_div(pllbase, PLLC_PREDIV);
81 #endif
82         return 1;
83 }
84
85 static inline unsigned pll_postdiv(volatile void *pllbase)
86 {
87 #ifdef CONFIG_SOC_DM355
88         return pll_div(pllbase, PLLC_POSTDIV);
89 #elif defined(CONFIG_SOC_DM6446)
90         if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE)
91                 return pll_div(pllbase, PLLC_POSTDIV);
92 #endif
93         return 1;
94 }
95
96 static unsigned pll_sysclk_mhz(unsigned pll_addr, unsigned div)
97 {
98         volatile void   *pllbase = (volatile void *) pll_addr;
99         unsigned        base = CONFIG_SYS_HZ_CLOCK / 1000;
100
101         /* the PLL might be bypassed */
102         if (REG(pllbase + PLLC_PLLCTL) & BIT(0)) {
103                 base /= pll_prediv(pllbase);
104                 base *= 1 + (REG(pllbase + PLLC_PLLM) & 0x0ff);
105                 base /= pll_postdiv(pllbase);
106         }
107         return DIV_ROUND_UP(base, 1000 * pll_div(pllbase, div));
108 }
109
110 int print_cpuinfo(void)
111 {
112         /* REVISIT fetch and display CPU ID and revision information
113          * too ... that will matter as more revisions appear.
114          */
115         printf("Cores: ARM %d MHz",
116                         pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV));
117
118 #ifdef DSP_PLLDIV
119         printf(", DSP %d MHz",
120                         pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, DSP_PLLDIV));
121 #endif
122
123         printf("\nDDR:   %d MHz\n",
124                         /* DDR PHY uses an x2 input clock */
125                         pll_sysclk_mhz(DAVINCI_PLL_CNTRL1_BASE, DDR_PLLDIV)
126                                 / 2);
127         return 0;
128 }
129
130 #endif
131